3

sweetpie api 不支持上传文件,所以我必须使用普通视图功能,查看我的其他问题

这是我的图片资源

 class ImageResource(ModelResource):
     album = fields.ForeignKey(AlbumResource, 'album')
     upload_by = fields.ForeignKey(UserResource, 'upload_by')

     class Meta:
         always_return_data=True
         filtering = {
                 "album": ('exact',),
                  }
         queryset = Image.objects.all()
         cache = SimpleCache(timeout=100)
         resource_name = 'image'
         authorization = ImageAuthorization()

现在假设我在普通视图功能中上传图像,因为我将缓存超时设置为 100 秒,浏览器不会在 100 秒内更新查询。

我想要的是浏览器在图像上传后立即更新查询,如果没有任何改变,则将缓存超时保持为 100 秒。这必须在正常视图功能中完成。

我怎样才能做到这一点?

4

1 回答 1

0

如果您愿意,可以手动清除缓存。Tastypie 的缓存键看起来像这样(如果您使用的是 simpleCache)

def generate_cache_key(self, *args, **kwargs):
    """
    Creates a unique-enough cache key.

    This is based off the current api_name/resource_name/args/kwargs.
    """
    smooshed = []

    for key, value in kwargs.items():
        smooshed.append("%s=%s" % (key, value))

    # Use a list plus a ``.join()`` because it's faster than concatenation.
    return "%s:%s:%s:%s" % (self._meta.api_name, self._meta.resource_name, ':'.join(args), ':'.join(smooshed))

(直接来自当前第 1031 行的代码)

您可以在 shell 中玩耍,以确保您准确地命中了您正在寻找的对象。完成后,只需在上传文件时删除该条目即可。

于 2013-06-10T05:58:05.433 回答