tags:

views:

79

answers:

1

I am not sure if this is possible. I was storing some information in a memcache server. The memcache entry i was storing was suppossed to have an expiry of 30 minutes. During that 30 minutes i could update the value of that memcache entry reference by the same key. But when i update the value i do not want to change the expire time. For example:

  • Key is created and set to expire in 30 minutes
  • 10 minutes goes by and the value of the key is requested and we change the value
  • i replace the value of they key using memcache replace (i do not provide a new expire time because it is optional), i want the expire time to be 30-10 = 20 because the key was created 10 minutes ago and was set to expire in 30 minutes.
  • Now since i did not set an expire time it defaults to 0 and the key will never expire.

Now, is there a way of setting items in memcache, setting an expire time, and then getting/replacing the item while keeping the expire time to x minutes after i set the item in cache?

I might possible be able to use unix timestamps instead of seconds to expire when setting into memcache, and also storing that timestamp in memcache and when i set it back into memcache i would just set it to the same timestamp stored in the value. Or is there a better way of doing this?

BTW I an using memcache and not memcached.

A: 

Essentially Memcache does exactally what you want it to. It does its job very well, getting and setting values... I think the answer your looking for is outside of the default functionality of memcache. I suppose you can put more control on your codebase to check a timestamp that you store with your blob and use that to set expire times for future updates?

I don't know what your using for your non-memcache consistent storage, but I would store an expiry date in that-- then use that value to update your memcache.

Jon
Yeah, i am just going to store the timestamp of the expiry in memecache so i can set the expiry back to that value when i replace the value.I do not want to use another type of storage (like a sql db or nosql db) for just an expiry. I can do it all in memcache just by a little ugly hack.But you are correct, memecache does what it is supposed to.Thanks!
gprime