Morwinyon.Caching
4.0.0
dotnet add package Morwinyon.Caching --version 4.0.0
NuGet\Install-Package Morwinyon.Caching -Version 4.0.0
<PackageReference Include="Morwinyon.Caching" Version="4.0.0" />
paket add Morwinyon.Caching --version 4.0.0
#r "nuget: Morwinyon.Caching, 4.0.0"
// Install Morwinyon.Caching as a Cake Addin #addin nuget:?package=Morwinyon.Caching&version=4.0.0 // Install Morwinyon.Caching as a Cake Tool #tool nuget:?package=Morwinyon.Caching&version=4.0.0
Caching
The Caching Extension is designed to enhance your WebAPI Projects by introducing a comprehensive Caching Feature. Notably, it offers configurability and by default, comes pre-configured with optimal settings upon implementation.
The Caching Config incorporates three distinct functions, outlined below, that empower the system to seamlessly retrieve the provided API version from various sources.
NuGet
Package Name | Package | Downloads |
---|---|---|
Caching |
Installation
PM> NuGet\Install-Package Morwinyon.Caching
or
dotnet add package Morwinyon.Caching
Usage
builder.Services.AddMorwinyonRedisCache(config =>
{
config.RedisConfig.Endpoints = "localhost:6379";
config.RedisConfig.ConnectTimeout = 5000;
config.RedisConfig.SyncTimeout = 1000;
config.RedisConfig.AbortOnConnectFail = false;
});
builder.Services.AddMorwinyonMemoryCache(config =>
{
config.MemoryConfig.SizeLimit = 1024;
config.MemoryConfig.ExpirationScanFrequency = TimeSpan.FromMinutes(1);
config.MemoryConfig.CompactionPercentage = 0.20;
});
It could be used as shown below. In this case, version 4.0.0 will be used as the default version when not specified.
builder.Services.AddMorwiyonMemoryCache();
builder.Services.AddMorwinyonRedisCache();
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
// Injecting ICacheService<string> for caching operations
private readonly ICacheService<string> _cacheService;
public TestController(ICacheService<string> cacheService)
{
_cacheService = cacheService;
}
// HTTP GET method to retrieve data from cache
[HttpGet]
public IActionResult GetFromCache()
{
// Attempt to retrieve cached data using the key "cacheKey"
string key = _cacheService.Get("cacheKey");
// If the data is found in the cache, return it as Ok result; otherwise, return a BadRequest with new trace and request IDs
if (key is not null)
return Ok(key);
return BadRequest(new string[]
{
$"TraceId: {Guid.NewGuid()}",
$"RequestId: {Guid.NewGuid()}"
});
}
// HTTP POST method to set data into the cache
[HttpPost]
public IActionResult SetFromCache([FromBody] string cacheKey)
{
// Set the provided data into the cache with the key "cacheKey" and a time-to-live of 5 minutes
_cacheService.Set("cacheKey", cacheKey, TimeSpan.FromMinutes(5));
// Return Ok result to indicate successful caching
return Ok();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Newtonsoft.Json (>= 11.0.2)
- StackExchange.Redis (>= 2.7.4)
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Newtonsoft.Json (>= 11.0.2)
- StackExchange.Redis (>= 2.7.4)
-
net7.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Newtonsoft.Json (>= 11.0.2)
- StackExchange.Redis (>= 2.7.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Summary of changes made in this release of the package.