0

I'm using redis server for caching. Using django-redis package.

Below is my setting file :

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
        },
    }
}

My view :

from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page

@method_decorator(cache_page(timeout=None,key_prefix="site1"), name='dispatch')
class ProfileView(APIView):
    # With auth: cache requested url for each user for 2 hours
    def get(self, request, format=None):
        content = {
            'user_feed': request.user.get_user_feed()
        }
        return Response(content)

When set timeout=60 it's working. But when i add timeout=None i'm getting 600 seconds timeout.

Ganesh sali
  • 116
  • 1
  • 5
  • Setting `timeout` to `None` doesn't do what you think it does. `None` is in fact the default, and it means that [Django will respect the max-age header of the response](https://github.com/django/django/blob/7119f40c9881666b6f9b5cf7df09ee1d21cc8344/django/middleware/cache.py#L107-L115), or skip caching if there is none. You can't use `cache_page` to cache forever - the best you can do is set a very long timeout. – solarissmoke Mar 10 '22 at 05:40
  • @solarissmoke Can't i extend cache_page and set never expire ? Or any other way to achieve it. Please suggest me – Ganesh sali Mar 10 '22 at 09:22

0 Answers0