django-redis-cache
django-redis-cache copied to clipboard
fix ignored version in first get_or_set fetch
Fixes https://github.com/sebleier/django-redis-cache/issues/122
get_or_set had been ignoring the key's version in it's attempt to fetch the key from cache initially. When using a versioned key, get_or_set therefore always misses the cache, runs the expensive function, and then updates the right key in the cache.
I'm having some getting the tests to pass, but here is some example code to show the issue.
cache.set('x', 'yay', version=2)
cache.set('x', 'boo')
cache.get_or_set('x', lambda: 'x', version=2)
> 'boo'
cache.get('x')
> 'yay'
Based on the failures, I might be going about this the wrong way. An alternative could be
- self.get(key)
+ value = client.get(key)
+ value = self.get_value(value)
which looks like it will keep the client the same.