首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows缓存top10图片小块

Windows缓存top10图片小块
EN

Stack Overflow用户
提问于 2014-04-13 15:05:17
回答 1查看 121关注 0票数 0

你好,各位程序员,

首先,我想说我的缓存是新的,以前从未使用过。

这是一个有桌子和blob存储的天蓝色网站。我在使用Azure缓存服务。我想要缓存我的top10 blob图片。我的top10视图使用@model IEnumerable

在使用缓存之前,这是我的top10操作:(工作)

代码语言:javascript
复制
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操作:

代码语言:javascript
复制
    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的东西,不能序列化。

我希望你们能帮我,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-15 10:23:43

我想这是品味的问题。我下一次尝试输出缓存,但它解决不了这个问题。

我通过添加:select e).Take(10).ToList();来解决这个问题

谢谢你的帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23044326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档