getCacheUrl() public static method

Creates a URL for cached data.
public static getCacheUrl ( string $type, array $params = [] ) : Horde_Url
$type string The cache type ('app', 'css', 'js').
$params array Optional parameters: - app: REQUIRED for $type == 'app'. Identifies the application to call the 'cacheOutput' API call, which is passed in the value of the entire $params array (which may include parameters other than those listed here). The return from cacheOutput should be a 2-element array: 'data' (the cached data) and 'type' (the content-type of the data). - cid: REQUIRED for $type == 'css' || 'js'. The cacheid of the data (stored in Horde_Cache). - nocache: If true, sets the cache limiter to 'nocache' instead of the default 'public'.
return Horde_Url The URL to the cache page.
Esempio n. 1
0
 /**
  */
 public function process($css, $cacheid)
 {
     global $injector;
     if (!empty($this->_params['filemtime'])) {
         foreach ($css as &$val) {
             $val['mtime'] = @filemtime($val['fs']);
         }
     }
     $cache = $injector->getInstance('Horde_Cache');
     $sig = hash(version_compare(PHP_VERSION, '5.4', '>=') ? 'fnv164' : 'sha1', json_encode($css) . $cacheid);
     // Do lifetime checking here, not on cache display page.
     if (!$cache->exists($sig, empty($this->_params['lifetime']) ? 0 : $this->_params['lifetime'])) {
         $compress = new Horde_Themes_Css_Compress();
         $cache->set($sig, $compress->compress($css));
     }
     return array(Horde::getCacheUrl('css', array('cid' => $sig)));
 }
Esempio n. 2
0
 /**
  */
 protected function _process($scripts)
 {
     global $injector;
     if (empty($scripts)) {
         return array();
     }
     $tmp = array();
     foreach ($scripts as $val) {
         $tmp[] = $val->modified;
     }
     $mtime = max($tmp);
     $hashes = array_keys($scripts);
     sort($hashes);
     $sig = hash(version_compare(PHP_VERSION, '5.4', '>=') ? 'fnv164' : 'sha1', json_encode($hashes) . $mtime);
     $cache = $injector->getInstance('Horde_Cache');
     $cache_lifetime = empty($this->_params['lifetime']) ? 0 : $this->_params['lifetime'];
     // Do lifetime checking here, not on cache display page.
     $js_url = Horde::getCacheUrl('js', array('cid' => $sig));
     $out = array($js_url);
     if ($cache->exists($sig, $cache_lifetime)) {
         return $out;
     }
     /* Check for existing process creating compressed file. Maximum 15
      * seconds wait time. */
     for ($i = 0; $i < 15; ++$i) {
         if ($cache->exists($sig . '.lock')) {
             sleep(1);
         } elseif ($i) {
             return $out;
         } else {
             $cache->set($sig . '.lock', 1);
             break;
         }
     }
     if (!isset($this->_compress)) {
         $this->_compress = new Horde_Script_Compress($this->_params['compress'], $this->_params);
     }
     $sourcemap_url = Horde::getCacheUrl('js', array('cid' => $sig . '.map'));
     $jsmin = $this->_compress->getMinifier($scripts, $sourcemap_url);
     $cache->set($sig, $jsmin->minify());
     if ($this->_compress->sourcemap_support) {
         $cache->set($sig . '.map', $jsmin->sourcemap());
     }
     $cache->expire($sig . '.lock');
     return $out;
 }