Skip to content

Instantly share code, notes, and snippets.

@renan
Created December 26, 2013 11:16
Show Gist options
  • Save renan/8132446 to your computer and use it in GitHub Desktop.
Save renan/8132446 to your computer and use it in GitHub Desktop.
<?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