简体   繁体   中英

How to use memcache with php

I am new to this memcache stuff. I read that it saves lot of time of page load time by caching the database key. I have my php application and I want to use memcache as it takes too much time for my application to retrieve the whole set of results from database.

Steps to take: Prerequisite: read the manual (at least a bit): http://php.net/manual/en/book.memcache.php and make sure you've got memcached installed.

1 Start the memcached program so there is a server that actually stores the key-value pairs.

2 Make a memcache object

3 Store a value for a key

4 Retrieve your key.

$memcache = new Memcache; //point 2. 
$memcache->set($yourUniqueKey,  $yourValue, false, 3600); //point 3
//later:
$memcache->get($yourUniqueKey); //point 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM