Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provide alternate implementations.
* [CacheInterface](#cacheinterface)
* [get()](#get)
* [set()](#set)
* [remove()](#remove)
* [delete()](#delete)
* [ArrayCache](#arraycache)
* [Common usage](#common-usage)
* [Fallback get](#fallback-get)
Expand Down Expand Up @@ -77,15 +77,22 @@ $cache->set('foo', 'bar', 60);
This example eventually sets the value of the key `foo` to `bar`. If it
already exists, it is overridden.

#### remove()
#### delete()

Deletes an item from the cache.

This method will resolve with `true` on success or `false` when an error
occurs. When no item for `$key` is found in the cache, it also resolves
to `true`. If the cache implementation has to go over the network to
delete it, it may take a while.

```php
$cache->remove('foo');
$cache->delete('foo');
```

This example eventually removes the key `foo` from the cache. As with `set`,
this may not happen instantly and a promise is returned to provide guarantees whether
or not the item has been removed from cache.
This example eventually deletes the key `foo` from the cache. As with
`set()`, this may not happen instantly and a promise is returned to
provide guarantees whether or not the item has been removed from cache.

### ArrayCache

Expand Down
2 changes: 1 addition & 1 deletion src/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function set($key, $value, $ttl = null)
return Promise\resolve(true);
}

public function remove($key)
public function delete($key)
{
unset($this->data[$key], $this->expires[$key]);

Expand Down
21 changes: 16 additions & 5 deletions src/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,23 @@ public function get($key, $default = null);
public function set($key, $value, $ttl = null);

/**
* Remove an item from the cache, returns a promise which resolves to true on success or
* false on error. When the $key isn't found in the cache it also
* resolves true.
* Deletes an item from the cache.
*
* This method will resolve with `true` on success or `false` when an error
* occurs. When no item for `$key` is found in the cache, it also resolves
* to `true`. If the cache implementation has to go over the network to
* delete it, it may take a while.
*
* ```php
* $cache->delete('foo');
* ```
*
* This example eventually deletes the key `foo` from the cache. As with
* `set()`, this may not happen instantly and a promise is returned to
* provide guarantees whether or not the item has been removed from cache.
*
* @param string $key
* @return PromiseInterface Returns a promise which resolves to true on success of false on error
* @return PromiseInterface Returns a promise which resolves to `true` on success or `false` on error
*/
public function remove($key);
public function delete($key);
}
8 changes: 4 additions & 4 deletions tests/ArrayCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ public function setShouldSetKey()
}

/** @test */
public function removeShouldRemoveKey()
public function deleteShouldDeleteKey()
{
$this->cache
->set('foo', 'bar');

$removePromise = $this->cache
->remove('foo');
$deletePromise = $this->cache
->delete('foo');

$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($this->identicalTo(true));

$removePromise->then($mock);
$deletePromise->then($mock);

$this->cache
->get('foo')
Expand Down