2012-02-29 62 views
2

我想在我的開發機器上設置約翰尼緩存,但我遇到了一些問題。使用基於文件的緩存是這樣的:配置約翰尼緩存

CACHES = { 
    'default' : dict(
     BACKEND= 'johnny.backends.filebased.FileBasedCache', 
     LOCATION= '/tmp', 
    ) 
} 

MIDDLEWARE_CLASSES = (
    'johnny.middleware.LocalStoreClearMiddleware', 
    'johnny.middleware.QueryCacheMiddleware', 
) 

我得到:

Traceback (most recent call last): 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 283, in run 
    self.result = application(self.environ, self.start_response) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__ 
    return self.application(environ, start_response) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 273, in __call__ 
    response = self.get_response(request) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/core/handlers/base.py", line 168, in get_response 
    receivers = signals.got_request_exception.send(sender=self.__class__, request=request) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send 
    response = receiver(signal=self, sender=sender, **named) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/db/transaction.py", line 222, in inner 
    self.__exit__(None, None, None) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/db/transaction.py", line 207, in __exit__ 
    self.exiting(exc_value, self.using) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/django/db/transaction.py", line 281, in exiting 
    commit(using=using) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/johnny/transaction.py", line 147, in newfun 
    self._flush(commit=commit, using=using) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/johnny/transaction.py", line 135, in _flush 
    self.cache_backend.set(key, value, self.timeout) 
    File "/Users/kitsunde/.virtualenvs/media-pop/lib/python2.7/site-packages/johnny/backends/filebased.py", line 23, in set 
    return super(CacheClass, self).set(key, value, timeout=timeout, **kwargs) 
NameError: global name 'kwargs' is not defined 

如果我嘗試使用基於一個記憶:

CACHES = { 
    'default' : { 
     'BACKEND': 'johnny.backends.locmem.LocMemCache', 
    } 
} 

連接只是掛在那裏。我現在打開了零緩存。任何想法如何設置?

+0

你發現了一個在JohnnyCache基於文件的後端的錯誤。請注意,我具有相同的版本,Memcached後端可以工作,因此您可以使用它。 – jpic 2012-02-29 07:36:07

回答

1

您在JohnnyCache文件的後端發現了一個錯誤。我有同樣的錯誤,但是我設法讓FileBased後端工作。我通過將這些代碼放在settings.py中修正了這個錯誤:

import sys 
from johnny.backends import filebased 
def fixed_set(self, key, value, timeout=None): 
    if timeout is 0: 
     timeout = sys.maxint 
    return super(filebased.CacheClass, self).set(key, value, timeout=timeout) 
filebased.CacheClass.set = fixed_set 

但是,您應該報告錯誤。

注意:我推薦的memcached後端開箱即用,超級超快!

我不明白你爲什麼只有兩個中間件。你不應該有這樣的:

MIDDLEWARE_CLASSES = [ 
    'johnny.middleware.LocalStoreClearMiddleware', 
    'johnny.middleware.QueryCacheMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.transaction.TransactionMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
]