diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-10-28 17:53:05 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-10-29 15:04:55 +0100 |
commit | 4d03b3dbaf9d2f949d113406ac15961c93866c71 (patch) | |
tree | 60d01939c517ad9d7656715da96c440ffcc7b436 /lib/router.php | |
parent | a7806076b1c20b80c0f1d1ee72e9050c8bda9715 (diff) | |
download | nextcloud-server-4d03b3dbaf9d2f949d113406ac15961c93866c71.tar.gz nextcloud-server-4d03b3dbaf9d2f949d113406ac15961c93866c71.zip |
Add ETag caching for Javascript routes
Diffstat (limited to 'lib/router.php')
-rw-r--r-- | lib/router.php | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/lib/router.php b/lib/router.php index d5adb72055a..dae2e91372e 100644 --- a/lib/router.php +++ b/lib/router.php @@ -17,7 +17,9 @@ class OC_Router { protected $collection = null; protected $root = null; - protected $generator= null; + protected $generator = null; + protected $routing_files; + protected $cache_key; public function __construct() { $baseUrl = OC_Helper::linkTo('', 'index.php'); @@ -29,18 +31,37 @@ class OC_Router { $this->root = $this->getCollection('root'); } + public function getRoutingFiles() { + if (!isset($this->routing_files)) { + $this->routing_files = array(); + foreach(OC_APP::getEnabledApps() as $app){ + $file = OC_App::getAppPath($app).'/appinfo/routes.php'; + if(file_exists($file)) { + $this->routing_files[$app] = $file; + } + } + } + return $this->routing_files; + } + + public function getCacheKey() { + if (!isset($this->cache_key)) { + $files = $this->getRoutingFiles(); + $files[] = 'core/routes.php'; + $this->cache_key = OC_Cache::generateCacheKeyFromFiles($files); + } + return $this->cache_key; + } + /** * loads the api routes */ public function loadRoutes() { - foreach(OC_APP::getEnabledApps() as $app){ - $file = OC_App::getAppPath($app).'/appinfo/routes.php'; - if(file_exists($file)) { - $this->useCollection($app); - require_once $file; - $collection = $this->getCollection($app); - $this->root->addCollection($collection, '/apps/'.$app); - } + foreach($this->getRoutingFiles() as $app => $file) { + $this->useCollection($app); + require_once $file; + $collection = $this->getCollection($app); + $this->root->addCollection($collection, '/apps/'.$app); } $this->useCollection('root'); require_once('core/routes.php'); @@ -128,10 +149,14 @@ class OC_Router { */ public static function JSRoutes() { - // TODO: http caching - $routes = array(); $router = OC::getRouter(); + + $etag = $router->getCacheKey(); + OC_Response::enableCaching(); + OC_Response::setETagHeader($etag); + $root = $router->getCollection('root'); + $routes = array(); foreach($root->all() as $name => $route) { $compiled_route = $route->compile(); $defaults = $route->getDefaults(); |