onPHP

core/Cache/RuntimeMemory.class.php Source File

 

RuntimeMemory.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2008 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: RuntimeMemory.class.php 5701 2008-12-31 16:02:05Z voxus $ */
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 ?>

generated by doxygen-1.5.7.1
for onPHP at Wed Dec 31 19:41:26 2008