<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

class Cache_ZendAdapter extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
{
	protected $_cacher=null;
	
	public function __construct($options=array(NULL))
	{
		if (!is_dir($options['cacheDir'])) {
			mkdir($options['cacheDir'], 0777, true);
		}
		$this->_cacher=new Cache_Lite($options);
	}
	
	public function save($data, $id, $tags = array(), $specificLifetime = false)
	{
		if ($specificLifetime) {
			$current=$this->_cacher->_lifeTime;
			$this->_cacher->setLifeTime($specificLifetime);
		}
		$result=$this->_cacher->save($data, $id);
		if ($specificLifetime) $this->_cacher->setLifeTime($current);
		if ($result) return true;
	}
	
	public function load($id, $doNotTestCacheValidity = false)
	{
		return $this->_cacher->get($id, 'default', $doNotTestCacheValidity);
	}
	
	public function remove($id)
	{
		return $this->_cacher->remove($id, 'default', true);
	}
	
	public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
	{
		return $this->_cacher->clean();
	}
	
	public function test($id)
	{
	}
}