Opened 13 years ago
Closed 12 years ago
#16858 closed Bug (duplicate)
incr() on locmem cache resets the expiry time
Reported by: | Malcolm Box | Owned by: | Berker Peksag |
---|---|---|---|
Component: | Core (Cache system) | Version: | 1.5-rc-1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
On the locmem cache backend, calling incr() causes the key's timeout value to be reset to the default for the cache.
To reproduce:
- setup the default cache to be locmem and with a timeout of 1 second
>> cache.set('key', 10, 300) >> time.sleep(1) >> cache.get('key') 10 >> cache.incr('key') >> time.sleep(1) >> cache.get('key') None
The cache should still contain the key at the last line.
The problem comes from the implementation of incr() in base.py which uses get() and set() to implement incr(). Since set() is called without a timeout, the cache default time is used.
Attachments (2)
Change History (11)
comment:1 by , 13 years ago
Description: | modified (diff) |
---|
comment:2 by , 13 years ago
Yes, I consider this a bug.
As far as I can tell, memcached does not alter the expiry time of a key when incr()/decr() is called on it. Running the same test using a memcached cache backend, I get the value out at the end.
It seems highly counter-intuitive that updating a key's value should suddenly reset the timeout and cause the key to expire.
comment:3 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Well, I think the locmem's behavior is a bit more intuitive personally, but we've generally tried to make the "stupid" backends do what memcached would do, since they're often used in development/testing. Marking as accepted.
by , 13 years ago
Attachment: | locmem-patch.diff added |
---|
Patch for locmem cache to bring incr() in line with memcached behaviour
comment:4 by , 13 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:5 by , 13 years ago
Needs tests: | set |
---|
by , 13 years ago
Attachment: | locmem_incr_expiration_16858.diff added |
---|
locmem cache's incr() will no longer change timeout to mimic memcached
comment:6 by , 13 years ago
Needs tests: | unset |
---|
The original patch walked the expiration time forward by time.time() with each call to incr() and decr(). The new patch uses a special timeout value to skip setting the expiration time.
comment:7 by , 12 years ago
Owner: | changed from | to
---|
comment:8 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Version: | 1.3 → 1.5-rc-1 |
comment:9 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
This bug already fixed in #17287.
See for the related commit:
https://github.com/django/django/commit/1086a9a8455420b7167fe5195bca4c74883dcef0
I'm assuming you consider this a bug, and would like it to not reset the expiry time ;) What's the justification for that behavior, memcached does it?