Location: PHPKode > projects > Thin PHP Framework > ngduc-Thin-PHP-Framework-d63ea45/app/cache/base/BaseCache.php
<?php
/**
 * Thin PHP Framework (TPF) 2011-2012 http://thinphp.com
 * @package       app.cache.base
 * @license       TPF License http://bit.ly/TPFLicense
 */
defined('BASE') or exit('No direct script access allowed!');
require_once 'ICache.php';

abstract class BaseCache implements ICache
{	
	private $_prefix;
	
	/**
	 * Constructor
	 */
	public function __construct($prefix)
	{
		$this->_prefix = $prefix;
	}
	
	private function getId_md5($id)
	{
		// append 'prefix' to $id
		return md5($this->_prefix.$id);
	}
	
	// ================== MUST BE IMPLEMENTED IN EXTENDING CLASSES ================== //
	
	abstract protected function getEntry($id);

	abstract protected function setEntry($id, $value, $lifeinsecs=0);

	abstract protected function delEntry($id);
	
	// ================== PUBLIC FUNCTIONS ================== //
	
	public function get($id)
	{
		if (($val = $this->getEntry($this->getId_md5($id))) !== false)
		{
			return $val;
		}
		return false;
	}
	
	public function set($id, $value, $lifeinsecs=0)
	{
		return $this->setEntry($this->getId_md5($id), $value, $lifeinsecs);
	}
	
	public function del($id)
	{
		return delEntry($id);
	}
}
Return current item: Thin PHP Framework