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

Which caching provider you want to use is determined by simply passing the corresponding value from the CacheType enum when calling the registration extension:

public enum CacheType
{
    InMemory,
    Redis
}

For example, to use in-memory caching, register like this:

csharpCopyEditbuilder.Services.AddRENCaching(CacheType.InMemory);

Or, to use Redis caching:

csharpCopyEditbuilder.Services.AddRENCaching(CacheType.Redis);

This approach keeps your startup configuration clean and highly flexible. Just change the enum value to instantly switch caching strategies—no extra refactoring required.

Last updated