Cer*_*rin 10 python django memcached caching amazon-elasticache
如何在Django中更改Memcached/Elasticache缓存后端的检索超时?
我正在使用亚马逊的Elasticache在Django中缓存内容,我经常看到如下错误:
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/template/defaulttags.py", line 285, in render
return nodelist.render(context)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/template/base.py", line 830, in render
bit = self.render_node(node, context)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/template/base.py", line 844, in render_node
return node.render(context)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/templatetags/static.py", line 109, in render
url = self.url(context)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/contrib/staticfiles/templatetags/staticfiles.py", line 12, in url
return staticfiles_storage.url(path)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 136, in url
hashed_name = self.cache.get(cache_key)
File "/usr/local/myproject/.env/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 64, in get
val = self._cache.get(key)
Error: error 31 from memcached_get(myproject:1:staticfiles:27e4bc0): A TIMEOUT OCCURRED
Run Code Online (Sandbox Code Playgroud)
我已经尝试增加我的Elasticache集群中的节点数量,但这没有任何效果.我的下一个想法是增加memcached检索的超时,但Django文档似乎没有为此提供选项.
有一个"TIMEOUT"选项,但这似乎定义了内容到期之前的默认时间,而不是HTTP请求到memcached服务器的超时.
我使用的解决方案是将我的Django缓存后端切换到django-ft-cache,这是标准memcache后端的容错版本.所以现在,当发生周期性超时时,缓存只是绕过非缓存检索媒体而不是抛出500错误.