With the Memcache service and PHP extensions installed, we can use PHP to manipulate memcache to implement the cache!
Summary of all methods of PHP Memcache client
The list of all methods for the Memcache class is as follows:
Memcache::add adds a value that, if it already exists, returns false Memcache::addserver add a server address to use Memcache::close close a Memcache object Memcache:: Connect creates a Memcache object Memcache_debug controls the Debug function Memcache::d ecrement to subtract the value from a saved key memcache::d elete Delete a key value MEMC Ache::flush clears all cached data memcache::get gets a key value that does not exist then returns Falsememcache::getextendedstats gets the run system statistics Memcache for all processes in the process pool:: Getserverstatus gets the parameters that run the server memcache::getstats returns some run statistics for the server memcache::getversion returns the version information of the Memcache that is running Memcache:: Increment an addition to the value in a saved key Memcache::p Connect to create a Memcache persistent connection object Memcache::replace-Overwrite an existing key Memcache:: Set adds a value that, if already present, memcache::setcompressthreshold to compress data larger than a certain size memcache::setserverparams modify the server's parameters at run time
Read and set the cache code instance
Connect (' 127.0.0.1 ', 11211);//Gets the value of a variable if there is a value in the return variable otherwise returns False$var = $memObj->get (' test ');//Determine if the cache exists, Does not exist then connect the database to get the variable and save to the Memcache server if (! $var) {//Connect to database ... Omitted here for example the return value of ' Test ... '; $var = ' Test ... '; $memObj->set (' Test ', $var);//test cache process output a hint that the echo ' cache does not exist ... '; Echo $var;
Delete Cache
Connect (' 127.0.0.1 ', 11211);//delete cache $memobj->delete (' test ');
Empty cache
Connect (' 127.0.0.1 ', 11211), $MEMOBJ->flush ();
Close connection
Connect (' 127.0.0.1 ', 11211), $MEMOBJ->flush (); $memObj->close ();
When combined with PHP, the memcache values can be common variables, arrays, objects, and other PHP variables.