DevelopmentFast.Cache
Uma biblioteca para ajudar no rápido desenvolvimento para aplicar camada de Cache utilizando Redis, usando Repository Pattern.
Development Fast - Cache
Package | Version | Popularity |
---|---|---|
DevelopmentFast.Cache |
📌 It is a .NET library with the responsibility to help in the fast development to apply Cache layer using Redis, using Repository Pattern. What is it ?
📌 To make development easier and save the time I had to configure a cache layer to apply anywhere in the project. Why i created ?
📌 It is available on .Nuget.org Where is it available ?
Nuget Link
Install-Package DevelopmentFast.CacheRedis -Version 1.0.1
How to use ?
Dependency and connection injections
builder.Services.AddSingleton<IDistributedCache, RedisCache>();
builder.Services.AddStackExchangeRedisCache(x => x.Configuration = "localhost:6379");
Or
//Scoped
services.AddScopedRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
//Transient
services.AddTransientRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
//Singleton
services.AddSingletonRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
Constructor
private readonly IBaseRedisRepositoryDF _baseRedisRepositoryDF;
public StudentController(IBaseRedisRepositoryDF baseRedisRepositoryDF)
{
this._baseRedisRepositoryDF = baseRedisRepositoryDF;
}
Create or Update asynchronous
var student = new Student("name_student");
await _baseRedisRepositoryDF.CreateOrUpdateAsync<Student>("key_example", student , TimeSpan.FromMinutes(1));
Create or Update synchronous
var student = new Student("name_student");
_baseRedisRepositoryDF.CreateOrUpdate<Student>("key_example", student , TimeSpan.FromMinutes(1));
Get asynchronous
var student = await _baseRedisRepositoryDF.GetAsync<Student>("key_example");
Get synchronous
var student = _baseRedisRepositoryDF.Get<Student>("key_example");
Remove synchronous
_baseRedisRepositoryDF.Remove("key_example");
Remove asynchronous
_baseRedisRepositoryDF.RemoveAsync("key_example");
Refresh synchronous
_baseRedisRepositoryDF.Refresh("key_example");
Refresh asynchronous
_baseRedisRepositoryDF.RefreshAsync("key_example");