From 407954c8d6f948af0a69a68421c871902468595e Mon Sep 17 00:00:00 2001 From: Marco Menzel Date: Tue, 22 May 2018 09:34:57 +0200 Subject: [PATCH] allow multiple RestServer instances in a shared apc cache add suffix to apc-key for private urlMap-cache --- src/JK/RestServer/RestServer.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/JK/RestServer/RestServer.php b/src/JK/RestServer/RestServer.php index e1f4346..b757894 100644 --- a/src/JK/RestServer/RestServer.php +++ b/src/JK/RestServer/RestServer.php @@ -42,6 +42,7 @@ class RestServer public $params; public $format; public $cacheDir = '.'; + public $apcCacheSuffix; public $realm; /** @var Mode|string Operation mode, can be one of [debug, production] */ public $mode; @@ -87,6 +88,7 @@ public function __construct($mode = Mode::PRODUCTION, $realm = 'Rest Server') $this->mode = $mode; $this->realm = $realm; $this->header_manager = new HeaderManager(); + $this->apcCacheSuffix = crc32(__DIR__); if (php_sapi_name() !== 'cli') { $this->root = ltrim(dirname($_SERVER['SCRIPT_NAME']).DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); @@ -108,7 +110,7 @@ public function __destruct() { if ($this->mode == Mode::PRODUCTION && !$this->cached) { if (function_exists('apc_store')) { - apc_store('urlMap', $this->map); + apc_store('urlMap_'.$this->apcCacheSuffix, $this->map); } else { file_put_contents($this->cacheDir.DIRECTORY_SEPARATOR.'urlMap.cache', serialize($this->map)); } @@ -340,7 +342,7 @@ protected function loadCache() if ($this->mode == Mode::PRODUCTION) { if (function_exists('apc_fetch')) { - $map = apc_fetch('urlMap'); + $map = apc_fetch('urlMap_'.$this->apcCacheSuffix); } elseif (file_exists($this->cacheDir.DIRECTORY_SEPARATOR.'urlMap.cache')) { $map = unserialize(file_get_contents($this->cacheDir.DIRECTORY_SEPARATOR.'urlMap.cache')); } @@ -350,7 +352,7 @@ protected function loadCache() } } else { if (function_exists('apc_delete')) { - apc_delete('urlMap'); + apc_delete('urlMap_'.$this->apcCacheSuffix); } else { @unlink($this->cacheDir.DIRECTORY_SEPARATOR.'urlMap.cache'); }