Questions tagged [django-cache]

Django includes a cache system that lets you save dynamic pages or page fragments so they don't have to be generated for each request.

Django comes with a robust cache system that lets you save dynamic pages so they don't have to be calculated for each request. For convenience, Django offers different levels of cache granularity: You can cache the output of specific views, you can cache only the pieces that are difficult to produce, or you can cache your entire site.

Django also works well with "upstream" caches, such as Squid and browser-based caches. These are the types of caches that you don't directly control but to which you can provide hints (via HTTP headers) about which parts of your site should be cached, and how.

See also:

248 questions
5
votes
1 answer

Which Django Caching System is Faster: Filesystem or DB?

I know there isn't necessarily a clear cut between these two like there is between Memcached an DB/Filesystem, but I'm wondering what conditions would lead to filesystem being faster than DB caching. And, conversely, under what conditions would DB…
Arion
  • 1,792
  • 2
  • 18
  • 29
5
votes
2 answers

memcache on django is not working

I have a race condition in Celery. Inspired by this - http://ask.github.io/celery/cookbook/tasks.html#ensuring-a-task-is-only-executed-one-at-a-time I decided to use memcache to add locks to my tasks. These are the changes I…
suprita shankar
  • 1,554
  • 2
  • 16
  • 47
5
votes
1 answer

How to enable @cache_page for some of the Django Rest Framework views?

I have basic rest framework setup: url(r'^items/$', ItemList.as_view(), name='item-list'), ... class ItemList(generics.ListCreateAPIView): model = Item serializer_class = ItemSerializer I want to cache this request using @cache_page…
serg
  • 109,619
  • 77
  • 317
  • 330
5
votes
1 answer

Django global data for threads

I have a shared global data object in my single-process multi-threaded django server - an object which is frequently used, but calculated infrequently. The calculation is time-consuming, so I want to share the results. I thought it would work to…
5
votes
2 answers

Caching non-view returns

I have a dozen or so permission lookups on views that make sure users have the right permissions to do something on the system (ie make sure they're in the right group, if they can edit their profile, if they're group administrators, etc). A check…
Oli
  • 235,628
  • 64
  • 220
  • 299
4
votes
2 answers

Django - how to invalidate per-view cache?

I want to use per-view cache. I know how it's working, but where's the problem? How can I invalidate that cache? I must do it each time database records are changed. There is no info about how to do that:/
robos85
  • 2,484
  • 5
  • 32
  • 36
4
votes
2 answers

Django multiple caching BACKEND routers howto?

So I want to cache some data in mysql and some in memcached. at the moment I have this In my config file, but i don't know how to write router for cache back end. CACHES = { 'default': { 'BACKEND':…
derevo
  • 9,048
  • 2
  • 22
  • 19
4
votes
2 answers

How can I expire entries to Django database cache?

I have a Django application with a registered database cache: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'exchange_rate_cache', } } I want the entries in my cache to expire…
Tom Finet
  • 2,056
  • 6
  • 30
  • 54
4
votes
3 answers

Django-select2 throwing 'Results cannot be loaded.'

I'm trying to deploy my django application in a Droplet virtual machine (DigitalOcean) following this guide. For this purpose I've used nginx and gunicorn with success. The problem I'm facing is with django-select2 and is that the widget of the form…
4
votes
3 answers

Caching a Django queryset for the calendar date

I have a query which results only change once a day. Seems like a waste to be performing that query every request I get for that page. I am investigating using memcached for this. How would I begin? Anyone have any suggestions or pitfalls I should…
Belmin Fernandez
  • 8,307
  • 9
  • 51
  • 75
4
votes
2 answers

How use Django Cache in view without cache all page

I trying to use Django Cache to make better my views. Works great, 400ms to 8ms is perfect. But when user access page for the first time, Django cache page with user info in header and when I try log out, page continue with user info. I try use…
GIA
  • 1,400
  • 2
  • 21
  • 38
4
votes
4 answers

django: saving a query set to session

I am trying to save query result obtained in one view to session, and retrieve it in another view, so I tried something like below: def default (request): equipment_list = Equipment.objects.all() request.session['export_querset'] =…
Hansong Li
  • 417
  • 2
  • 11
  • 26
4
votes
1 answer

How to use Elasticache with Django's MemcachedCache Backend

What's the correct way to use Amazon's Elasticache service (with the Memcached engine) with Django's MemcachedCache backend? I have a local Memcached service running locally, which works fine with the Django setting: CACHES = { 'default': { …
Cerin
  • 60,957
  • 96
  • 316
  • 522
4
votes
1 answer

Django shell doesn't respect cache configuration

In my settings.py I have: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'ws_cache_table', 'TIMEOUT': '3000000', 'OPTIONS': { 'MAX_ENTRIES': 10000000 …
mnowotka
  • 16,430
  • 18
  • 88
  • 134
4
votes
2 answers

Use middleware or a custom template tag for infrequently changing snippet

I've got a small snippet that I want in my sidebar. The snippet will be visible on each page, and while cheap to fetch (about 50ms on my super-slow netbook!), will change so infrequently that I'd quite like to cache it (partly because I've yet to…
Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
1 2
3
16 17