Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does memcache store data?

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.

like image 331
macha Avatar asked Dec 09 '10 16:12

macha


People also ask

Is Memcache a database?

Memcached is an open source, distributed memory object caching system that alleviates database load to speed up dynamic Web applications. The system caches data and objects in memory to minimize the frequency with which an external database or API (application program interface) must be accessed.

Is Memcache a memory?

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches.

What data structure does Memcached use?

Data Structure: MemcacheD uses strings and integers in its data structure. Hence, everything you save can either be one or the other. With integers, the only data manipulation you can do is adding or subtracting them. If you need to save arrays or objects, you will have to serialize them first and then save them.

How does Memcached work internally?

In order to alleviate the load from the database, a cache is used to store the requested data so that when a user requests for some information, the application will first look into the cache and if it is found there, the application won't go to the database for it; rather, it will fetch the data from the cache and ...


1 Answers

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.

like image 142
bhamby Avatar answered Sep 23 '22 19:09

bhamby