【发布时间】:2017-05-10 13:25:48
【问题描述】:
首先,图书馆的链接:ServiceStack.Redis
现在,我正在研究一些通用缓存机制,目前支持 4 种方法:
Put、Get、PutMany、GetMany
问题是,每当我想插入大量记录时,我没有选项(对我可见)添加过期时间,不像 Put - 我可以。
代码很直接:
public void PutMany(ICollection<T> items)
{
TimeSpan expiration = GetExpiration();
DateTime expire = DateTime.UtcNow.Add(expiration);
Dictionary<string, CachedItem<T>> dict = new Dictionary<string, CachedItem<T>>();
foreach (T item in items)
{
CachedItem<T> cacheItem = new CachedItem<T>(item, expire);
if (!dict.ContainsKey(cacheItem.Id))
dict.Add(cacheItem.Id, cacheItem);
}
// Store item in cache
_client.SetAll(dict);
}
CachedItem<T> 的模型是我的,把它想象成某种物体。
如您所见,我没有设置过期时间的选项。
有没有办法(除了使用_client.Set() 逐个插入它们)来实现这一点?
TIA。
附言
我知道我可以将所有记录存储在列表或哈希中,我不希望所有记录都有一个到期日期(错误,并且在到期时会导致非常严重的性能问题)
【问题讨论】:
标签: c# caching redis servicestack servicestack.redis