Uma biblioteca para ajudar no rápido desenvolvimento para aplicar camada de Cache utilizando Redis, usando Repository Pattern.
Package | Version | Popularity |
---|---|---|
DevelopmentFast.Cache |
Nuget Link
Install-Package DevelopmentFast.CacheRedis -Version 1.0.1
builder.Services.AddSingleton<IDistributedCache, RedisCache>();
builder.Services.AddStackExchangeRedisCache(x => x.Configuration = "localhost:6379");
//Scoped
services.AddScopedRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
//Transient
services.AddTransientRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
//Singleton
services.AddSingletonRedisCacheDF(x =>
{
x.Configuration = "localhost:6379";
});
private readonly IBaseRedisRepositoryDF _baseRedisRepositoryDF;
public StudentController(IBaseRedisRepositoryDF baseRedisRepositoryDF)
{
this._baseRedisRepositoryDF = baseRedisRepositoryDF;
}
var student = new Student("name_student");
await _baseRedisRepositoryDF.CreateOrUpdateAsync<Student>("key_example", student , TimeSpan.FromMinutes(1));
var student = new Student("name_student");
_baseRedisRepositoryDF.CreateOrUpdate<Student>("key_example", student , TimeSpan.FromMinutes(1));
var student = await _baseRedisRepositoryDF.GetAsync<Student>("key_example");
var student = _baseRedisRepositoryDF.Get<Student>("key_example");
_baseRedisRepositoryDF.Remove("key_example");
_baseRedisRepositoryDF.RemoveAsync("key_example");
_baseRedisRepositoryDF.Refresh("key_example");
_baseRedisRepositoryDF.RefreshAsync("key_example");