given a URL,try finding that page in the cache
if the page isin the cache:return the cached page
else:
generate the page
save the generated page in the cache (fornext time)return the generated page
given a URL,try finding that page in the cache
if the page isin the cache:return the cached page
else:
generate the page
save the generated page in the cache (fornext time)return the generated page
classCacheRouter:"""A router to control all database cache operations"""defdb_for_read(self, model,**hints):"All cache read operations go to the replica"if model._meta.app_label =='django_cache':return'cache_replica'returnNonedefdb_for_write(self, model,**hints):"All cache write operations go to primary"if model._meta.app_label =='django_cache':return'cache_primary'returnNonedefallow_migrate(self, db, app_label, model_name=None,**hints):"Only install the cache model on primary"if app_label =='django_cache':return db =='cache_primary'returnNone
from django.views.decorators.cache import cache_page
@cache_page(60*15)defviewArticles(request, year, month):
text ="Displaying articles of : %s/%s"%(year, month)return HttpResponse(text)