Skip to content

Instantly share code, notes, and snippets.

@kenjis
Created August 25, 2011 02:38
Show Gist options
  • Save kenjis/1169846 to your computer and use it in GitHub Desktop.
Save kenjis/1169846 to your computer and use it in GitHub Desktop.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006 - 2011 EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 2.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter XCache Caching Class
*
* NOTE:
* At the moment, It is not possible to store resources, callbacks or objects using xcache_* functions.
* http://xcache.lighttpd.net/wiki/XcacheApi)
* Because of that, this class uses the (un-)serialize() -functions to store the data internally
*
*
* @package CodeIgniter
* @subpackage Libraries
* @category Core
* @author Timo Hoen
* @link
*/
class Cache_xcache extends CI_Driver {
/**
* Fetch from Cache
*
* @param string
* @return mixed
*/
public function get($id)
{
if (! xcache_isset($id))
return FALSE;
return unserialize(xcache_get($id));
}
// ------------------------------------------------------------------------
/**
* Cache Save
*
* @param string Unique Key
* @param mixed Data to store
* @param int Length of time (in seconds) to cache the data
*
* @return boolean
*/
public function save($id, $data, $ttl = 60)
{
return xcache_set($id, serialize($data),$ttl);
}
// ------------------------------------------------------------------------
/**
* Delete from Cache
*
* @param mixed unique identifier of the item in the cache
* @param boolean
*/
public function delete($id)
{
return xcache_unset($id);
}
// ------------------------------------------------------------------------
/**
* Not yet implemented
*
* @return boolean
*/
public function clean()
{
return FALSE;
}
// ------------------------------------------------------------------------
/**
* Not yet implemented
*
* @param string user/filehits
* @return boolean FALSE
*/
public function cache_info($type = NULL)
{
return FALSE;
}
// ------------------------------------------------------------------------
/**
* Not yet implemented
*
* @param mixed key to get cache metadata on
* @return boolean FALSE
*/
public function get_metadata($id)
{
return FALSE;
}
// ------------------------------------------------------------------------
/**
* Is this caching driver supported on the system?
*
*
* @return TRUE;
*/
public function is_supported()
{
if ( ! extension_loaded('xcache'))
{
log_message('error', 'The XCache PHP extension must be loaded to use XCache.');
return FALSE;
}
if ( ! function_exists('serialize'))
{
log_message('error', 'The serialize function is not available.');
return FALSE;
}
return TRUE;
}
// ------------------------------------------------------------------------
}
// End Class
/* End of file Cache_xcache.php */
/* Location: ./system/libraries/Cache/drivers/Cache_xcache.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment