memcached

Memcached [ mɛm.kæʃ.t ː ] is a published under the BSD license cache server for general Depositing and fetching data from memory. The software is mainly used for web pages, the data from database systems temporarily deposit on the server. It is used in many dynamic websites with database connection to improve performance by be spared by the provision of important data in RAM disk accesses or calling (relatively) complex and frequently used database queries (in particular SELECT statement ) is minimized.

  • 4.1 Program Libraries
  • 4.2 Software that uses memcached

History

Operation

A connection to such a server is via the TCP and IP. Data will be provided with a unique key value ( similar to the name of a variable) and stored as strings in memory. In order to allow the storage of data types such as integers or floating point numbers, and objects, this data is serialized by most libraries in advance.

Data can be stored either permanently or temporarily. Memcached For the latter accepts the deletion automatically.

Examples

PHP

/ / Connect $ memcached = @ memcache_connect ( 'localhost', 11211 )               or die ( 'ERROR The connection to the server failed! ');   / / The string 'hello' under the name ' value1' / Save / for 1800 seconds $ memcached -> add ( ' value1', ' Hello ', false, 1800 );   / / The string ' Hello, again ' under the name ' value2 ' Save / / permanent ( value 0) in compressed form $ memcached -> add ( ' value2 ', ' Hello, again ', MEMCACHE_COMPRESSED, 0);   / / ' Value1' delete $ memcached -> delete ( ' value1' );   / / ' Value2 ' replace it with the integer value 5979 and 23,979 seconds / / Save uncompressed. Existing values ​​must be overwritten with replace () / / Be. The use of add () would in such a case to / / Error cause! $ memcached -> replace ( ' value2 ', 5979, false, 23979 );   / / 'Value object ' for 10 seconds with the value of an instance of the PHP class / Create / stdClass $ memcached -> add ( 'value object ', new stdClass (), false, 10);   / / Print the stored object of ' value object ' echo var_export ($ memcached -> get (' value object '), true);   / / All the statistics that provides the servers available to spend var_dump ($ memcached -> getStats ());   / / Clear all values $ memcached - > flush ();   / / Close the connection again $ memcached - > close (); Perl

Use Modern :: Perl; Cache :: Memcached :: Fast use;   # Create a new memcached object # my $ cache = Cache :: Memcached :: Fast- > new ( { servers = > [ '127 .0.0.1:11211 ', '192 .168.50.55:11211 ']} );   # Store a simple key / value pair # $ cache - > set ( 'key', 'value' );   # Store complex data structures # $ cache - > set ( 'key', { name = > 'John', age = > 22} );   # To query data stored # my $ data = $ cache -> get (' key' );   # Delete a record # $ cache -> delete ( 'key' );   # Delete all values # $ cache -> flush_all;   # Close connection # $ cache -> disconnect_all; Web Links

  • Official website
  • Tim Schürmann: memcached as a distributed database cache. In: ADMIN magazine. Linux New Media AG, accessed on March 15, 2010.

Program libraries

  • ASP.NET
  • C / C
  • Java
  • Perl
  • PHP
  • Python
  • Ruby
  • Go

Software that uses memcached

  • Memory management
  • Free proxy software
  • Free database management system
563469
de