Code pull completed, the page will refresh automatically
var services = new ServiceCollection();
services.AddMemoryCache(options => { });
services.AddSingleton(provider => new RedisService("localhost:32768"));
services.AddDistributedRedisCache(options => { options.InstanceName = "local"; });
services.AddSingleton<ICacheSerializer, JsonCacheSerializer>();
services.AddSingleton<ICacheProvider, DistributedCacheProvider>();
services.AddSingleton<CacheFactory>();
class PostManager
{
private readonly ICache _cache;
public PostManager(CacheFactory cacheFactory)
{
_cache = cacheFactory.GetCache("Post");
}
public Post Get(int id)
{
var key = CacheKey.NewCacheKeyString(id); // конечный формат: local:Post:{id}
var data = _cache.Get<Post>(key);
if (data == null)
{
// TODO: получить данные из базы данных
//_cache.Set(key, data);
}
return data;
}
public void Delete(int id)
{
var key = CacheKey.NewCacheKeyString(id);
// TODO: удалить данные из базы данных
_cache.Remove(key);
}
}
You can comment after Login
Inappropriate content may be displayed here and will not be shown on the page. You can check and modify it through the relevant editing function
If you confirm that the content does not involve inappropriate language/advertisement redirection/violence/vulgar pornography/infringement/piracy/false/insignificant or illegal content related to national laws and regulations, you can click submit to make an appeal, and we will handle it as soon as possible.
Comments ( 0 )