PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 13, 2022

[FIXED] How to set Memcached retrieval timeout in Django

 November 13, 2022     amazon-elasticache, caching, django, memcached, python     No comments   

Issue

How do you change the retrieval timeout for the Memcached/Elasticache caching backend in Django?

I'm using Amazon's Elasticache for caching content in Django, and I'm frequently seeing errors like:

  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

I've tried increasing the number of nodes in my Elasticache cluster, but that has had no effect. My next thought was to increase the timeout for the memcached retrieval, but the Django docs don't seem to provide an option for this.

There's a "TIMEOUT" option, but that seems to define the default time after which the content expires, not the timeout of the HTTP request to the memcached server.


Solution

The solution I went with was to switch my Django cache backend to django-ft-cache, a fault-tolerant version of the standard memcache backend. So now, when a periodic timeout occurs, the cache simply bypasses to a non-cache retrieval of media instead of throwing a 500 error.



Answered By - Cerin
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing