views:

55

answers:

1

If I load the data of user_x into memory with memcache, how long will this data stay available?

If a user only logs in once a year this data is unnecessary in the memory.

Or am i looking at this the wrong way?

+3  A: 

memcached FAQ covers some of this.

You can set expire times up to 30 days in the future. After that memcached interprets it as a date, and will expire the item after said date. This is a simple (but obscure) mechanic.

When memcached hits its memory limit, it will automatically expire the oldest / least used entries first.

memcached uses a lazy expiration, which means it uses no extra cpu expiring items. When an item is requested (a get request) it checks the expiration time to see if the item is still valid before returning it to the client.

Similarly when adding a new item to the cache, if the cache is full, it will look at for expired items to replace before replacing the least used items in the cache.

Your cached data may be invalidated at any time because of this. As Dustin pointed out, it may also stay around forever.

jasonbar
To be clear, it can stay forever (as long as you specify 0 for expiration), but we don't guarantee it will ever be returned (little memory + high set rate == most records falling out before you get a chance to see them).
Dustin