Example #1
0
 /**
  * Set X-Accel-Expires header for web server-side caching
  * @param bool|int $ttl
  */
 public function putExpires($ttl = null)
 {
     if (Debugger::isEnabled()) {
         return;
     }
     if (is_null($ttl)) {
         $ttl = $this->cache;
     }
     if ($ttl === true) {
         $ttl = self::DEFAULT_CACHE;
     }
     if (!$ttl or !is_numeric($ttl) or $ttl < 0) {
         return;
     }
     View::addExpires($ttl);
 }
Example #2
0
 /**
  * Output resource
  * @param $instance
  * @return bool
  * @throws Exception
  */
 public function view($instance)
 {
     if (!$this->isPrintable()) {
         throw new Exception("Resource of type '{$this->type}' is not printable");
     }
     // Cut extension
     $parts = explode('.', $instance);
     if (sizeof($parts) == 2) {
         if ($parts[1] == $this->type) {
             $instance = $parts[0];
         }
     }
     if (!$instance or !$this->checkInstance($instance)) {
         return false;
     }
     /*
      * Disabled due to nginx doesn't support Vary in fastcgi_cache implementation at the moment
      *
     // Detect if browser supports gzip compression
     $enc = false;
     if( !empty( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
         $encTypes = $_SERVER['HTTP_ACCEPT_ENCODING'];
         if( strpos( $encTypes, ',' ) ) {
             $encTypes = explode( ',', $encTypes );
         } else {
             $encTypes = array( $encTypes );
         }
         foreach( $encTypes as $type ) {
             $type = trim( $type );
             switch( $type ) {
             case 'gzip':
                 $enc = 'gzip';
                 break 2;
             }
         }
     }
     */
     $enc = 'gzip';
     if ($enc == 'gzip' and $data = $this->compileGZ($instance)) {
         // header( 'Vary: Accept-Encoding' );
         header('Content-Encoding: gzip');
     } else {
         $data = $this->compile($instance);
     }
     if (!$data) {
         return false;
     }
     header('Content-Type: ' . $this->contentType);
     if (!($modified = Cache::getInstance()->get("{$instance}_{$this->type}_modified"))) {
         $modified = gmdate('D, d M Y H:i:s') . ' GMT';
     }
     View::addExpires(Controller::DEFAULT_CACHE);
     header('Last-Modified: ' . $modified);
     header('Expires: ' . gmdate('D, d M Y H:i:s', time() + self::CACHE_TTL) . ' GMT');
     echo $data;
     return true;
 }