caching - Django: Cached items not accessible between processes? -
i have problems using django cache. looks cached items not readable between processes. design? haven't found information on it.
testing on production server using 2 ssh sessions in parallel, , setting cache in 1 , reading in other using memcache backend (also tested file based backend), , result:
(session 1):
>>> django.core.cache import cache >>> cache.set('foo','bar') >>> cache.get('foo') 'bar'
(session 2):
>>> 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, expect 'bar' here 0
i use low level cache api cache processed results of uploaded file. user complete more steps describe uploaded data @ point it's entered in db. done asynchronously using apache2 1 thread per process, mod_wsgi , python 2.5. problem ran in "cache.get('<filekey>')"
returns none when test , upload file.
thanks
django's cache system abstraction layer several different cache backends. although allows interact them using same api behave differently depending on 1 have configured. see documentation full details.
you configure backend use using cache_backend setting in settings.py file. if don't set setting you'll simple, in-process, cache explain why you're not able access cache values set in other processes. suggest @ memcached , use backend. it's fast, scalable , easy configure.
Comments
Post a Comment