Opened 4 years ago

Closed 2 years ago

#16858 closed Bug (duplicate)

incr() on locmem cache resets the expiry time

Reported by: boxm Owned by: berkerpeksag
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 Alex)

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)

locmem-patch.diff (1004 bytes) - added by boxm 4 years ago.
Patch for locmem cache to bring incr() in line with memcached behaviour
locmem_incr_expiration_16858.diff (2.2 KB) - added by manfre 3 years ago.
locmem cache's incr() will no longer change timeout to mimic memcached

Download all attachments as: .zip

Change History (11)

comment:1 Changed 4 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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?

comment:2 Changed 4 years ago by boxm

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 Changed 4 years ago by Alex

  • Triage Stage changed from Unreviewed to 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.

Changed 4 years ago by boxm

Patch for locmem cache to bring incr() in line with memcached behaviour

comment:4 Changed 4 years ago by boxm

  • Easy pickings set
  • Has patch set

comment:5 Changed 4 years ago by SmileyChris

  • Needs tests set

Changed 3 years ago by manfre

locmem cache's incr() will no longer change timeout to mimic memcached

comment:6 Changed 3 years ago by manfre

  • 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 Changed 2 years ago by paper82

  • Owner changed from nobody to paper82

comment:8 Changed 2 years ago by berkerpeksag

  • Owner changed from paper82 to berkerpeksag
  • Status changed from new to assigned
  • Version changed from 1.3 to 1.5-rc-1

comment:9 Changed 2 years ago by berkerpeksag

  • Resolution set to duplicate
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.
Back to Top