def cache_per_user_method(ttl=None, prefix=None, cache_post=False):
'''
Decorator which caches the view for each User
* ttl - the cache lifetime, do not send this parameter means that the cache
will last until the restart server or decide to remove it
* prefix - Prefix to use to store the response in the cache. If not informed,
it will be used 'view_cache _' + function.__ name__
* cache_post - Determine whether to make requests cache POST
* The caching for anonymous users is shared with everyone
How to use it:
@cache_per_user_method(ttl=3600, cache_post=False)
def get(self, request):
...
'''
def decorator(view_method):
def apply_cache(obj, request, *args, **kwargs):
CACHE_KEY = cache_key(request, prefix)
logger.debug("cache key %s",CACHE_KEY)
# Verifica se pode fazer o cache do request
if not cache_post and request.method == 'POST':
can_cache = False
else:
can_cache = True
if can_cache:
response = core_cache.get(CACHE_KEY, None)
else:
response = None
if not response:
response = view_method(obj, request, *args, **kwargs)
logger.debug("cache not found in decorator")
if can_cache and hasattr(response, 'render'):
logger.debug("cache set in decorator")
core_cache.set(CACHE_KEY, response.render(), ttl)
return response
return apply_cache
The above code was causing the error to happen but couldn't figure out where the issue was in the above.
Thanks,
On Wednesday, November 22, 2017 at 9:44:59 PM UTC+5:30, Tim Graham wrote:
I tried a Google search for the last line of the error message and came to https://code.djangoproject.com/ticket/25964 . Conclusion: try clearing your cache.
On Wednesday, November 22, 2017 at 3:29:42 AM UTC-5, Web Architect wrote:Hi,We recently migrated from Django 1.8 to Django 1.11.7. We have an ecommerece site running on Django. When we are trying to access a page, following exception is occuring:Traceback (most recent call last):
File "/usr/local/lib/python2.7/
wsgiref/handlers.py", line 85, in run self.result = application(self.environ, self.start_response)
File "/virenv/lib/python2.7/site-
packages/django/contrib/ staticfiles/handlers.py", line 63, in __call__ return self.application(environ, start_response)
File "/virenv/lib/python2.7/site-
packages/django/core/handlers/ wsgi.py", line 161, in __call__ status = '%d %s' % (response.status_code, response.reason_phrase)
File "/virenv/lib/python2.7/site-
packages/django/http/response. py", line 69, in reason_phrase if self._reason_phrase is not None:
AttributeError: 'TemplateResponse' object has no attribute '_reason_phrase'
I am completely clueless why the above exception is occurring. I do not have any other data or logs for the above exception
Could anyone help me in providing a way to debug the above?
Thanks.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27d1281c-2d9f-44f3-a6a3-d2e6672310c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment