Django: Cached items not accessible between processes?
Question: I have problems using the django cache. It looks like the cached items are not
readable between processes. Is that by design? I haven't found any information
on it.

Testing on the production server using two ssh sessions in parallel, and
setting the cache in one and reading in the other using the memcache backend
(also tested with file based backend), and this was the result:

(session 1):

    
    
    >>> from django.core.cache import cache
    >>> cache.set('foo','bar')
    >>> cache.get('foo')
    'bar'
    

(session 2):

    
    
    >>> from django.core.cache import cache
    >>> cache.get('foo', 0) #Cache has not been set yet...
    0
    >>> cache.get('foo', 0) #Cache has been set in other session, I expect 'bar' here
    0
    

I use the low level cache api to cache the processed results of an uploaded
file. The user then complete some more steps that describe the uploaded data
at which point it's entered in the DB. This is done asynchronously using
apache2 with one thread per process, mod_wsgi and python 2.5. The problem I
ran in to was that the `"cache.get('<filekey>')"` always returns None when I
test and upload a file.

Thanks


Answer: Django's cache system is an abstraction layer for several different cache
backends. Although it allows you to interact with them using the same API they
will behave differently depending on which one you have configured. See the
[documentation](http://docs.djangoproject.com/en/dev/topics/cache/) for the
full details.

You configure which backend to use using the CACHE_BACKEND setting in your
settings.py file. If you don't set that setting then you'll get a simple, in-
process, cache which would explain why you're not able to access cache values
set in other processes. I would suggest that you look at
[memcached](http://memcached.org/) and use that your backend. It's very fast,
very scalable and also very easy to configure.

