RuntimeMemory.class.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 final class RuntimeMemory extends CachePeer
00019 {
00020 private $cache = array();
00021
00025 public static function create()
00026 {
00027 return new self;
00028 }
00029
00030 public function isAlive()
00031 {
00032 return true;
00033 }
00034
00035 public function increment($key, $value)
00036 {
00037 if (isset($this->cache[$key]))
00038 return $this->cache[$key] += $value;
00039
00040 return null;
00041 }
00042
00043 public function decrement($key, $value)
00044 {
00045 if (isset($this->cache[$key]))
00046 return $this->cache[$key] -= $value;
00047
00048 return null;
00049 }
00050
00051 public function get($key)
00052 {
00053 if (isset($this->cache[$key]))
00054 return $this->cache[$key];
00055
00056 return null;
00057 }
00058
00059 public function delete($key)
00060 {
00061 if (isset($this->cache[$key])) {
00062 unset($this->cache[$key]);
00063 return true;
00064 }
00065
00066 return false;
00067 }
00068
00072 public function clean()
00073 {
00074 $this->cache = array();
00075
00076 return parent::clean();
00077 }
00078
00079 public function append($key, $data)
00080 {
00081 if (isset($this->cache[$key])) {
00082 $this->cache[$key] .= $data;
00083 return true;
00084 }
00085
00086 return false;
00087 }
00088
00089 protected function store($action, $key, $value, $expires = 0)
00090 {
00091 if ($action == 'add' && isset($this->cache[$key]))
00092 return true;
00093 elseif ($action == 'replace' && !isset($this->cache[$key]))
00094 return false;
00095
00096 if (is_object($value))
00097 $this->cache[$key] = clone $value;
00098 else
00099 $this->cache[$key] = $value;
00100
00101 return true;
00102 }
00103 }
00104 ?>