django-cacheops icon indicating copy to clipboard operation
django-cacheops copied to clipboard

Cacheops not working in Production.

Open Ptar2020 opened this issue 4 years ago • 5 comments

Cacheops is not working for me in production but it does in development . I can't tell if it's my settings. Here is my settings. `CACHEOPS_DEGRADE_ON_FAILURE=True CACHEOPS_ENABLED = True CACHEOPS_REDIS = { 'host': 'localhost', 'port': 6379,

} CACHEOPS_DEFAULTS = { 'timeout': 60*60 } CACHEOPS = {

'libman.*': {'ops':'all'},

}`

Ptar2020 avatar Jan 04 '22 07:01 Ptar2020

How do you know it is not working?

Suor avatar Jan 04 '22 10:01 Suor

How do you know it is not working?

Through DjDT. The no of queries are the same the first time I access a page and after I refresh...

Ptar2020 avatar Jan 04 '22 17:01 Ptar2020

There could be many reasons:

  1. Fail to connect to redis, see logs, there might be warnings. Because of CACHEOPS_DEGRADE_ON_FAILURE = True you still continue.
  2. Queries are not the same, this is common if timestamp or some random component is involved.
  3. Cache got invalidated.
  4. Queries are not being cached because of transactions. Any transaction once performed any write query starts bypassing cache to be safe.

Aside from looking into logs you may try redis-cli monitor to see whether cache is being saved and or deleted. Or you may use signals cacheops provides to log something, see README.

Suor avatar Jan 05 '22 02:01 Suor

[Django] ERROR (EXTERNAL IP): Internal Server Error: /login/

Traceback (most recent call last):
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/workspace/.heroku/python/lib/python3.9/site-packages/sentry_sdk/integrations/django/templates.py", line 73, in rendered_content
    return real_rendered_content.fget(self)
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/workspace/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 168, in render
    with context.bind_template(self):
  File "/workspace/.heroku/python/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/workspace/.heroku/python/lib/python3.9/site-packages/debug_toolbar/panels/templates/panel.py", line 48, in _request_context_bind_template
    updates.update(context)

Exception Type: TypeError at /login/
Exception Value: 'NoneType' object is not iterable
Request information:
USER: AnonymousUser

There could be many reasons:

  1. Fail to connect to redis, see logs, there might be warnings. Because of CACHEOPS_DEGRADE_ON_FAILURE = True you still continue.
  2. Queries are not the same, this is common if timestamp or some random component is involved.
  3. Cache got invalidated.
  4. Queries are not being cached because of transactions. Any transaction once performed any write query starts bypassing cache to be safe.

Aside from looking into logs you may try redis-cli monitor to see whether cache is being saved and or deleted. Or you may use signals cacheops provides to log something, see README.

Ptar2020 avatar Jan 05 '22 19:01 Ptar2020

Doesn't look related to cacheops

Suor avatar Jan 06 '22 00:01 Suor