Memcache PHP5 Library

Well it has been a couple of months since my last blog post so I decided I better make my next one post a good one. I have created a simple PHP5 library to interact with the memcache php library.

Some of the library features are:

  • Create one instance of library with ability to pass through different options.
  • Debug features to see the cached, requested and deleted input.
  • Prefix keys automatically and ability to encrypt the key.

Prefixing the keys is a good idea if you have multiple sites that connect to the same memcached server and running the same code which could share the same key names. This will stop any of the sites sharing data across the other sites that really shouldn’t be sharing data with.

Sample use on how to use the library:

<?php
/**
 * Include the memcache library and set up a new instance
 */
require_once "memcache.php";

$memCache = CacheManager::getInstance( "some_prefix", true, true );

/**
 * Add a new server, set a value and get it back
 */

$memCache->addServer("Server IP or address");

echo "Setting a value on the memcache server:<br />";
var_dump( $memCache->set("some_key", "This is the value of the key") );

echo "Retrieving the value from the server:<br />";
var_dump( $memCache->get("some_key") );

/**
 * Delete the key from the server
 */
echo "Deleting the key from the server:<br />";
var_dump( $memCache->delete("some_key") );

echo "Debug Information:<br />";
var_dump( $memCache->returnDebug() );
?>

Download Library:

If you have any problems, questions or suggestions please leave a comment. I would be happy to here your feedback.

Leave a Reply