From e53c0142e5795c734cac1b1477f64848c4321669 Mon Sep 17 00:00:00 2001 From: Anagh Padmanabhan Date: Thu, 10 May 2018 11:21:45 +0530 Subject: [PATCH] Add collection caching --- src/Quintype/Caching.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Quintype/Caching.php b/src/Quintype/Caching.php index 3416df9..3daefbb 100644 --- a/src/Quintype/Caching.php +++ b/src/Quintype/Caching.php @@ -13,11 +13,20 @@ private function buildStoryKeys($params) return implode(' ', $storyKeys); } + private function buildCollectionKeys($params) + { + $collectionKeys = []; + foreach ($params['storiesToCache'] as $key => $collection) { + array_push($collectionKeys, 'c/'.$params['publisherId'].'/'. trim($collection['id'])); + } + return implode(' ', $collectionKeys); + } + private function buildStoryKeysFromCollections($params) { $stories = []; foreach ($params['storiesToCache'] as $key => $collection) { - foreach ($collection['items'] as $key => $item) { + foreach (array_slice($collection['items'], 0, 5) as $key => $item) { if ($item['type'] === 'story') { array_push($stories, $item['story']); } @@ -36,7 +45,7 @@ private function buildSurrogateKey($cacheParams) if (isset($cacheParams['storiesToCache'])) { if (isset($cacheParams['storiesFrom']) && $cacheParams['storiesFrom'] === "collection"){ - $surrogateKey = $surrogateKey.' '.$this->buildStoryKeysFromCollections($cacheParams); + $surrogateKey = $surrogateKey.' '.$this->buildStoryKeysFromCollections($cacheParams).' '. $this->buildCollectionKeys($cacheParams); } else { $surrogateKey = $surrogateKey.' '.$this->buildStoryKeys($cacheParams); }