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 (
RedisConfigurationand/orInMemoryConfiguration).Important: If you want to allow advanced admin operations (like flush), set
"IsAdmin": truein 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!
If you want to use the FLUSHDB operation (for example, when calling ClearAll() on your Redis cache), you must set "isAdmin": true in your RedisConfiguration.
This is a Redis security safeguard:
Setting
isAdmintotruegrants your application elevated permissions, enabling administrative commands such asFLUSHDB.If
isAdminisfalse(the default), all destructive/admin-level operations are blocked—your data will remain safe from accidental wipes.This setting only applies to Redis caching; In-Memory cache doesn’t require it.
💡 Tip: Only enable admin mode in development or trusted environments. Never expose admin privileges in production unless absolutely necessary!
⚡ Note:
Step-by-step setup instructions for both Redis and In-Memory cache providers will be covered in detail on their dedicated pages.
Just follow along—each provider’s configuration and integration will be crystal clear in the following sections!
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:
A multiplexer factory (
Func<IServiceProvider, IConnectionMultiplexer>)A lifetime definition (
RedisMultiplexerLifetime)
📌 More details about Redis configuration and advanced usage are covered in the Redis Caching section below.
Last updated