• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Cache/Frontend/Function.php

00001 <?php
00027 require_once 'Zend/Cache/Core.php';
00028 
00029 
00036 class Zend_Cache_Frontend_Function extends Zend_Cache_Core
00037 {
00052     protected $_specificOptions = array(
00053         'cache_by_default' => true,
00054         'cached_functions' => array(),
00055         'non_cached_functions' => array()
00056     );
00057 
00064     public function __construct(array $options = array())
00065     {
00066         while (list($name, $value) = each($options)) {
00067             $this->setOption($name, $value);
00068         }
00069         $this->setOption('automatic_serialization', true);
00070     }
00071 
00082     public function call($name, $parameters = array(), $tags = array(), $specificLifetime = false, $priority = 8)
00083     {
00084         $cacheBool1 = $this->_specificOptions['cache_by_default'];
00085         $cacheBool2 = in_array($name, $this->_specificOptions['cached_functions']);
00086         $cacheBool3 = in_array($name, $this->_specificOptions['non_cached_functions']);
00087         $cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
00088         if (!$cache) {
00089             // We do not have not cache
00090             return call_user_func_array($name, $parameters);
00091         }
00092         $id = $this->_makeId($name, $parameters);
00093         if ($this->test($id)) {
00094             // A cache is available
00095             $result = $this->load($id);
00096             $output = $result[0];
00097             $return = $result[1];
00098         } else {
00099             // A cache is not available
00100             ob_start();
00101             ob_implicit_flush(false);
00102             $return = call_user_func_array($name, $parameters);
00103             $output = ob_get_contents();
00104             ob_end_clean();
00105             $data = array($output, $return);
00106             $this->save($data, $id, $tags, $specificLifetime, $priority);
00107         }
00108         echo $output;
00109         return $return;
00110     }
00111 
00120     private function _makeId($name, $parameters)
00121     {
00122         if (!is_string($name)) {
00123             Zend_Cache::throwException('Incorrect function name');
00124         }
00125         if (!is_array($parameters)) {
00126             Zend_Cache::throwException('parameters argument must be an array');
00127         }
00128         return md5($name . serialize($parameters));
00129     }
00130 
00131 }

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2