Cache.MemoryCache/MemoryCacheHandler.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
namespace Cache.MemoryCache
{
public class MemoryCacheHandler : ICacheHandler
{
private readonly IMemoryCache _cache;
public MemoryCacheHandler(IMemoryCache cache)
{
_cache = cache;
}
public string Get(string key)
{
var value = _cache.Get(key);
return value?.ToString();
}
public T Get<T>(string key)
{
return _cache.Get<T>(key);
}
public Task<string> GetAsync(string key)
{
var value = Get(key);
return Task.FromResult(value);
}
public Task<T> GetAsync<T>(string key)
{
return Task.FromResult(_cache.Get<T>(key));
}
public bool TryGetValue(string key, out string value)
{
return _cache.TryGetValue(key, out value);
}
public bool TryGetValue<T>(string key, out T value)
{
return _cache.TryGetValue(key, out value);
}
public bool Set<T>(string key, T value)
{
_cache.Set(key, value);
return true;
}
public bool Set<T>(string key, T value, int expires)
{
_cache.Set(key, value, new TimeSpan(0, 0, expires, 0));
后面还有 64 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。