赞
踩
CACHE_BACKEND = ‘memcached: / / 127.0 . 0.1 : 11211 / ’ |
CACHE_BACKEND = ‘memcached: / / 172.19 . 26.240 : 11211 ; 172.19 . 26.242 : 11211 / ’ |
python manage.py createcachetable [cache_table_name] |
CACHE_BACKEND = ‘db: / / my_cache_table’ |
CACHE_BACKEND = ‘ file : / / / var / tmp / django_cache’ |
CACHE_BACKEND = ‘locmem: / / / ’ |
CACHE_BACKEND = ’simple: / / / ’ |
CACHE_BACKEND = ‘dummy: / / / ’ |
CACHE_BACKEND = “locmem: / / / ?timeout = 60 ″ |
CACHE_BACKEND = “locmem: / / / ?timeout = 30 &max_entries = 400 ″ |
MIDDLEWARE_CLASSES = ( |
'django.middleware.cache.CacheMiddleware' , |
'django.middleware.common.CommonMiddleware' , |
) |
from django.views.decorators.cache import cache_page |
@cache_page ( 60 * 15 ) |
def my_view(request, param): |
# ... |
from django.views.decorators.cache import cache_page |
urlpatterns = ('', |
(r '^foo/(\d{1,2})/$' , cache_page(my_view, 60 * 15 )), |
) |
>>> from django.core.cache import cache |
>>> cache. set (’my_key’, ‘hello, world!’, 30 ) |
>>> cache.get(’my_key’) |
‘hello, world!’ |
# Wait 30 seconds for ‘my_key’ to expire… |
>>> cache.get(’my_key’) |
None |
>>> cache.get(’some_unset_key’) |
None |
>>> cache.get(’my_key’, ‘has expired’) |
‘has expired’ |
>>> cache. set (’a', 1 ) |
>>> cache. set (’b', 2 ) |
>>> cache. set (’c', 3 ) |
>>> cache.get_many([ 'a' , 'b' , 'c' ]) |
{’a': 1 , ‘b’: 2 , ‘c’: 3 } |
>>> cache.get_many([ 'a' , 'b' , 'c' , 'd' ]) |
{’a': 1 , ‘b’: 2 , ‘c’: 3 } |
>>> cache.delete(’a') |
from django.views.decorators.vary import vary_on_headers |
@vary_on_headers ( 'User-Agent' , 'Cookie' ) |
def my_view(request): |
# ... |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。