PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Bryan Boardwine   Memcache Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example page showing the usage.
Class: Memcache Class
Store and retrieve data in a Memcache server
Author: By
Last change:
Date: 12 years ago
Size: 882 bytes
 

Contents

Class file image Download
<?php

include('./memcache.class.php');

$cache = Cache::getInstance();

//Checking if the the key exists
if($cache->exists("key"))
{
    echo
$cache->get("key");
} else {
   
$cache->set("key", "It's cached!", "900");
}
//Setting data in the memory
if(!cache->exists("hello"))
{
  
$cache->set("hello", "Hello! this is my cached data for 6 hours!", 60 * 60 * 6); //Interval: 60 * 60 * 6 (6 hours) or 21600 in seconds
  
echo $cache->get("hello");
}

//Replacing data for its key
if($cache->exists("test"))
{
   
$cache->update("key", "Here is my newly replaced data for the key (key) for one hour!", 60 * 60 * 1);
}

//Deleting data for a key
if($cache->exists("key"))
{
  
$cache->delete("key"); //We've now deleted the data for the key (key)!
}

//Flushing a projects memory block
$cache->flush(); //All the data for our prefix is now gone!

?>