我正在尝试在我的开发机器上设置Johnny Cache,但遇到了一些问题。使用基于文件的缓存,如下所示:
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 :(得分: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',
]