12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- class sfFunctionCache
- {
- protected $cache = null;
-
- public function __construct($cache)
- {
- if (!is_object($cache))
- {
- $this->cache = new sfFileCache($cache);
- throw new sfException('DEPRECATED: You must now pass a sfCache object when initializing a sfFunctionCache object. Be warned that the call() method signature has also changed.');
- }
- $this->cache = $cache;
- }
-
- public function call($callable, $arguments = array())
- {
-
- $key = md5(serialize($callable).serialize($arguments));
- $serialized = $this->cache->get($key);
- if ($serialized !== null)
- {
- $data = unserialize($serialized);
- }
- else
- {
- $data = array();
- if (!is_callable($callable))
- {
- throw new sfException('The first argument to call() must be a valid callable.');
- }
- ob_start();
- ob_implicit_flush(false);
- try
- {
- $data['result'] = call_user_func_array($callable, $arguments);
- }
- catch (Exception $e)
- {
- ob_end_clean();
- throw $e;
- }
- $data['output'] = ob_get_clean();
- $this->cache->set($key, serialize($data));
- }
- echo $data['output'];
- return $data['result'];
- }
- }
|