Diatly.Cache 1.0.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Diatly.Cache --version 1.0.0.1
NuGet\Install-Package Diatly.Cache -Version 1.0.0.1
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="Diatly.Cache" Version="1.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Diatly.Cache --version 1.0.0.1
#r "nuget: Diatly.Cache, 1.0.0.1"
#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 Diatly.Cache as a Cake Addin
#addin nuget:?package=Diatly.Cache&version=1.0.0.1

// Install Diatly.Cache as a Cake Tool
#tool nuget:?package=Diatly.Cache&version=1.0.0.1

***************** Dialty.Cache Library *****************


There is cache implemention of

  1. Memory cache and
  2. Redis cache.

How you use ?

Set configureService in startup.cs file

Step 1:

public void ConfigureServices(IServiceCollection services) { if (Environment.EnvironmentName != "Production") { string redisConnection = Configuration["Redis:ConnectionString"]; services.AddSingleton<IDistributedCache>(factory ⇒ { var cache = new RedisCache(new RedisCacheOptions { Configuration = redisConnection }); return cache; });

    services.AddSingleton(typeof(ICacheService<>), typeof(RedisCacheService<>));
}
else
{
    services.AddSingleton<IMemoryCache>(factory =>
    {
        var cache = new MemoryCache(new MemoryCacheOptions());
        return cache;
    });
    services.AddSingleton(typeof(ICacheService<>), typeof(MemoryCacheService<>));
}

services.AddMvc();

}

Step2: Creat business layer sen use cache.

public class ProductManager : IProductManager { private IDataRepository<Product, int> _iRepo; private readonly ICacheService<Product> cache; public ProductManager(IDataRepository<Product, int> repo, ICacheService<Product> cacheService) { _iRepo = repo; cache = cacheService; }

    public long Add(Product model)
    {
        var data = _iRepo.Add(model);
        cache.Delete("all");
        return data;
    }

    public long Delete(int id)
    {
        var data = _iRepo.Delete(id);
        cache.Delete(id.ToString());
        cache.Delete("all");
        return data;
    }

    public Product Get(int id)
    {
        Product product = null;
        var dataById = cache.GetById(id.ToString());

        if (dataById == null)
        {
            var products = cache.GetAll("all");
            if (products == null)
            {
                product = _iRepo.Get(id);
                cache.Save(id.ToString(), product);
            }
            else
            {
                product = products.FirstOrDefault(b => b.ProductId == id);
                cache.Save(id.ToString(), product);
            }
        }
        else
        {
            product = dataById;
        }
        return product;
    }

    public IEnumerable<Product> GetAll()
    {
        var data = cache.GetAll("all");
        if (data == null)
        {
            data = _iRepo.GetAll().ToList();
            var productsList = JsonConvert.SerializeObject(data);
            cache.Save("all", productsList);
        }

        return data;
    }

    public long Update(int id, Product model)
    {
        var data = _iRepo.Update(id, model);
        cache.Delete(id.ToString());
        cache.Delete("all");
        return data;
    }
}

Step3: Add Redis key in appsettings.json file, if you want to use redis cache

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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