Skip to content

Commit

Permalink
Add collection caching
Browse files Browse the repository at this point in the history
  • Loading branch information
anagh-p committed May 10, 2018
1 parent 3dc72fb commit e53c014
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Quintype/Caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit e53c014

Please sign in to comment.