Morwinyon.Caching 4.0.0

dotnet add package Morwinyon.Caching --version 4.0.0                
NuGet\Install-Package Morwinyon.Caching -Version 4.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Morwinyon.Caching" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Morwinyon.Caching --version 4.0.0                
#r "nuget: Morwinyon.Caching, 4.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 NuGet NuGet

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 232 11/28/2023
3.0.0 197 11/28/2023

Summary of changes made in this release of the package.