public class MemCachedHelper : ICacheHelper
{ private IMemcachedClient memcachedClient; public MemCachedHelper(IMemcachedClient memcachedClient)
{ this.memcachedClient = memcachedClient;
} public object Get(string key)
{ return memcachedClient.Get(key);
} public void Set(string key, object obj)
{
memcachedClient.Set(key, obj, int.MaxValue);
} public void Set(string key, object obj, int seconds)
{
memcachedClient.Set(key, obj, seconds);
} public void Remove(string key)
{
memcachedClient.Remove(key);
} public void RemoveAllCache()
{
memcachedClient.FlushAll();
}
}放在类库项目中。那这个MemCachedHelper要如何使用?参数是?MemCachedHelper cache= new MemCachedHelper (????);
1 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
Startup 中注册到依赖注入容器
public void ConfigureServices(IServiceCollection services){ services.AddTransient<MemCachedHelper>(); }
使用的地方通过构造函数注入
public class UserService{ private readonly MemCachedHelper _memCachedHelper; public UserService(MemCachedHelper memCachedHelper) { _memCachedHelper = memCachedHelper; } }
- 1 回答
- 0 关注
- 765 浏览
添加回答
举报
0/150
提交
取消