Created
December 26, 2013 11:16
-
-
Save renan/8132446 to your computer and use it in GitHub Desktop.
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 | |
class OneEntryCacheEngine extends CacheEngine { | |
protected $_dirty = false; | |
protected $_data = false; | |
public function read($key) { | |
if ($this->_data === false) { | |
$this->_data = (array)Cache::read($this->_config['cacheKey'], $this->_config['cacheConfig']); | |
} | |
if (!array_key_exists($key, $this->_data)) { | |
return false; | |
} | |
return $this->_data[$key]; | |
} | |
public function write($key, $value) { | |
if ($this->_data === false) { | |
$this->_data = []; | |
} | |
$this->_dirty = true; | |
$this->_data[$key] = $value; | |
} | |
public function shutdown() { | |
if ($this->_dirty === false) { | |
return; | |
} | |
Cache::write($this->_config['cacheKey'], $this->_data, $this->_config['cacheConfig']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment