Basic Caching Setup

Before you dive into REN.Kit’s blazing fast caching, you’ll need a minimal configuration in your project. REN.Kit.CacheKit supports two cache providers out-of-the-box:

  • In-Memory Cache (for single-server, high-speed, volatile scenarios)

  • Redis Cache (for distributed, scalable, persistent caching)


Add Cache Configuration

To unlock the full power of Ren.Kit, you must configure your appsettings.json file with the following structure:

 "CacheConfiguration": {
   "RedisConfiguration": {
     "Url": "localhost:6379",
     "TimeConfiguration": {
       "AbsoluteExpirationInHours": 12
     },
     "DatabaseId": 4,
     "Username": "default",
     "Password": "ofqa9YpQ6iw5tmDsoH5EW1OTMJtKs2Gs",
     "AbortOnConnectFail": false,
     "IsAdmin": false
   },
   "InMemoryConfiguration": {
     "TimeConfiguration": {
       "AbsoluteExpirationInHours": 12,
       "SlidingExpirationInMinutes": 30
     }
   }
 }
  • You can enable only the sections you intend to use (RedisConfiguration and/or InMemoryConfiguration).

  • Important: If you want to allow advanced admin operations (like flush), set "IsAdmin": true in the Redis section.

  • For production, always use secure credentials and restrict admin permissions!

With this setup, Ren.Kit can auto-detect your preferred caching provider and deliver blazing-fast performance out of the box.

⚠️ Heads up for Redis users!

Note:


Selecting the Cache Provider via Enum

The cache provider is determined at the time of service registration. Simply choose the provider you want by specifying a CacheType enum value.

🧠 In-Memory Caching Example

This will automatically configure a lightweight and high-performance memory cache using IMemoryCache.

🚀 Redis Caching Example

To use Redis as the distributed cache provider, you must supply:

  1. A multiplexer factory (Func<IServiceProvider, IConnectionMultiplexer>)

  2. A lifetime definition (RedisMultiplexerLifetime)

📌 More details about Redis configuration and advanced usage are covered in the Redis Caching section below.

Last updated