diff --git a/src/Lunr/Corona/Model.php b/src/Lunr/Corona/Model.php index 21a3e1d0..65a30257 100644 --- a/src/Lunr/Corona/Model.php +++ b/src/Lunr/Corona/Model.php @@ -109,6 +109,18 @@ protected function cache_if_needed(string $id, callable $callable, array $args = return $value; } + /** + * Delete cache item. + * + * @param string $key Unique identifier for the data. + * + * @return bool True if the item was successfully removed. False if there was an error. + */ + protected function delete_from_cache(string $key): bool + { + return $this->cache->deleteItem($key); + } + } ?> diff --git a/src/Lunr/Corona/Tests/ModelCacheTest.php b/src/Lunr/Corona/Tests/ModelCacheTest.php index 8131c63f..76b6e6e8 100644 --- a/src/Lunr/Corona/Tests/ModelCacheTest.php +++ b/src/Lunr/Corona/Tests/ModelCacheTest.php @@ -249,6 +249,23 @@ public function testCacheIfNeededCachesWhenNeededWithArgs() $this->assertEquals('test param', $result); } + /** + * Test that delete_from_cache() deletes value from cache. + * + * @covers \Lunr\Corona\Model::delete_from_cache + */ + public function testDeleteFromCache() + { + $this->cache->expects($this->once()) + ->method('deleteItem') + ->with('foo') + ->willReturn(TRUE); + + $method = $this->get_accessible_reflection_method('delete_from_cache'); + + $method->invokeArgs($this->class, [ 'foo' ]); + } + } ?>