Skip to content

Commit

Permalink
rename internal key for cache expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 13, 2022
1 parent dafd2d5 commit 3ba7c91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Cache/BaseDataCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public function getData($key, $default = null)
return $default;
}

if (! array_key_exists('cache_expiration_time', $data)) {
if (! array_key_exists('__cache_expiration_time', $data)) {
return $default;
}

if ($data['cache_expiration_time'] < time()) {
if ($data['__cache_expiration_time'] < time()) {
return $default;
}

unset($data['cache_expiration_time']);
unset($data['__cache_expiration_time']);

return $data;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public function setData($key, array $value, $ttl = null)
$ttl = 3600;
}

$value['cache_expiration_time'] = time() + $ttl;
$value['__cache_expiration_time'] = time() + $ttl;

return $this->cache->save($value);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Cache/BaseDataCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testSetDataReturnsFalseIfDataCouldNotBeWritten()
public function testGetDataReturnsCorrectData()
{
$key = 'name';
$cachedValue = ['cache_expiration_time' => time() + 3600];
$cachedValue = ['__cache_expiration_time' => time() + 3600];
$value = [];

$baseCache = $this->createMock(Base::class);
Expand All @@ -108,7 +108,7 @@ public function testGetDataWithCacheMissReturnsDefault()
public function testGetDataWithCacheExpiredReturnsDefault()
{
$key = 'name';
$cachedValue = ['cache_expiration_time' => 0];
$cachedValue = ['__cache_expiration_time' => 0];
$default = new stdClass();

$baseCache = $this->createMock(Base::class);
Expand Down

0 comments on commit 3ba7c91

Please sign in to comment.