Skip to content

Commit

Permalink
Make sure to invalidate cache properly (#90)
Browse files Browse the repository at this point in the history
Make sure to invalidate cache properly
  • Loading branch information
Nyholm committed Jun 28, 2016
1 parent 5711b65 commit e14a981
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Manager/CachedSettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function all(SettingsOwnerInterface $owner = null)
public function set($name, $value, SettingsOwnerInterface $owner = null)
{
$this->invalidateCache($name, $owner);
$this->invalidateCache(null, $owner);

return $this->settingsManager->set($name, $value, $owner);
}
Expand All @@ -92,6 +93,7 @@ public function setMany(array $settings, SettingsOwnerInterface $owner = null)
foreach ($settings as $key => $value) {
$this->invalidateCache($key, $owner);
}
$this->invalidateCache(null, $owner);

return $this->settingsManager->setMany($settings, $owner);
}
Expand All @@ -102,6 +104,7 @@ public function setMany(array $settings, SettingsOwnerInterface $owner = null)
public function clear($name, SettingsOwnerInterface $owner = null)
{
$this->invalidateCache($name, $owner);
$this->invalidateCache(null, $owner);

return $this->settingsManager->clear($name, $owner);
}
Expand Down
20 changes: 16 additions & 4 deletions Tests/CachedSettingsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,19 @@ public function testSet()
->setMethods(array('invalidateCache'))
->setConstructorArgs(array($settingsManager, $this->getMock(CacheItemPoolInterface::class), 4711))
->getMock();
$cachedSettingsManager->expects($this->once())

// Clear the cache
$cachedSettingsManager->expects($this->at(0))
->method('invalidateCache')
->with($this->equalTo($name), $this->equalTo($owner))
->willReturn(null);

// Clear all cache for this owner
$cachedSettingsManager->expects($this->at(1))
->method('invalidateCache')
->with($this->equalTo(null), $this->equalTo($owner))
->willReturn(null);

$cachedSettingsManager->set($name, $value, $owner);
}

Expand All @@ -131,9 +139,9 @@ public function testSetMany()
->setMethods(array('invalidateCache'))
->setConstructorArgs(array($settingsManager, $this->getMock(CacheItemPoolInterface::class), 4711))
->getMock();
$cachedSettingsManager->expects($this->exactly(3))
$cachedSettingsManager->expects($this->exactly(4))
->method('invalidateCache')
->with($this->logicalOr('name0', 'name1', 'name2'), $owner);
->with($this->logicalOr('name0', 'name1', 'name2', null), $owner);

$cachedSettingsManager->setMany($settings, $owner);
}
Expand All @@ -150,10 +158,14 @@ public function testClear()
->setMethods(array('invalidateCache'))
->setConstructorArgs(array($settingsManager, $this->getMock(CacheItemPoolInterface::class), 4711))
->getMock();
$cachedSettingsManager->expects($this->once())
$cachedSettingsManager->expects($this->at(0))
->method('invalidateCache')
->with($this->equalTo($name), $this->equalTo($owner))
->willReturn(null);
$cachedSettingsManager->expects($this->at(1))
->method('invalidateCache')
->with($this->equalTo(null), $this->equalTo($owner))
->willReturn(null);

$cachedSettingsManager->clear($name, $owner);
}
Expand Down

0 comments on commit e14a981

Please sign in to comment.