Loader.php
00001 <?php
00012 class Dsao_Cache_Loader
00013 {
00017 protected static $_backendName = 'File';
00018
00022 protected static $_backendOptions = array();
00023
00027 protected $_cache = null;
00028
00036 public function __construct($frontendName = 'Core', array $frontendOptions = array())
00037 {
00038
00039
00040
00041 $this->_cache = Zend_Cache::factory(
00042 (string) $frontendName, self::$_backendName,
00043 $frontendOptions, self::$_backendOptions);
00044 }
00045
00061 public function getObject($class, $id = null, $constructorParameters = null, array $tags = array())
00062 {
00063
00064 $id = $id ? $id : $class;
00065
00066
00067 if (!$this->_cache->test($id))
00068 {
00069 $constructor = new $class();
00070
00071
00072 if ($constructor instanceof Dsao_Constructor_Interface)
00073 {
00074
00075 $object = call_user_func_array(array($constructor, 'getObject'),
00076 (array) $constructorParameters);
00077 }
00078
00079 else
00080 {
00081 $object = $constructor;
00082 }
00083
00084
00085 $this->_cache->save($object, $id, $tags);
00086 }
00087
00088 else
00089 {
00090 $object = $this->_cache->load($id);
00091 }
00092
00093 return $object;
00094 }
00095
00101 public static function getBackendName()
00102 {
00103 return self::$_backendName;
00104 }
00105
00111 public static function getBackendOptions()
00112 {
00113 return self::$_backendOptions;
00114 }
00115
00121 public function getCache()
00122 {
00123 return $this->_cache;
00124 }
00125
00132 public static function setBackendName($backendName)
00133 {
00134 self::$_backendName = $backendName;
00135 }
00136
00143 public static function setBackendOptions(array $backendOptions)
00144 {
00145 self::$_backendOptions = $backendOptions;
00146 }
00147 }