Created
June 27, 2011 04:18
-
-
Save cbandy/1048308 to your computer and use it in GitHub Desktop.
For per-request caching, #4065
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
/** | |
* Non-persistent, in-memory implementation of [Kohana Cache](api/Kohana_Cache). | |
* | |
* @package Kohana/Cache | |
* @category Base | |
* @author Kohana Team | |
* @copyright (c) 2011 Kohana Team | |
* @license http://kohanaphp.com/license | |
*/ | |
class Kohana_Cache_Memory extends Cache | |
{ | |
/** | |
* @var array | |
*/ | |
protected $_data = array(); | |
public function delete($id) | |
{ | |
unset($this->_data[$id]; | |
return TRUE; | |
} | |
public function delete_all() | |
{ | |
$this->_data = array(); | |
return TRUE; | |
} | |
public function get($id, $default = NULL) | |
{ | |
if ( ! isset($this->_data[$id])) | |
return $default; | |
list($expiry, $data) = $this->_data[$id]; | |
if ($expiry < now()) | |
{ | |
unset($this->_data[$id]; | |
return $default; | |
} | |
return $data; | |
} | |
public function set($id, $data, $lifetime = NULL) | |
{ | |
if ($lifetime === NULL) | |
{ | |
$lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE); | |
} | |
$this->_data[$id] = array(now() + $lifetime, $data); | |
return TRUE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment