Memcache is a high-performance distributed memory object cache system commonly used in php. we can use it to improve website performance and reduce server load, the following is my learning notebook. let's take a look at the simplest connection method. the sample code is as follows :... memcache is a high-performance distributed memory object cache system commonly used in php. we can use it to improve website performance and reduce server load, the following is my learning notebook. let's take a look at the simplest connection method.
The sample code is as follows:
connect('127.0.0.1', 11211) or die ("Could not connect"); $mem->set('key', 'This is a test!', 0, 60); $val = $mem->get('key'); echo $val; ?>
The application will create a class, the code is as follows:
addServer(self::$server[0],self::$server[1]); } return $memcache; } public static function set($key, $value, $expire=600) { self::$client === 'memcached' ? self::get_memcache()->set($key, $value, $expire) : self::get_memcache()->set($key, $value, MEMCACHE_COMPRESSED, $expire); } public static function get($key) { return self::get_memcache()->get($key); } }MCache::set('test_one', 'value_one', 60); # 60 Sec print_r(MCache::get('test_one'));?>
The following table lists all the methods of the memcache function: Memcache: add-add a value. if a value already exists, falseMemcache: addServer-is returned to add an available server address Memcache :: close-close a Memcache object Memcache: connect-create a Memcache object memcache_debug-control debugging function Memcache: decrement-perform the subtraction operation on the values of a saved key. Memcache :: delete-delete a key value Memcache: flush-clear all cached data Memcache: get-get a key value Memcache :: getExtendedStats-get the running system statistics of all processes in the process pool Memcache: getServerStatus-get the running server parameter Memcache: getStats-return some running statistics of the server Memcache :: getVersion-returns the version information of the running Memcache. Memcache: increment-adds the value of a saved key. Memcache: pconnect-creates a persistent connection object for Memcache :: replace-overwrite an existing key to Memcache: set-add a value. if it already exists, overwrite Memcache :: setCompressThreshold-compress Memcache: setServerParams for data larger than a certain size-modify server parameters at runtime
Article address:
Reprint at will ^ please include the address of this article!