开发者

Django: how to cache dynamic pages flexibly?

I was trying to set up cache for my Django application but it seems that Django's caching framework is based on TIMEOUT: set a cache and it'll remain valid for the TIMEOUT amount of seconds.

That seems pretty useless for most situations. Most webpages would have some user contributed contents such as comments or votes or forum posts. A timeout cache mechanism wouldn't work there. What is needed would be some way to invalidate caches: when a user submits a comment or a 开发者_开发问答vote, the cache for that page needs to be invalidated.

Is there any way to do that in Django? If not, how do you cache pages generated by your Django application?

Thanks.


There's a way to manually delete cached items in django. Search in the documentation for cache.delete and cache.delete_many. In your django views you could programatically decide when to invalidate (or delete) the cached item based on whatever rules you want. To avoid the TIME_OUT issue just give an enough long time out to not be reached.

There are also few similar questions in SO that might help you ... see this one ...

Removing specific items from Django's cache?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜