django-redis-cache
django-redis-cache copied to clipboard
get_or_set returns 'Must pass in a callable error'
I don't know why but I got this error
>>> tweets = cache.get_or_set('tweets', 'x', timeout=300)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/redis_cache/backends/base.py", line 33, in wrapped
return method(self, client, key, *args, **kwargs)
File "/Users/deanchristianarmada/Desktop/projects/asian_gaming/radar/lib/python2.7/site-packages/redis_cache/backends/base.py", line 406, in get_or_set
raise Exception("Must pass in a callable")
Exception: Must pass in a callable
my pip freeze is:
amqp==1.4.9
anyjson==0.3.3
argh==0.26.2
Babel==2.3.4
backports.ssl-match-hostname==3.5.0.1
billiard==3.3.0.23
celery==3.1.24
certifi==2016.9.26
Django==1.10.2
django-redis-cache==1.7.1
django-supervisor==0.4.0
flower==0.9.1
futures==3.0.5
gunicorn==19.6.0
kombu==3.0.37
meld3==1.0.2
pathtools==0.1.2
psycopg2==2.6.2
pycrypto==2.6.1
python-crontab==2.1.1
python-dateutil==2.5.3
pytz==2016.7
PyYAML==3.12
redis==2.10.5
requests==2.11.1
six==1.10.0
supervisor==3.3.1
tornado==4.2
Unipath==1.1
watchdog==0.8.3
xmltodict==0.10.2
my settings is:
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': CACHE_LOCATION,
'TIMEOUT': None,
},
}
You'll want the second argument to be a callable, e.g. get_or_set('tweets', lambda: 'x', timeout=300)
But isn't it better to follow like django's get_or_set cache that is very similar to django model's get_or_create?
I agree. In Django's cache API, get_or_set takes either a value or a callable. I think redis_cache should follow that convention in order to be usable as a drop-in replacement. Would you accept a PR?
+1 can we please make it compatible with signature of django.core.cache.backends.base.BaseCache#get_or_set
? Because right now this is not a drop in replacement.
Guys I beg you, please merge this. There is even a pull request. This is very confusing as long as signature of the method doesn't respect Django interface method with the equal name. Makes every developer to walk thru code and update it line by line.
Apologies on the terribly late response. I have twin toddlers and my free time has been limited the last few years.