i know the django has some cache method such as the The per-site cache,The per-view cache,Specifying per-view cache and Template fragment caching
but what’s differece between those cache ?
the per-site cache means the cache system cache the whole site ?
how can i understand the words ‘cache the whole site’?
i know the django has some cache method such as the The per-site cache,The
Share
I think the docs do a great job of describing this but I will paste it here and give a little description as well.
Cache the whole site means django will attempt to cache every view you’ve set up via middleware.
Per site cache docs
http://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache
Basically, it’s a set of middleware so it caches all views. Middleware is applied to every request/response.
Per view cache docs
http://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache
This is a per view cache. You can decide to cache a certain view by applying the
@cache_pagedecorator to a specific view (as opposed to ALL views above)Template fragment cache docs
http://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching
This lets you cache chunks of your template (as opposed to an entire view above), so for example you could cache an expensive query in your template while other pieces of the site are still served dynamically.
This would be useful if certain pieces can’t be cached.. for example the classic problem of displaying a logged in user at the top wouldn’t be possible with a per view cache, as the user would need to be updated and thus the cache invalidated.
If you read further in the docs, you’ll reach the cache api as well:
Cache api docs
http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api
This is basically how you get control over the cache in python code (as opposed to the template, above).