我正在尝试存储IEnumerable<T>
到 memcached 中,但是,我只能成功存储T
.
在 memcached 中存储枚举是否有不同的代码?
public IEnumerable<UsContentView> GetContentViewByUserId(int userId)
{
Expire("contentViewUserId_" + userId);
var result = Memcached.Get<IEnumerable<UsContentView>>("contentViewUserId_" + userId);
if (result == null)
{
result = db.UsContentViews.Where(m => m.UserID == userId).OrderBy(m => m.ArticleId).Distinct();
var arr = result.ToArray();
var arrList = arr.ToList();
//store it in the cache, with the key
StoreList(arrList, "contentViewUserId_" + userId);
MemoryStream mem = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
try
{
b.Serialize(mem, result);
}
catch (EntitySqlException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (EntityCommandExecutionException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (SerializationException ex)
{
throw new ApplicationException("The object graph could not be serialized", ex);
}
}
return result;
}