diff --git a/newscoop/library/Newscoop/Cache/CacheKey.php b/newscoop/library/Newscoop/Cache/CacheKey.php new file mode 100644 index 0000000000..2ade971cf4 --- /dev/null +++ b/newscoop/library/Newscoop/Cache/CacheKey.php @@ -0,0 +1,22 @@ + + * @license http://www.gnu.org/licenses/gpl-3.0.txt + */ + +namespace Newscoop; + +/** + * Cache key + */ +class CacheKey extends ValueObject +{ + public $key; + + public function __toString() + { + return $this->key; + } +} diff --git a/newscoop/library/Newscoop/Services/CacheService.php b/newscoop/library/Newscoop/Services/CacheService.php index b3bfd7b778..3fa0a23528 100644 --- a/newscoop/library/Newscoop/Services/CacheService.php +++ b/newscoop/library/Newscoop/Services/CacheService.php @@ -8,6 +8,8 @@ namespace Newscoop\Services; +use Newscoop\CacheKey; + /** * Cache service */ @@ -87,12 +89,16 @@ public function delete($id) public function getCacheKey($id, $namespace = null) { + if (is_a($id, 'Newscoop\CacheKey')) { + return $id->key; + } + if (is_array($id)) { $id = implode('__', $id); } // make cache key short - $id = base64_encode($id); + $id = base64_encode($id.'|'.$this->systemPreferences->installation_id); if ($namespace) { $namespace = $this->getNamespace($namespace); @@ -100,7 +106,7 @@ public function getCacheKey($id, $namespace = null) return $namespace.'__'.$id; } - return $id; + return new CacheKey(array('key' => $id)); } public function getNamespace($namespace) @@ -109,7 +115,7 @@ public function getNamespace($namespace) return $this->getCacheDriver()->fetch($namespace); } - $value = $namespace .'|'.time(); + $value = $namespace .'|'.time().'|'.$this->systemPreferences->installation_id; $this->getCacheDriver()->save($namespace, $value); return $value; diff --git a/newscoop/src/Newscoop/NewscoopBundle/Controller/BackendJournalistDashboardController.php b/newscoop/src/Newscoop/NewscoopBundle/Controller/BackendJournalistDashboardController.php index d53c487d7d..cdbc398e5e 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/Controller/BackendJournalistDashboardController.php +++ b/newscoop/src/Newscoop/NewscoopBundle/Controller/BackendJournalistDashboardController.php @@ -89,7 +89,7 @@ public function loadUsersAction(Request $request) } $criteria = $this->getCriteria($request); - $cacheKey = array('author_articles__'.md5(serialize($criteria)), $author->getId()); + $cacheKey = $cacheService->getCacheKey(array('author_articles__'.md5(serialize($criteria)), $author->getId())); if ($cacheService->contains($cacheKey)) { $responseArray = $cacheService->fetch($cacheKey); diff --git a/newscoop/src/Newscoop/NewscoopBundle/Controller/UsersController.php b/newscoop/src/Newscoop/NewscoopBundle/Controller/UsersController.php index 05c5911fe7..c99f42f18c 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/Controller/UsersController.php +++ b/newscoop/src/Newscoop/NewscoopBundle/Controller/UsersController.php @@ -70,7 +70,7 @@ public function loadUsersAction(Request $request) $registered = $userService->countBy(array('status' => User::STATUS_ACTIVE)); $pending = $userService->countBy(array('status' => User::STATUS_INACTIVE)); - $cacheKey = array('users__'.md5(serialize($criteria)), $registered, $pending); + $cacheKey = $cacheService->getCacheKey(array('users__'.md5(serialize($criteria)), $registered, $pending)); if ($cacheService->contains($cacheKey)) { $responseArray = $cacheService->fetch($cacheKey); diff --git a/newscoop/src/Newscoop/NewscoopBundle/EventListener/OldPluginsTranslationListener.php b/newscoop/src/Newscoop/NewscoopBundle/EventListener/OldPluginsTranslationListener.php index 63431bce6c..e256d89307 100644 --- a/newscoop/src/Newscoop/NewscoopBundle/EventListener/OldPluginsTranslationListener.php +++ b/newscoop/src/Newscoop/NewscoopBundle/EventListener/OldPluginsTranslationListener.php @@ -43,7 +43,7 @@ public function onRequest(GetResponseEvent $event) } $locale = $event->getRequest()->getLocale(); - $cacheKey = 'oldPlugins_translations_'.count($this->pluginsService->getEnabledPlugins()); + $cacheKey = $cacheService->getCacheKey('oldPlugins_translations_'.count($this->pluginsService->getEnabledPlugins())); if ($this->cacheService->contains($cacheKey)) { $files = $this->cacheService->fetch($cacheKey); } else {