Skip to content

Commit

Permalink
Fix cache key generation (remove slashes)
Browse files Browse the repository at this point in the history
  • Loading branch information
iherak committed Mar 19, 2018
1 parent d8036a4 commit 59a8277
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Cache/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public function __construct(CacheService $cacheService)
$this->cacheService = $cacheService;
}

/**
* Remove slashes from start and end of keys, and for content replace it with _ to avoid issues for Stash.
*
* @param string $key
* @return string
*/
private function washKey($key)
{
return str_replace('/', '_', trim($key, '/'));
}

/**
* @return bool
*/
Expand Down Expand Up @@ -42,7 +53,7 @@ public function clear()
public function getItem($key)
{
if (is_array($key)) {
$key = implode('/', $key);
$key = implode('/', array_map([$this, 'washKey'], $key));
}

return $this->cacheService->getItem($key);
Expand Down

0 comments on commit 59a8277

Please sign in to comment.