我无法弄清楚可能是什么原因。
在我的开发机器上,完全相同的django项目正常运行,而在自定义中间件代码生产中,app_cache_ready()方法始终返回False。如果我忽略并绕过它,cache.set不会缓存该对象。
我的开发环境使用runserver启动服务器,而生产使用Apache和mod_wsgi和virtualhost指令。
有没有人知道可能是什么问题?我已经花了几个小时没有成功。
提前致谢
以下是无法再次缓存的简化代码:
from django.conf import settings
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect, Http404
from django.core.cache import cache
from django.db.models.loading import app_cache_ready
from django.utils.cache import patch_vary_headers
class MyMiddleware(object):
def process_request(self, request):
key='kuku'
val=cache.get(key)
if not val:
logger.warn('Cached key is not available')
cache.set(key,5)
else:
logger.warn('Cached key is %s' % str(val))
随后的调用我看到Cached密钥总是不可用。