【发布时间】:2017-04-13 19:00:24
【问题描述】:
我想知道是否有办法在指定的到期日期后从我的 c# 服务中清除/刷新整个缓存。如何在 c# 中实现这一点?
C#
// library
using StackExchange.Redis;
public class RedisCacheService
{
// Fields
ConnectionMultiplexer _Redis = null;
IDatabase _RedisDB = null;
// ctor
public RedisCacheService(String redisConnectionString) // , DateTime ExpiryDate ? - Extracted from config
{
try
{
if (String.IsNullOrEmpty(redisConnectionString))
{
throw new Exception("The 'redisConnectionString' parameter is unassigned");
}
this._Redis = ConnectionMultiplexer.Connect(redisConString);
if (_Redis == null)
{
throw new Exception("_Redis object not initialized");
}
this._RedisDB = _Redis.GetDatabase();
// I need to set some sort of expiry config here in the constructor.
// The redisConnectionString is passed through when an instance of this class is created in the host startup and
// the redisConnectionString is extracted from the config.
}
catch (Exception e)
{
throw new Exception(e);
}
}
}
我看到了一个类似的解决方案,当我实际使用对象填充缓存时,我可以传递一个过期时间,但我更想要一个全局缓存清除解决方案。
任何帮助或建议将不胜感激。
【问题讨论】: