<div class="codebody" id="code41350"> $cache = new Cache_MemCache(); $cache->addServer('www1'); $cache->addServer('www2',11211,20); // this server has double the memory,and gets double the weight $cache->addServer('www3',11211); // Store some data in the cache for 10 minutes $cache->store('my_key','foobar',600); // Get it out of the cache again echo($cache->fetch('my_key'));
<div class="codebody" id="code33064"> $cache = new Cache_File(); $key = 'getUsers:selectAll'; // check if the data is not in the cache already if (!$data = $cache->fetch($key)) { // assuming there is a database connection $result = MysqL_query("SELECT * FROM users"); $data = array(); // fetching all the data and putting it in an array while($row = MysqL_fetch_assoc($result)) { $data[] = $row; } // Storing the data in the cache for 10 minutes $cache->store($key,$data,600); }