Code Monkey home page Code Monkey logo

Comments (16)

honi avatar honi commented on June 9, 2024 2

After some debugging, and correctly setting the TIMEOUT option, I think it is not respected by django-redis.

Though if I manually set timeout=None when setting a key with the cache object, it works fine.

cache.set('dummy', 'abc', timeout=None)

Not sure if it's a misconfiguration on my end or something else.

from django-redis.

peterstory avatar peterstory commented on June 9, 2024 2

My goal was to have things time out after one day, so my settings look like this:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://redis:6379/0",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        },
        "TIMEOUT": 60 * 60 * 24, # Items in the cache will expire after 1 day
    }
}

REST_FRAMEWORK_EXTENSIONS = {
    'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 60 * 24, # 1 day timeout, as above
}

I have not tried setting "TIMEOUT" to None, so unfortunately I cannot comment on whether it works or not.

from django-redis.

niwinz avatar niwinz commented on June 9, 2024 1

Hmm, TIMEOUT property at OPTIONS level is socket timeout and not affects the default timeout.

I reopen this issue for research about rool level TIMEOUT value and take a look if it value is respected.

Thanks for report this issue!

from django-redis.

honi avatar honi commented on June 9, 2024 1

A simple search for TIMEOUT in the code base shows that TIMEOUT setting defined in django's CACHE dict is never used.

from django-redis.

maxgutman avatar maxgutman commented on June 9, 2024

TIMEOUT should be at the root level.
https://docs.djangoproject.com/en/dev/topics/cache/#cache-arguments

CACHES = {
...,
"staticfiles": {
"BACKEND": "redis_cache.cache.RedisCache",
"LOCATION": "%(redis_host)s:%(redis_port)s:%(redis_db)s" % {
'redis_host': SESSION_REDIS_HOST,
'redis_port': SESSION_REDIS_PORT,
'redis_db': SESSION_REDIS_DB,
},
"OPTIONS": {
"CLIENT_CLASS": "redis_cache.client.DefaultClient",
'SOCKET_TIMEOUT': SESSION_REDIS_TIMEOUT,
'PASSWORD': '%(redis_password)s' % {
'redis_password': SESSION_REDIS_PASSWORD,
} ,
},
'KEY_PREFIX': 'staticfiles_',
'TIMEOUT': 2592000,
}
}

On Fri, Feb 14, 2014 at 12:29 PM, Joni Bekenstein
[email protected]:

Hello, can anybody confirm that TIMEOUT setting is respected by
django-redis? This is my configuration (I want key/values to _never_expire):

CACHES = {
'default': {
'BACKEND': 'redis_cache.cache.RedisCache',
'LOCATION': '127.0.0.1:6379',
'KEY_PREFIX': 'my-prefix',
'OPTIONS': {
'TIMEOUT': None
}
}
}

Reply to this email directly or view it on GitHubhttps://github.com//issues/56
.

from django-redis.

honi avatar honi commented on June 9, 2024

Oh, my bad. Thanks!

from django-redis.

niwinz avatar niwinz commented on June 9, 2024

But, django-redis backend extends from django's base backend and takes the default timeout from it: https://github.com/niwibe/django-redis/blob/master/redis_cache/client/default.py#L148 and django base backend takes the default_timeout value from CACHES["TIMEOUT"]: https://github.com/django/django/blob/master/django/core/cache/backends/base.py#L59

At first glance, I have not found any bug. I believe that it need more research! ;)

from django-redis.

honi avatar honi commented on June 9, 2024

I think it might be a django bug, introduced in 1.6 with the changes regarding cache timeout (changelog).

django's BaseCache will discard TIMEOUT == None defined in CACHE settings by looking at these lines.

So these lines in django-redis appear to be correct, only if self._backend.default_timeout returns the correct value as configured in the CACHE settings.

Maybe I missed something though. I'm looking in django bugs right now to see if this is already reported.

from django-redis.

niwinz avatar niwinz commented on June 9, 2024

Are you found some thing?

from django-redis.

niwinz avatar niwinz commented on June 9, 2024

Seems not django-redis bug.

from django-redis.

schumannd avatar schumannd commented on June 9, 2024

Any pointers how or where to solve this problem?

from django-redis.

peterstory avatar peterstory commented on June 9, 2024

@schumannd I initially thought there was a problem with django-redis because I was observing cache entries which weren't expiring. Actually, the problem was with Django Rest Framework: it uses its own setting for TIMEOUT.
https://github.com/chibisov/drf-extensions/blob/master/docs/index.md#timeout

from django-redis.

schumannd avatar schumannd commented on June 9, 2024

@peterstory you linked a document for drf-extensions, which we don't explicitly use. We now set
CACHE_MIDDLEWARE_SECONDS to a very high value, as setting


CACHES = {
    "default": {
        "TIMEOUT": None,
        ...

does not seem to work.

What setting did work for you?

from django-redis.

schumannd avatar schumannd commented on June 9, 2024

@peterstory but are you using drf-extensions in any way or does this setting also work when only using drf?

from django-redis.

peterstory avatar peterstory commented on June 9, 2024

I am using:

djangorestframework==3.3.0
drf-extensions==0.3.1

And in particular:

from rest_framework_extensions.cache.decorators import cache_response
from rest_framework_extensions.cache.mixins import ListCacheResponseMixin

from django-redis.

Elendiar avatar Elendiar commented on June 9, 2024

When you use middleware django.middleware.cache.UpdateCacheMiddleware it is self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS in it, so you can set global cache timeout using global variable CACHE_MIDDLEWARE_SECONDS in settings.py

from django-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.