From df23690a93ded5991758f01744d38f70aa45f8d3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 15 Oct 2020 11:45:15 -0400 Subject: [PATCH] Add routes file recompute on last modification time change --- src/App/Router.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/App/Router.php b/src/App/Router.php index dfe890fb96..d27a9c1ae9 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -268,20 +268,33 @@ class Router * The cached "routerDispatchData" lasts for a day, and must be cleared manually when there * is any changes in the enabled addons list. * + * Additionally, we check for the base routes file last modification time to automatically + * trigger re-computing the dispatch data. + * * @return array|mixed * @throws HTTPException\InternalServerErrorException */ private function getCachedDispatchData() { $routerDispatchData = $this->cache->get('routerDispatchData'); + $lastRoutesFileModifiedTime = $this->cache->get('lastRoutesFileModifiedTime'); + $forceRecompute = false; - if ($routerDispatchData) { + if ($this->baseRoutesFilepath && file_exists($this->baseRoutesFilepath)) { + $routesFileModifiedTime = filemtime($this->baseRoutesFilepath); + $forceRecompute = $lastRoutesFileModifiedTime != $routesFileModifiedTime; + } + + if (!$forceRecompute && $routerDispatchData) { return $routerDispatchData; } $routerDispatchData = $this->getDispatchData(); $this->cache->set('routerDispatchData', $routerDispatchData, Duration::DAY); + if (!empty($routesFileModifiedTime)) { + $this->cache->set('lastRoutesFileMtime', $routesFileModifiedTime, Duration::MONTH); + } return $routerDispatchData; }