コード例 #1
0
ファイル: RouteTest.php プロジェクト: cawaphp/cawa
 /**
  * Test Empty Option
  */
 public function testGetEmptyOption()
 {
     $route = new Route();
     $this->assertNull($route->getOption(Route::OPTIONS_CACHE));
 }
コード例 #2
0
ファイル: Router.php プロジェクト: cawaphp/cawa
 /**
  * @param Route $route
  * @param string $cacheKey
  * @param $return
  *
  * @return bool
  */
 private function cacheSet(Route $route, string $cacheKey, $return) : bool
 {
     if ($route->getOption(AbstractRoute::OPTIONS_CACHE)) {
         $second = $route->getOption(AbstractRoute::OPTIONS_CACHE);
         if (self::session()->isStarted()) {
             throw new \LogicException("Can't set a cache on a route that use session data");
         }
         self::response()->addHeader('Expires', gmdate('D, d M Y H:i:s', time() + $second) . ' GMT');
         self::response()->addHeader('Cache-Control', 'public, max-age=' . $second . ', must-revalidate');
         self::response()->addHeader('Pragma', 'public, max-age=' . $second . ', must-revalidate');
         self::response()->addHeader('Vary', 'Accept-Encoding');
         $data = ['output' => $return, 'headers' => self::response()->getHeaders()];
         self::cache('OUTPUT')->set($cacheKey, $data, $second);
     }
     return true;
 }