Django way for adding a cache backend?

4 views
Skip to first unread message

Joe Bowman

unread,
Jun 3, 2008, 3:58:41 PM6/3/08
to Django developers
Hello,

I'm sure you've seen your share of new Django/Python developers come
by this group since the prerelease of Google Appengine, and I'm yet
another one. I'm trying to determine what the best way to add a cache
backend to Django might be? Preferably I'd like to do it in a way so
that it's easy to share with the user community. I'm currently working
on a project I started called appengine-utilities to provide new
classes for providing old functionality not available currently on
Appengine.

I figured out how to create a session middleware. Soon I'll be going
at inserting caching. I'm mainly working on this stuff for a site I
intend to develop, using Django. What's the preferred method for the
release of 3rd party cache backends? I'm creating on that will use
BigTable and Google's memcache solution. Should I just create it and
tell people to copy it into the directory with the default cache
backends? That appears the only way to insert a new one, but I'm so
new to Django I thought I should ask first and see if there's a
preferred way.

Jeremy Dunck

unread,
Jun 3, 2008, 4:10:23 PM6/3/08
to django-d...@googlegroups.com
On Tue, Jun 3, 2008 at 2:58 PM, Joe Bowman <bowman...@gmail.com> wrote:
....

> Should I just create it and
> tell people to copy it into the directory with the default cache
> backends? That appears the only way to insert a new one, but I'm so
> new to Django I thought I should ask first and see if there's a
> preferred way.

A directory there is currently the only way.
This line in django/core/cache/__init__.py is the culprit:

cache_class = getattr(__import__('django.core.cache.backends.%s' %
BACKENDS[scheme], {}, {}, ['']), 'CacheClass')

You could, of course, also smash the django.core.cache.cache attribute
with your own, if you wanted to be rude.

It certainly seems to me that SESSION_ENGINE (with module pathing) is
a better approach than CACHE_BACKEND (with URI-ish schemes). This
could be overcome by allowing scheme resolution to be registered. The
argument for or against is a bikeshed.

Lau Bech Lauritzen

unread,
Jun 9, 2008, 11:44:30 AM6/9/08
to Django developers
I created a ticket (including patch) that might be of interest:

http://code.djangoproject.com/ticket/7398

On Jun 3, 10:10 pm, "Jeremy Dunck" <jdu...@gmail.com> wrote:

Jacob Kaplan-Moss

unread,
Jun 9, 2008, 12:17:22 PM6/9/08
to django-d...@googlegroups.com
On Mon, Jun 9, 2008 at 10:44 AM, Lau Bech Lauritzen
<lau.la...@gmail.com> wrote:
> http://code.djangoproject.com/ticket/7398

Looks nice. Needs a quick addition to docs/settings.txt to describe
the new setting, but otherwise it's good to go.

Jacob

Joe Bowman

unread,
Jun 9, 2008, 12:43:05 PM6/9/08
to Django developers
That would be a big help for implementing backends for appengine.

I did notice a project working on an appengine helper for Django
managed to also accomplish this by creating a cache middleware. So for
others on appengine currently, using the .96 version of Django
included within the environment, this is a direction you can look at
also. I imagine there will be some lag time between a stable release
of Django and adoption by appengine.

On Jun 9, 11:44 am, Lau Bech Lauritzen <lau.laurit...@gmail.com>
wrote:

Lau Bech Lauritzen

unread,
Jun 12, 2008, 8:54:15 AM6/12/08
to Django developers
Okay, the patch is good to go. Looking forward to seeing it in trunk!

-Lau

theillustratedlife

unread,
Jul 10, 2008, 4:42:56 AM7/10/08
to Django developers
Is there an ETA for when this will be included in the SVN? I've
created a patch for Google's Appengine Helper for Django that relies
on this to load memcache. Obviously, we can't include it in the
helper until this patch is applied to the SVN.

Thanks!

Appengine backend: http://code.google.com/p/google-app-engine-django/issues/detail?id=57
Reply all
Reply to author
Forward
0 new messages