From a36d51bb1a6876962b32606db134de6edbfbbcec Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Wed, 7 Nov 2012 19:28:44 -0500 Subject: [PATCH] Fixed Cache::delete() when passing an array of keys Since get() allows you to pass an array and get all of the keys back, I assumed delete worked the same way. It does not. --- classes/Cache.php | 21 ++++++++++++++++----- jar.php | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/classes/Cache.php b/classes/Cache.php index 34fc0c2..3a847e8 100644 --- a/classes/Cache.php +++ b/classes/Cache.php @@ -148,7 +148,7 @@ class Cache extends Object /** * Get Key * - * Gets the value of the key and returns it. + * Gets the value of the key(s) and returns it. * * @param mixed $keys key(s) to retrieve * @return mixed value(s) of the requested key(s), false if not set @@ -204,16 +204,27 @@ class Cache extends Object /** * Delete Key * - * Deletes the specified key. + * Deletes the specified key(s). * - * @param string $key key to delete + * @param mixed $keys key(s) to delete * @return boolean status of deleting the key */ - public function delete($key) + public function delete($keys) { if ($this->open()) { - return $this->connection->delete(strtoupper($this->namespace . $key)); + if (!is_array($keys)) + { + $keys = array($keys); + } + + // Memcache() doesn't let you pass an array to delete all records the same way you can with get() + foreach ($keys as $key) + { + $this->connection->delete(strtoupper($this->namespace . $key)); + } + + return true; } return false; diff --git a/jar.php b/jar.php index 3e000bd..3212a4c 100755 --- a/jar.php +++ b/jar.php @@ -620,7 +620,7 @@ class Cache extends Object /** * Get Key * - * Gets the value of the key and returns it. + * Gets the value of the key(s) and returns it. * * @param mixed $keys key(s) to retrieve * @return mixed value(s) of the requested key(s), false if not set @@ -676,16 +676,27 @@ class Cache extends Object /** * Delete Key * - * Deletes the specified key. + * Deletes the specified key(s). * - * @param string $key key to delete + * @param mixed $keys key(s) to delete * @return boolean status of deleting the key */ - public function delete($key) + public function delete($keys) { if ($this->open()) { - return $this->connection->delete(strtoupper($this->namespace . $key)); + if (!is_array($keys)) + { + $keys = array($keys); + } + + // Memcache() doesn't let you pass an array to delete all records the same way you can with get() + foreach ($keys as $key) + { + $this->connection->delete(strtoupper($this->namespace . $key)); + } + + return true; } return false;