From 9dad4b353fd03324df31bc190a3da738cd95e9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 8 Jun 2018 14:02:47 +0200 Subject: [PATCH] Rename remove() to delete() for consistency with PSR-16 --- README.md | 19 +++++++++++++------ src/ArrayCache.php | 2 +- src/CacheInterface.php | 21 ++++++++++++++++----- tests/ArrayCacheTest.php | 8 ++++---- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 81808ab..13bf887 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/src/ArrayCache.php b/src/ArrayCache.php index 8512a1f..314814a 100644 --- a/src/ArrayCache.php +++ b/src/ArrayCache.php @@ -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]); diff --git a/src/CacheInterface.php b/src/CacheInterface.php index da46cae..f31a68e 100644 --- a/src/CacheInterface.php +++ b/src/CacheInterface.php @@ -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); } diff --git a/tests/ArrayCacheTest.php b/tests/ArrayCacheTest.php index a5a23df..3336012 100644 --- a/tests/ArrayCacheTest.php +++ b/tests/ArrayCacheTest.php @@ -59,13 +59,13 @@ 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 @@ -73,7 +73,7 @@ public function removeShouldRemoveKey() ->method('__invoke') ->with($this->identicalTo(true)); - $removePromise->then($mock); + $deletePromise->then($mock); $this->cache ->get('foo')