How to use the Memcache under SAE

Source: Internet
Author: User

Recently a short web address of the Cloud Shield interface query speed is a bit slow, think how to optimize speed. Because a short web site is placed on the SAE, and the SAE has memcache, ready to use this first greatly improve the database of the pear ~

Here's how to use memcache in an SAE environment:

Activate the Memcache function inside your SAE project
    1. Go to your Sina cloud platform, select the app you want to set up, go to the admin page
    2. Select Memcache this link under service management, click
    3. Enter memcache This page, select the "point this initialization MC" This button, more with their own site needs to set the capacity of the cache, when you enter the time will prompt you to consume how many cloud beans, we recommend that you carefully set, if set unreasonable, resulting in a huge waste of cloud beans, Or did not play to the real role of Memcache.

The following code is used:

<?PHP//Connection    $mem=Memcache_init (); //Save Data    $mem->set (' Key1 ', ' This is first value ', 0, 60); $val=$mem->get (' Key1 '); Echo"Get Key1 Value:".$val." <br/> "; //Replace Data    $mem->replace (' Key1 ', ' This is replace value ', 0, 60); $val=$mem->get (' Key1 '); Echo"Get Key1 Value:".$val. "<br/>"; //Save Array    $arr=Array(' AAA ', ' BBB ', ' CCC ', ' DDD ')); $mem->set (' Key2 ',$arr, 0, 60); $val 2=$mem->get (' Key2 '); Echo"Get Key2 Value:"; Print_r($val 2); Echo"<br/>"; //Delete Data    $mem->delete (' Key1 '); $val=$mem->get (' Key1 '); Echo"Get Key1 Value:".$val. "<br/>"; //Clear All data    $mem-Flush(); $val 2=$mem->get (' Key2 '); Echo"Get Key2 Value:"; Print_r($val 2); Echo"<br/>"; //Close Connection    $mem-close ();?>

$mem->set (' key1 ', ' This is first value ', 0, 60);

The first parameter is the key of the data, which is used to locate a data,

The second parameter is the data content that needs to be saved, here is a string,

The third parameter is a marker, typically set to 0 or memcache_compressed,

The fourth parameter is the validity period of the data, that is, the data in this time is valid, if the past this time, then the memcache server side will be purged of this data, the unit is seconds, if set to 0, it is always valid

Transferred from: http://www.gulianqiang.com/php/207.html

How to use the Memcache under SAE

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.