Comments (16)
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.
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.
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.
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.
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.
Oh, my bad. Thanks!
from django-redis.
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.
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.
Are you found some thing?
from django-redis.
Seems not django-redis bug.
from django-redis.
Any pointers how or where to solve this problem?
from django-redis.
@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.
@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.
@peterstory but are you using drf-extensions in any way or does this setting also work when only using drf?
from django-redis.
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.
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)
- Redis Sentinel breaking change in redis==5.0.0
- object attribute is missing after manager.py is restarted when using django redis cache HOT 1
- Why do we use `param["url"]` as a unique connection pool key? HOT 5
- Connection Pooling doesn't work as intended HOT 1
- Pytest 7.0 compatibility HOT 1
- Drop django 4.0
- Drop support for django 3.2 HOT 1
- How to configure and connect redis cluster correctly? HOT 2
- Django `TIMEOUT` setting not working as expected HOT 2
- Which timezone wil it take? system timezone or django timezone HOT 1
- Why Django Redis does not raise exception while connecting to Redis Server with SSL param equal string "False"
- `Expire` method fails when using `DEFAULT_TIMEOUT` HOT 1
- Getting/Setting occasionally extremely slow HOT 5
- django requirements update
- Add NX, XX, GT and LT to expire and pexpire HOT 2
- Multiple redis caches with fallback mechanism HOT 1
- Is it necessary to get coverage of tests directory? HOT 2
- Implementing HGET
- using redis in django getting connection error HOT 1
- strict_map_key
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-redis.