[英]How to set Memcached retrieval timeout in Django
如何在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
我已经尝试增加我的Elasticache集群中的节点数量,但这没有任何效果。 我的下一个想法是增加memcached检索的超时,但Django文档似乎没有为此提供选项。
有一个“TIMEOUT”选项,但这似乎定义了内容到期之前的默认时间,而不是HTTP请求到memcached服务器的超时。
我使用的解决方案是将我的Django缓存后端切换到django-ft-cache ,这是标准memcache后端的容错版本。 所以现在,当发生周期性超时时,缓存只是绕过非缓存检索媒体而不是抛出500错误。
django没有设置这样做。 这样的东西应该有效,尽管它很脏。 确保在创建缓存之前执行以下操作:
import memcached; memcached._SOCKET_TIMEOUT = whatever_you_want_it_to_be;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.