View Cache in Django framework

Source: Internet
Author: User
This article mainly introduces the View-level cache in the Django framework. Django is the most popular Pythonweb development framework, for more information about the cache framework, see cache the output of a single view. Django. views. decorators. cache defines a cache_page modifier that automatically caches View responses. It is easy to use:

From django. views. decorators. cache import cache_pagedef my_view (request): #... my_view = cache_page (my_view, 60*15)

You can also use the decorator syntax of Python2.4:

@ Cache_page (60*15) def my_view (request ):#...

Cache_page only accepts one parameter: cache timeout in seconds. In the response, the results of the "my_view ()" view will be cached for 15 minutes. (Note: to improve readability, this parameter is written as 60*15. 60*15 is calculated as 900, that is, 15 minutes multiplied by 60 seconds per minute .)

Like the site cache, the View Cache has nothing to do with the URL. If multiple URLs direct to the same view, each view is cached separately. Continue to the my_view example. if URLconf is as follows:

Urlpatterns = ('', (r' ^ foo/(\ d {1, 2})/$ ', my_view ),)

As expected, requests sent to/foo/1/and/foo/23/will be cached separately. However, once a specific request (such as/foo/23/) is sent, the request directed to the URL again will be cached.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.