我剛安裝Membase的和enyim客戶端.NET和跨提到這個技術集成LINQ的論文是:Membase的服務器,並Enyim - 整合LINQ和/或集合
public static IEnumerable<T> CachedQuery<T>
(this IQueryable<T> query, MembaseClient cache, string key) where T : class
{
object result;
if (cache.TryGet(key, out result))
{
return (IEnumerable<T>)result;
}
else
{
IEnumerable<T> items = query.ToList();
cache.Store(StoreMode.Set, key, items);
return items;
}
}
它會檢查如果所需數據首先在緩存中,並且如果不緩存則返回。
目前我在我的應用程序中使用了Dictionary<'String, List'>
,並且想用membase/memcached類型的方法替換它。
將項目添加到列表<'T'>或在緩存列表上使用Linq運算符的類似模式怎麼樣?在我看來,將單個密鑰下的整個列表「<'T'>存儲在單個密鑰下並且必須檢索它,添加到它,然後在每次要添加元件。或者這是一種可接受的做法?
public bool Add(T item)
{
object list;
if (cache.TryGet(this.Key, out list))
{
var _list = list as List<T>;
_list.Add(item);
return cache.Store(StoreMode.Set, this.Key, _list);
}
else
{
var _list = new List<T>(new T[] { item });
return cache.Store(StoreMode.Set, this.Key, _list);
}
}
如何集合通常在這樣的情況下緩存處理?通常是使用散列算法,還是使用某種鍵前綴系統來在緩存的鍵值存儲中標識類型T的「列表」?