Is there a where to work out when the key was written to memcache and calculate the age of the oldest key on our memcache?

72 views
Skip to first unread message

Gurdipe Dosanjh

unread,
Jan 12, 2015, 12:34:37 PM1/12/15
to memc...@googlegroups.com
Hi All,

I am new  to memcache and need to know is there a where to work out when the key was written to memcache and calculate the age of the oldest key on our memcache?

Kind Regards

Gurdipe

Jay Grizzard

unread,
Jan 12, 2015, 2:26:04 PM1/12/15
to memcached
I don’t think there’s a way to figure out when a given key was written. If you really needed that, you could write it as part of the data you stored, or use the ‘flags’ field to store a unixtime timestamp.

You can get the age of the oldest key, on a per-slab basis, with ‘stats items’ and looking at the ‘age’ field. If you want the overall oldest age, you’ll have to find the oldest age value amongst all the slabs.

Do note, though, that if you have evictions going on, ‘oldest’ is kind of dubious, if you’re trying to use it as a “anything newer than this exists”, since evictions happen in lru order and per-slab, so younger items can disappear before older ones, if they’re in a different slab or have been accessed more recently. (Don’t know if that’s what you’re doing, but just in case you are…)

-j


--

---
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,
Jan 12, 2015, 3:15:03 PM1/12/15
to 'Jay Grizzard' via memcached
The only data stored are when the item expires, and when the last time it
was accessed.

The "age" field (and evicted_time) is how long ago the oldest item in the
LRU was accessed. You can roughly tell how wide your LRU is with that.

Jay Grizzard

unread,
Jan 12, 2015, 3:49:11 PM1/12/15
to memcached
Ack! You are, of course, right. I looked at the protocol documentation and completely failed to engage my brain enough to realize that the protocol documentation is… imprecise. Or at least unclear. Or at least lacks an appropriate definition of ‘age’.

My bad!

-j

Gurdipe Dosanjh

unread,
Jan 16, 2015, 5:24:05 AM1/16/15
to memc...@googlegroups.com
Hi All,

Thank you for the updates.

I have been doing a lot of reading on memcached and I am trying to find a way I can find out what is the oldest key.

Is there a way I can do this?

Kind Regards

Gurdipe

Kind Regards

Gurdipe

Mobile: 07879682511
Home: 01656749236
Skype: gurdipe_veeqo
Linkedin: gurdipe


You received this message because you are subscribed to a topic in the Google Groups "memcached" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/memcached/D4Szg9tsaS0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to memcached+...@googlegroups.com.

Ryan McElroy

unread,
Jan 16, 2015, 10:20:40 AM1/16/15
to memc...@googlegroups.com

As was answered, there's no built-in way to determine when a key was set. Furthermore, memcached itself doesn't track when the oldest key changes. The only way to approximate the behavior you want is to store the set times in each value, get all possible keys, and then do the comparison yourself. This will not be fast or efficient.

I suggest taking a step back k and talking about the higher-level gioal you're trying to accomplish that makes you think you need the time the oldest key was set. There may be a good way to accomplish your actual goal without this information.

~Ryan

Gurdipe Dosanjh

unread,
Jan 17, 2015, 5:28:34 AM1/17/15
to memc...@googlegroups.com
Hi All,

Ryan Thank you for the update, you are right and I have taken it on board

Kind Regarrds

Gurdipe

Kind Regards

Gurdipe

Mobile: 07879682511
Home: 01656749236
Skype: gurdipe_veeqo
Linkedin: gurdipe


Reply all
Reply to author
Forward
0 new messages