Memcached

memcached is a distributed memory caching system that was originally developed by Danga Interactive for LiveJournal. It is used to speed up dynamic database-driven websites by caching data and objects in memory to reduce the amount the database needs to be read. memcached is open source and released under a BSD license. It uses libevent. Memcached lacks authentication and security features, meaning it should only be used on servers with a firewall set up appropriately. MediaWiki is one example of software that supports memcached. Slashdot uses memcached in some parts of its site. memcached acts as a giant hash table, caching data as it is requested. Originally designed to speed up only the queries themselves, memcached is now often used in object caching as well. Any task which is time intensive can be improved by using memcached to store the data, rather than regenerate it every time, so long as the cached data has either a definite expiry time or a process through which the cached data can be marked as deletable. Converting your database or object creation queries to use memcached is simple. Typically, if you are using straight database queries, you might have code that looks like the following:
  function foo (int userid) {     result = db_select("SELECT * FROM users WHERE userid = " + foo);     return result;  } 
After conversion to memcached, the same call might look like the following:
  function get_foo (int userid) {      result = memcached_fetch("userrow:" + userid);      if (result) {          return result;      }      result = db_select("SELECT * FROM users WHERE userid = " + foo);      memcached_add("userrow:" + userid,  result);      return result;  } 
As you can see, you would first check whether a memcached value with the unique key "userrow:userid" exists, where userid is some number. If the memcached_fetch call returns the data, you immediately return - and never need to touch the database or slow disks. If the result does not exist, you would select from the database as usual, and set the unique key using the memcached API add function call. However, if you only modified this API call, and no others, you would eventually end up fetching incorrect data (assuming your entire database doesn't fit into the memory caching you have available). In addition to creating a "add" call, you would also need to implement an update call, using the memcached set function.
  function update_foo(int userid, string dbUpdateString) {      result = db_execute(dbUpdateString);      if (result) {          data = createUserDataFromDBString(dbUpdateString);          memcached_set("userrow:"+userid, data);      }  } 
This call would update the currently cached data to match the new data in the database, assuming the database query succeeds. Note that all functions described on this page are pseudocode only. Memcached calls and programming languages may vary based on the API you use.

External links

 

<< PreviousWord BrowserNext >>
mount rokko
the war hound and the world's pain
1896 in science
1762 in science
1765 in science
1771 in science
1796 in science
1897 in science
microcirculation
1776 in science
john riley
arklow
1895 in science
1768 in science
1802 in science
genmaicha
wood elves
dependent variable
list of people by name: mat
independent variable
list of people by name: mau max
lyle lovett
list of people by name: may maz
hiv positive people
eddie lopat
web cache
conway twitty
patient
pinetum
operation balak
operation horev
mulayam singh yadav
pvv
common palm civet
hcf
tongue piercing
nailsea
bearsden
matrix normal distribution
hms achilles
whitey ford
european beech
germania superior
premaxilla