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/orInMemoryConfiguration
).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!
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
isAdmin
totrue
grants your application elevated permissions, enabling administrative commands such asFLUSHDB
.If
isAdmin
isfalse
(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
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