Updated UrlShortener to namespace the cache entries

This commit is contained in:
Alejandro Celaya
2016-08-09 13:32:33 +02:00
parent 99b7c77997
commit 8eb279fd28
2 changed files with 7 additions and 6 deletions

View File

@@ -148,9 +148,10 @@ class UrlShortener implements UrlShortenerInterface
*/
public function shortCodeToUrl($shortCode)
{
$cacheKey = sprintf('%s_longUrl', $shortCode);
// Check if the short code => URL map is already cached
if ($this->cache->contains($shortCode)) {
return $this->cache->fetch($shortCode);
if ($this->cache->contains($cacheKey)) {
return $this->cache->fetch($cacheKey);
}
// Validate short code format
@@ -165,7 +166,7 @@ class UrlShortener implements UrlShortenerInterface
// Cache the shortcode
if (isset($shortUrl)) {
$url = $shortUrl->getOriginalUrl();
$this->cache->save($shortCode, $url);
$this->cache->save($cacheKey, $url);
return $url;
}