コード例 #1
0
ファイル: cache.php プロジェクト: annaqin/eden
 /**
  * Sets a cache path root
  *
  * @param string the root path
  * @return Eden_CacheModel
  */
 public function setRoot($root)
 {
     //argument 1 must be a string
     Eden_Cache_Error::i()->argument(1, 'string');
     $this->_path = (string) Eden_Path::i($root)->absolute();
     return $this;
 }
コード例 #2
0
ファイル: eden.php プロジェクト: rafamaxber/Arkay-sync
if(!class_exists('Eden_Cache')){class Eden_Cache extends Eden_Class{protected $_key=NULL;protected $_path=NULL;protected $_cache=array();public static function i(){return self::_getMultiple(__CLASS__);}public function __construct($root,$key='key.php'){Eden_Cache_Error::i()->argument(1,'string')->argument(2,'string');$this->setKey($key)->setRoot($root)->build();}public function build(){try{$this->_cache=Eden_File::i($this->_path.'/'.$this->_key)->getData();}catch(Eden_Path_Error $e){$this->_cache=array();}return $this;}public function get($key,$default=NULL){Eden_Cache_Error::i()->argument(1,'string');if($this->keyExists($key)){return Eden_File::i($this->_cache[$key])->getData();}return $default;}public function getCreated($key){Eden_Cache_Error::i()->argument(1,'string');if($this->keyExists($key)){return Eden_File::i($this->_cache[$key])->getTime();}return 0;}public function getKeys(){return array_keys($this->_cache);}public function keyExists($key){Eden_Cache_Error::i()->argument(1,'string');return isset($this->_cache[$key]) && file_exists($this->_cache[$key]);}public function remove($key){Eden_Cache_Error::i()->argument(1,'string');if(isset($this->_cache[$key])){unset($this->_cache[$key]);}Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache);return $this;}public function set($key,$path,$data){Eden_Cache_Error::i()->argument(1,'string')->argument(2,'string');$path=$this->_path.Eden_Path::i($path);Eden_File::i($path)->setData($data);$this->_cache[$key]=$path;Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache);return $this;}public function setKey($key){Eden_Cache_Error::i()->argument(1,'string');$this->_key=$key;return $this;}public function setRoot($root){Eden_Cache_Error::i()->argument(1,'string');$this->_path=(string) Eden_Path::i($root)->absolute();return $this;}}class Eden_Cache_Error extends Eden_Error{public static function i($message=NULL,$code=0){$class=__CLASS__;return new $class($message,$code);}}}