Cache.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2007 by Anton E. Lebedevich, 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: Cache.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012     
00023     final class Cache extends StaticFactory implements Instantiatable
00024     {
00025         const NOT_FOUND         = 'nil';
00026         
00027         const EXPIRES_FOREVER   = 604800; // 7 days
00028         const EXPIRES_MAXIMUM   = 21600; // 6 hrs
00029         const EXPIRES_MEDIUM    = 3600; // 1 hr
00030         const EXPIRES_MINIMUM   = 300; // 5 mins
00031         
00032         const DO_NOT_CACHE      = -2005;
00033         
00035         private static $map     = null;
00036         
00038         private static $peer    = null;
00039         
00041         private static $worker  = null;
00042         
00046         public static function me()
00047         {
00048             if (!self::$peer || !self::$peer->isAlive())
00049                 self::$peer = new RuntimeMemory();
00050             
00051             return self::$peer;
00052         }
00053         
00054         /* void */ public static function setPeer(CachePeer $peer)
00055         {
00056             self::$peer = $peer;
00057         }
00058         
00059         /* void */ public static function setDefaultWorker($worker)
00060         {
00061             Assert::isTrue(class_exists($worker, true));
00062             
00063             self::$worker = $worker;
00064         }
00065         
00069         public static function setDaoMap($map)
00070         {
00071             self::$map = $map;
00072         }
00073         
00077         public static function worker(GenericDAO $dao)
00078         {
00079             static $instances = array();
00080             
00081             $class = get_class($dao);
00082             
00083             if (!isset($instances[$class])) {
00084                 if (isset(self::$map[$class])) {
00085                     $className = self::$map[$class];
00086                     $instances[$class] = new $className($dao);
00087                 } elseif ($worker = self::$worker)
00088                     $instances[$class] = new $worker($dao);
00089                 else
00090                     $instances[$class] = new CommonDaoWorker($dao);
00091             }
00092             
00093             return $instances[$class];
00094         }
00095     }
00096 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4