Skip to content

Instantly share code, notes, and snippets.

@dragoonis
Created April 11, 2011 20:38
Show Gist options
  • Save dragoonis/914275 to your computer and use it in GitHub Desktop.
Save dragoonis/914275 to your computer and use it in GitHub Desktop.
<?php
/**
*
* @version 1.0
* @author Paul Dragoonis <dragoonis@php.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @copyright Digiflex Development
* @package Cache
*/
class PPI_Cache_XCache implements PPI_Cache_Interface {
/**
* Get a value from cache
* @param string $p_sKey The Key
* @return mixed
*/
function get($p_sKey) { return xcache_get($p_sKey); }
function init() {}
/**
* Set a value in the cache
* @param string $p_sKey The Key
* @param mixed $p_mData The Data
* @param mixed $p_iTTL The Time To Live. Integer or String (strtotime)
* @return boolean True on succes, False on failure.
*/
function set($p_sKey, $p_mData, $p_mTTL = 0) {
return xcache_set($p_sKey, $p_mData, (is_numeric($p_mTTL) ? $p_mTTL : strtotime($p_mTTL)));
}
/**
* Check if a key exists in the cache
* @param string $p_mKey The Key
* @return boolean
*/
function exists($p_sKey) { return xcache_isset($p_sKey); }
/**
* Remove a key from the cache
* @param string $p_sKey The Key
* @return boolean
*/
function remove($p_sKey) { return xcache_unset($p_sKey); }
/**
* Wipe the cache contents
* @todo This uses some kind of authentication - must look into it more.
* @return unknown
*/
function clear() { return apc_clear_cache('user'); }
/**
* Increment a numerical value
*
* @param string $p_sKey The Key
* @param numeric $p_iInc The incremental value
* @return numeric
*/
function increment($p_sKey, $p_iInc = 1) { return xcache_inc($p_sKey, $p_iInc); }
/**
* Enter description here...
*
* @param string $p_sKey The Key
* @param numeric $p_iDec The decremental value
* @return numeric
*/
function decrement($p_sKey, $p_iDec = 1) { return xcache_dec($p_sKey, $p_iDec); }
/**
* Check if the APC extension has been loaded and is enabled in its configuration.
*
* @return boolean
*/
function enabled() { return extension_loaded('xcache'); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment