Using REN.Kit’s Built-in Redis Cache Service

The easiest way to achieve high-performance, distributed caching is by leveraging REN.Kit’s default Redis cache service—no custom code, no setup headaches, just effortless, scalable caching out of the box.


How to Use the Built-In Redis Cache

Once you’ve added your Redis configuration to appsettings.json and registered the Redis cache service (see previous section), you’re ready to inject and use the cache interface anywhere in your project:

[Route("api/[controller]")]
[ApiController]
public class StandardCacheController(IRENCacheService cacheService) : ControllerBase
{
    /// <summary>
    /// Adds or updates an item in the Redis cache.
    /// </summary>
    [HttpPost("set")]
    public async Task<IActionResult> SetCache([FromQuery] string key, [FromBody] object value)
    {
        await cacheService.SetAsync(key, value, TimeSpan.FromMinutes(10));
        return Ok("Value cached in Redis.");
    }
}

Supported Operations

With REN.Kit’s standard Redis cache, you can:

  • Set cache entries with absolute or sliding expiration

  • Get cached objects or strings by key

  • Remove individual entries

  • Get or create (add if missing, otherwise return cached)

  • Clear the entire cache (with admin enabled)

  • All methods are available both synchronously and asynchronously.

Last updated