我尝试在我的 Django 网站上安装 johnny 缓存。
所以我设置了所有与 johnny 缓存相关的设置,如下所示:
CACHES = {
'default': {
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'BACKEND': 'johnny.backends.memcached.MemcachedCache',
'JOHNNY_CACHE': True,
}
}
到目前为止,整个项目仍然在生产模式下正常运行。
但是在设置中间件后立即
'johnny.middleware.LocalStoreClearMiddleware'
和 'johnny.middleware.QueryCacheMiddleware'
我得到以下异常:Environment:
Request Method: GET
Django Version: 1.3.1
Python Version: 2.6.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'core_knowledge_platform.core_web_service',
'south']
Installed Middleware:
('johnny.middleware.LocalStoreClearMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'johnny.middleware.QueryCacheMiddleware')
Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
117. response = middleware_method(request, e)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/u1/msc/vg55/public_html/core_knowledge_web_platform/core_knowledge_platform/core_web_service/views.py" in __call__
95. return getattr(self, method)(request, *args, **kwargs)
File "/u1/msc/vg55/public_html/core_knowledge_web_platform/core_knowledge_platform/core_web_service/views.py" in GET
673. if not access.validate_user_is_editor(request.user):
File "/u1/msc/vg55/public_html/core_knowledge_web_platform/core_knowledge_platform/core_web_service/business_logic/access.py" in validate_user_is_editor
38. if papergroups:
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in __nonzero__
113. iter(self).next()
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in _result_iter
107. self._fill_cache()
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in _fill_cache
772. self._result_cache.append(self._iter.next())
File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in iterator
273. for row in compiler.results_iter():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in results_iter
698. row = self.resolve_columns(row, fields)
File "/usr/lib/python2.6/site-packages/django/db/backends/mysql/compiler.py" in resolve_columns
12. return row[:index_extra_select] + tuple(values)
Exception Type: TypeError at /publication/
Exception Value: cannot concatenate 'str' and 'tuple' objects
注意:约翰尼缓存未在 INSTALLED_APPS 中设置,因为文档说它没用
编辑 :
好吧,我发现只有在缓存命中时才会抛出异常。
当我等待 memcached 中存储的值过期时,然后在加载页面上,没有抛出异常...
为了给我的问题添加更多阴影,当我在 localhost 中激活 johnny 的情况下运行整个项目时,一切正常。但是当我在生产环境(Apache/2.2.15(CentOS))中运行它时,会抛出异常......
并且两个环境下的 django 版本完全一样:1.3.1
注意:我已经按照 okm 的指定设置了中间件顺序
谢谢
最佳答案
我遇到了完全相同的问题。虽然我仍在试图深入了解它的确切含义,但我发现了一些有用的东西。
我已经检查了我的配置并尝试了很多东西,就像你一样,这不是问题。
希望这可以帮助。
编辑:
更多的挖掘表明,这个提交 bcdb46c5d357 出现了问题,它添加了代码来缓存返回 null 的查询:https://bitbucket.org/jmoiron/johnny-cache/changeset/bcdb46c5d357
如果您坚持使用较早的方法,它应该会起作用。
关于django - 无法连接 'str' 和 'tuple' 对象 - Django - johnny 缓存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10090753/