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
3
votes
1 answer

Django in-memory model, not for tests

I have a model whose instances don't need to be written to database, ever. They are generated on the fly, very cheaply, and almost never change. I wish to query these instances via the ORM and also browse them in django-admin (read-only +…
frnhr
  • 12,354
  • 9
  • 63
  • 90
3
votes
2 answers

Very slow to write to Django cache

I used to cache a database query in a global variable to speed up my application. Since this is strongly unadvised (and it did generate problems), I want to use any kind of Django cache instead. I tried LocMemCache and DatabaseCache, but both…
JulienD
  • 7,102
  • 9
  • 50
  • 84
3
votes
0 answers

Django Filesystem Caching

I'm trying to get entire-site filesystem based caching working for the first time. I've created /var/tmp/django_cache with 777 permissions. I've added this to settings.py: CACHES = { 'default': { 'BACKEND':…
user3449833
  • 779
  • 2
  • 10
  • 28
3
votes
1 answer

Is Django filesystem cache thread-safe? and is it cross-process?

I need to cache lists 10MB+ size, is it safe to do it in Django filesystem cache? Or is there a better way to do it?
Bob
  • 5,809
  • 5
  • 36
  • 53
3
votes
1 answer

How can I render and cache a view programatically in Django?

I have a view in Django that is very slow to render. I'd like to render this view and cache it programmatically but haven't figured out how to do so. Is there any simple way to simply invoke my StatusView and get the markup as a string so I can…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
1 answer

Caching authenticated users in Redis?

Nearly all pages in my Django application require authentication. The app uses Django's AuthenticationMiddleware, so on every request the application hits the DB to retrieve the authenticated user. I recently started storing session data in a…
tino
  • 4,780
  • 5
  • 24
  • 30
3
votes
0 answers

mistake with django STATICFILES_STORAGE

I'm working with django, and the settings file I put the configuration for STATICFILES_STORAGE, STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'. I run collectstatic and run my app and the staticfiles has a new…
3
votes
0 answers

Prevent cache middleware from using HTTP_COOKIE to generate cache key

I'm having problems issues using the Django caching middleware. I want to cache an expensive page so that it does not need to be regenerated for each individual visitor. It seems that SessionMiddleware is setting "Vary: Cookie" in the response…
aco
  • 719
  • 2
  • 9
  • 26
3
votes
2 answers

Django-Cache Testing

Since i'm new to django-cache, I was trying to cache a particular view in Django. I'm not sure whether the data is fetched from cache or from the database. How do I verify that? Being a newbie, kindly also check that I'm caching the view correctly…
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
3
votes
2 answers

django-cache-machine and Redis

I'm trying to use django-cache-machine to cache queries within my application, but I want to use Redis as a backend. The docs don't really explain how to do this, yet the repository is filled with Redis references, so I'm pretty sure it's possible.…
acjay
  • 34,571
  • 6
  • 57
  • 100
3
votes
2 answers

Django Cache: Use Memcached and fallback to FileSystem

Simple question: My server has 1G RAM and 10GB disk-space I'm using per-site cache, and I want to use as much as possible Memcached, but when its out of space that the cache will be saved in hard disk. (All site's pages together are about 2GB) Is…
YardenST
  • 5,119
  • 2
  • 33
  • 54
3
votes
1 answer

caching queryset and filtering doubts

I'm working on an app that requires me to filter through large amount of records. I've been reading about caching QuerySets and related stuff and found some good material. For example: Caching query results in…
Omie
  • 190
  • 3
  • 12
3
votes
1 answer

TypeError can't pickle function objects (Django caching)

Why does the first example throw TypeError (can't pickle function objects) and the second one doesn't, I suppose it's got to do with QuerySet evaluation (Django 1.4)? def get_or_set_foo_cache(): if not cache.get('foo'): foo =…
Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100
3
votes
2 answers

Django - Johnny Cache for multiple processes

I've configured johnny cache with one of my applications that is hosted on apache. It is configured with memcached as the backend which runs on the same machine on the default port. The caching works fine when multiple web clients go through…
ksrini
  • 1,412
  • 2
  • 19
  • 33
2
votes
2 answers

Invalidate particular cache

I have cache tag in the base template: {% cache 100000 categories %} Categories output {% endcache %} When I add new category through Django admin, I want invalidate this cache: class CategoriesAdmin(admin.ModelAdmin): def save_model(self,…
Deadly
  • 2,034
  • 6
  • 24
  • 32