how to get find out key expiration time after it was put in the cache?

392 views
Skip to first unread message

nag...@fitbit.com

unread,
Mar 22, 2019, 2:27:39 PM3/22/19
to memcached
Hi All,

I have a `key` which was put in the cache, the database does not have the key anymore, but since it was in the cache our app gets the value. I want to know when it would expire before I go in and try to delete it by hand. What is the recommended way to find the key expiration time after the fact? We are running 1.4.20 (i know its a few years old). I tried to figure out by searching on google, some people recommended `stats cachedump <slab-id> <count>` (https://stackoverflow.com/questions/2558706/how-can-i-get-the-expire-time-for-the-particular-item-in-memcached). I wanted to check here if there is some better or "recommended" way

Thanks
Nikhil

Daniel Ellis

unread,
Mar 22, 2019, 3:27:09 PM3/22/19
to memc...@googlegroups.com
As far as I know, cachedump is the only way.  The unfortunate downside is that you can only dump one page per slab, according to this.

I bet you could get fancy and dump the entire process memory and dig through it yourself...  That could be fun.

--

---
You received this message because you are subscribed to the Google Groups "memcached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to memcached+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dormando

unread,
Mar 22, 2019, 3:32:12 PM3/22/19
to memc...@googlegroups.com
There's no way to retrieve the metadata back from an item aside from the
client flags as part of a normal command.

What people typically do is embed the original TTL into the object you've
stored. that way the application can read it or any other metadata you
want to make decisions with.

Though I see you said "by hand" - are you debugging something or designing
a flow in your app to remove stale data?

If you're debugging, "lru_crawler metadump" will get you the data, but you
need a newer version I think.

Nikhil

unread,
Mar 22, 2019, 5:00:18 PM3/22/19
to memcached
Got it. Thank you Dormando and Daniel for your prompt responses. 

Dormando, yes I am debugging a corner case, where I deleted an unused feature that queried a key from memcache (that key is not in the db, so cannot be in memcache after TTL expired). But it happens to be there, so I want to know the TTL to be sure that it was put there incorrectly (possibly with 0 ie never expire).

Thanks 
Nikhil

dormando

unread,
Mar 22, 2019, 5:03:20 PM3/22/19
to 'Nikhil' via memcached
Got it. stats cachedump might find it, but it's limited to "a megabyte"
worth of keys/metadata per slab class. it'll also hang your server while
it fills up the buffer.

in newer versions you can definitely find it with lru_crawler metadump
[slabclass]. I'll be improving those interfaces too. Questions like this
help me figure out which direction to go :)
Reply all
Reply to author
Forward
0 new messages