6

Why does memcached impose a 30-day limit on the lifetime of cache entries?

In my system, I am always setting the lifetime to be 30 days, since that's the max allowed value. Setting it to a value much greater than 30 days would be ideal for my app.

Is there a way to change the "30-day" value to something else?

I am considering downloading the memcached source and recompiling it for my own use. I would either change the "30" to "300" or perhaps get rid of that check entirely. If I were to do this, would I be changing something that would cause memcached to malfunction or perform poorly? My expectation would be that items would be allowed to remain in the cache for longer, and they items would be removed from the cache when the cache gets full.

Mike W
  • 1,128
  • 1
  • 13
  • 27
  • 1
    Why is the 30 day limit a problem? Is it causing issues? – Oded Sep 02 '10 at 16:10
  • I just found about this limit the hard way, if you specify a limit that is too long, the value is not stored at all (at least on my memcached version), this can cause some problems because (doh) *items that you want stored as long as possible are (silently) not stored at all*. – adrianTNT Aug 03 '22 at 23:10

2 Answers2

10

30 days is the limit at which we consider the time you specified to be a TTL from now.

If you want longer than 30 days, it's fine, just use an absolute time (time() + whatever).

If you want no time-based expiration, as ConroyP says, just use 0.

Dustin
  • 89,080
  • 21
  • 111
  • 133
  • can you add more detail ? consider my question over here:http://magento.stackexchange.com/questions/5925/memcached-why-data-is-not-stored/5961?noredirect=1#5961 – WonderLand Jul 23 '13 at 02:35
  • This explains it - thank you! I've just been reading the doctrine/cache source and couldn't work out why they were checking the duration in this way so glad to find an explanation. – puppyFlo May 21 '15 at 08:28
8

30 days is the maximum length of time for which you can specify an expiry, but if you're thinking of eliminating the expiry check altogether, would it not be simpler to set the expiry time to 0? This should mean that the data is stored until the cache is full and it's removed to allow for insertion of newer items.

From the PHP Memcache docs:

Parameter expire is expiration time in seconds. If it's 0, the item never expires (but memcached server doesn't guarantee this item to be stored all the time, it could be deleted from the cache to make place for other items).
ConroyP
  • 40,958
  • 16
  • 80
  • 86