django-redis-cache icon indicating copy to clipboard operation
django-redis-cache copied to clipboard

fix ignored version in first get_or_set fetch

Open AlexRiina opened this issue 8 years ago • 1 comments

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'

AlexRiina avatar Oct 05 '16 21:10 AlexRiina

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.

AlexRiina avatar Oct 05 '16 23:10 AlexRiina