PHP Operation Memcache Cache

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.