Using REN.Kit’s Built-in In-Memory Cache Service
The easiest way to enjoy high-performance caching is by leveraging REN.Kit’s default in-memory cache service—no customizations, no boilerplate, just pure out-of-the-box speed.
How to Use the Built-In In-Memory Cache
Once you’ve configured and registered the in-memory 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 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.");
}
}
Supported Operations
With the standard REN.Kit In-Memory Cache, you can:
Set cache entries with expiration
Get cached objects or strings by key
Remove individual entries
Get or create (add if missing, otherwise return cached)
All methods are available both synchronously and asynchronously. And for most .NET applications, this is all you need for high-performance, easy-to-maintain caching.
Last updated