Skip to content

Commit

Permalink
Corona: Add delete from cache function
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mendes authored and pprkut committed Oct 2, 2023
1 parent f702e0c commit b5b5927
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Lunr/Corona/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

?>
17 changes: 17 additions & 0 deletions src/Lunr/Corona/Tests/ModelCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]);
}

}

?>

0 comments on commit b5b5927

Please sign in to comment.