Example #1
0
 if ($requestMethod != 'GET') {
     throw new \Exception('only GET supported');
 }
 $scssFile = $scss->getScssFileName($viewName);
 if (!file_exists($scssFile)) {
     throw new \Core3\Exception\FileNotFound();
 }
 $cachedFile = $scss->getCachedFileName($viewName);
 if (file_exists($cachedFile)) {
     $orgMtime = filemtime($scssFile);
     $cacheMtime = filemtime($cachedFile);
     if ($cacheMtime > $orgMtime) {
         $data = file_get_contents($cachedFile);
     } else {
         // update cache
         $data = $scss->renderViewToCss($viewName);
         $scss->writeCache($cachedFile, $data);
     }
 } else {
     // create initial cached
     $data = $scss->renderViewToCss($viewName);
     $scss->writeCache($cachedFile, $data);
 }
 $etag = '"' . md5($viewName . $scss->getCachedFileMtime($viewName)) . '"';
 header('ETag: ' . $etag);
 $timestamp = filemtime($scss->getCachedFileName($viewName));
 header('Last-Modified: ' . gmdate('D, d M Y H:i:s ', $timestamp) . 'GMT');
 if (isClientCachingDocument($etag)) {
     throw new \Core3\Exception\CachedInClient();
 }
 echo $data;