django-cache

Django staticgenerator vs CACHE_BACKEND

依然范特西╮ 提交于 2019-12-23 03:53:30
问题 Is there any difference between staticgenerator and useing Django's CACHE_BACKEND on the filesystem eg. CACHE_BACKEND = 'file:///var/tmp/django_cache' ? 回答1: Yes. StaticGenerator generates static HTML files to bypass Django entirely . Any caching that django does such as the filesystem cache is still processed by django. A lot of the overhead of running your app is still there: django processes a request, goes through middlewares, checks filesystem cache for content, etc. With StaticGenerator

django querysets + memcached: best practices

こ雲淡風輕ζ 提交于 2019-12-18 12:15:53
问题 Trying to understand what happens during a django low-level cache.set() Particularly, details about what part of the queryset gets stored in memcached. First, am I interpreting the django docs correctly? a queryset (python object) has/maintains its own cache access to the database is lazy; even if the queryset.count is 1000, if I do an object.get for 1 record, then the dbase will only be accessed once, for that 1 record. when accessing a django view via apache prefork MPM, everytime that a

Caching queryset choices for ModelChoiceField or ModelMultipleChoiceField in a Django form

爷,独闯天下 提交于 2019-12-17 22:42:28
问题 When using ModelChoiceField or ModelMultipleChoiceField in a Django form, is there a way to pass in a cached set of choices? Currently, if I specify the choices via the queryset parameter, it results in a database hit. I'd like to cache these choices using memcached and prevent unnecessary hits to the database when displaying a form with such a field. 回答1: You can override "all" method in QuerySet something like from django.db import models class AllMethodCachingQueryset(models.query.QuerySet

How to cache a view only for unauthenticated users?

◇◆丶佛笑我妖孽 提交于 2019-12-14 03:05:42
问题 I have a view which I want to cache only for unauthenticated users. The view should be something like this: @cache_page_for_guests(60 * 15) def my_view(request): I've looked at the docs but could not but could not find any hints about this. Actually my question is exactly as this, which is unanswered, and I could not make sense of the comments. So appreciate your help. 回答1: Write a custom decorator like this: from django.views.decorators.cache import cache_page def cache_page_for_guests(cache

Django can't clear database cache on Oracle backend

可紊 提交于 2019-12-11 18:01:44
问题 I have one row in my oracle cache table. I'm trying to clear it using standard django way: from django.core.cache import cache cache.clear() But it doesn't work! The row is still in my cache table. So I run python manage.py sell and put some code from DatabaseCache.clear() method: from django.db import connections table = connections['cache'].ops.quote_name('ws_cache_table') cursor = connections['cache'].cursor() cursor.execute('DELETE FROM %s' % table) But it doesn't work either... I don't

Clearing specific cache in Django

百般思念 提交于 2019-12-09 10:16:46
问题 I am using view caching for a django project. It says the cache uses the URL as the key, so I'm wondering how to clear the cache of one of the keys if a user updates/deletes the object. An example: A user posts a blog post to domain.com/post/1234/ .. If the user edits that, i'd like to delete the cached version of that URL by adding some kind of delete cache command at the end of the view that saves the edited post. I'm using: @cache_page(60 * 60) def post_page(....): If the post.id is 1234,

Will Django's cache modules work on Google App Engine?

我的未来我决定 提交于 2019-12-07 10:31:26
问题 I am running Django (1.0.2) on Google App Engine, and would like to know which (if any) of the following Django caching modules ought to inherently work with Google's memcache implementation: Middlewear django.middleware.cache.UpdateCacheMiddleware django.middleware.common.CommonMiddleware django.middleware.cache.FetchFromCacheMiddleware Decorators django.views.decorators.cache.cache_page Template fragment caching In a template: {{ load cache }}{% cache 500 cache_name %}...cached...{%

How do I access template cache? - Django

淺唱寂寞╮ 提交于 2019-12-04 10:52:49
问题 I am caching html within a few templates e.g.: {% cache 900 stats %} {{ stats }} {% endcache %} Can I access the cache using the low level library? e.g. html = cache.get('stats') I really need to have some fine-grained control over the template caching :) Any ideas? Thanks everyone! :D 回答1: This is how I access the template cache in my project: from django.utils.hashcompat import md5_constructor from django.utils.http import urlquote def someView(request): variables = [var1, var2, var3] hash

Clearing specific cache in Django

陌路散爱 提交于 2019-12-03 12:42:29
I am using view caching for a django project. It says the cache uses the URL as the key, so I'm wondering how to clear the cache of one of the keys if a user updates/deletes the object. An example: A user posts a blog post to domain.com/post/1234/ .. If the user edits that, i'd like to delete the cached version of that URL by adding some kind of delete cache command at the end of the view that saves the edited post. I'm using: @cache_page(60 * 60) def post_page(....): If the post.id is 1234, it seems like this might work, but it's not: def edit_post(....): # stuff that saves the edits cache