How does memcache store data?

macha picture macha · Dec 9, 2010 · Viewed 15.7k times · Source

I am a newbie to caching and have no idea how data is stored in caching. I have tried to read a few examples online, but everybody is providing code snippets of storing and getting data, rather than explaining how data is cached using memcache. I have read that it stores data in key, value pairs , but I am unable to understand where are those key-value pairs stored?

Also could someone explain why is data going into cache is hashed or encrypted? I am a little confused between serialising data and hashing data.

Answer

bhamby picture bhamby · Dec 9, 2010

A couple of quotes from the Memcache page on Wikipedia:

Memcached's APIs provide a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.

And

The servers keep the values in RAM; if a server runs out of RAM, it discards the oldest values. Therefore, clients must treat Memcached as a transitory cache; they cannot assume that data stored in Memcached is still there when they need it.

The rest of the page on Wikipedia is pretty informative, and it might help you get started.