你好,各位程序员,
首先,我想说我的缓存是新的,以前从未使用过。
这是一个有桌子和blob存储的天蓝色网站。我在使用Azure缓存服务。我想要缓存我的top10 blob图片。我的top10视图使用@model IEnumerable
在使用缓存之前,这是我的top10操作:(工作)
public ActionResult TopPictures()
{
picturesList.Clear();
CloudTable table = _Service.GetCloudTable();
CloudBlobContainer blob = _Service.GetCloudBlobContainer();
TableQuery<PictureEntity> query = new TableQuery<PictureEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "bilder"));
var tablelist = table.ExecuteQuery(query);
var entity = (from e in tablelist
orderby e.AverageRating descending
select e).Take(10);
return View(entity);
}这是我在使用缓存之后的top10操作:
DataCache cache = new DataCache("default");
public ActionResult TopPictures()
{
picturesList.Clear();
CloudTable table = _Service.GetCloudTable();
CloudBlobContainer blob = _Service.GetCloudBlobContainer();
var cache = new DataCache("default");
object cacheTop = cache.Get("top");
if (cacheTop == null)
{
TableQuery<PictureEntity> query = new TableQuery<PictureEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "bilder"));
var tablelist = table.ExecuteQuery(query);
var entity = (from e in tablelist
orderby e.AverageRating descending
select e).Take(10);
cache.Add("top", entity);
return View(entity);
}
return View(cacheTop);
}我把东西还给你了吗?(cachetop (如果不是null)和实体(如果为null )
当我导航到top10时,我在cache.Add("top",entity)上得到了一个InvalidDataContractException;这个错误提到了一些关于PictureEntity的东西,不能序列化。
我希望你们能帮我,谢谢
发布于 2014-04-15 10:23:43
我想这是品味的问题。我下一次尝试输出缓存,但它解决不了这个问题。
我通过添加:select e).Take(10).ToList();来解决这个问题
谢谢你的帮助:)
https://stackoverflow.com/questions/23044326
复制相似问题