Database data caching in Django?...

59 views
Skip to first unread message

Fred Stluka

unread,
Aug 17, 2016, 3:34:33 PM8/17/16
to django-users -- mailing list
Django users,

Is there an easy way to enable an automatic write-through
database cache in Django?

I'd want memcached or something to cache all data read by the
Django ORM and use the cached copy on future reads, and of
course update the cache as well as the DB (a "write-through"
cache) when writing data.

Is there a piece of middleware I can activate to cause the ORM
to do this automatically for all DB queries?  Thanks!

Details:

I'm interested in caching the results of queries to the DB, not
caching the results of templates or views.  So, it is different
from the following, which I already know how to do:
- Caching of template files:
   - http://us5.campaign-archive1.com/?u=a8d4be66d1927077a9255182d&id=a6f7d644a7&e=c90970e145
   - https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
- Caching of all Django views for an entire site:
   - https://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache
- Caching of specific Django views:
  - https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache
- Caching of fragments of a Django Template:
  - https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching

I'm also hoping to not have to add cache API calls throughout my
code, as described here:
- https://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api

I'd like the Django ORM to make the API calls for me automatically
when I call objects.get(), objects.filter(), save(), etc.  I'd hoped to
enable it simply by adding middleware or a custom manager or
something.

Any suggestions?  I feel like I may be missing something obvious.

--Fred

Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Tim Graham

unread,
Aug 17, 2016, 4:43:54 PM8/17/16
to Django users
I did a quick search and found https://github.com/BertrandBordage/django-cachalot. Does it meet your requirements?

Avraham Serour

unread,
Aug 17, 2016, 5:13:11 PM8/17/16
to django-users

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c778bee7-eb39-4d95-ba23-acfb5e998dc8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ravi Bhushan

unread,
Jul 9, 2018, 5:07:51 AM7/9/18
to Django users
Reply all
Reply to author
Forward
0 new messages