开发者

How can i config my CACHE_BACKEND

when i deal with session and page cache,i get a problem. i use memcache to store my session info, and i would like to use file to cache the 开发者_JS百科site page. The quesion is they both use CACHE_BACKEND, if i make it like this: CACHE_BACKEND = 'memcached://127.0.0.1:11211/', then how can i make my page cache work with file?


You have three possibilities:

0) use Beaker http://beaker.groovie.org/index.html

1) Do not use memcache for session storing but use the db session engine by adding 'django.contrib.sessions' to your INSTALLED_APPS (do not forget to syncdb to create the session tables). If you have concerns about performance you could use an in-memory table engine.

2) Implement your own session engine that use a separate cache:

SESSION_ENGINE='yourapp.session_engine' SESSION_CACHE_BACKEND='memcached://127.0.0.1:11211/'

then in session_engine.py something like (untested):

from django.contrib.sessions.backend.cache import SessionStore as BaseSessionStore from django.core.cache import get_cache from django.conf import settings

class SessionStore(BaseSessionStore): def init(self, session_key=None): super(SessionStore, self).init(session_key) self._cache = get_cache(settings.SESSION_CACHE_BACKEND)


django 1.3 will be released soon and there will be support for multiple cache backends (look at the development docs: http://docs.djangoproject.com/en/dev//topics/cache/).

You can use latest django svn checkout (it is not uncommon, django svn is quite stable) or just wait a couple of weeks for a release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜