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.
This commit is contained in:
parent
a0ad85e8e9
commit
a36d51bb1a
2 changed files with 32 additions and 10 deletions
|
@ -148,7 +148,7 @@ class Cache extends Object
|
||||||
/**
|
/**
|
||||||
* Get Key
|
* 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
|
* @param mixed $keys key(s) to retrieve
|
||||||
* @return mixed value(s) of the requested key(s), false if not set
|
* @return mixed value(s) of the requested key(s), false if not set
|
||||||
|
@ -204,16 +204,27 @@ class Cache extends Object
|
||||||
/**
|
/**
|
||||||
* Delete Key
|
* 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
|
* @return boolean status of deleting the key
|
||||||
*/
|
*/
|
||||||
public function delete($key)
|
public function delete($keys)
|
||||||
{
|
{
|
||||||
if ($this->open())
|
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;
|
return false;
|
||||||
|
|
21
jar.php
21
jar.php
|
@ -620,7 +620,7 @@ class Cache extends Object
|
||||||
/**
|
/**
|
||||||
* Get Key
|
* 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
|
* @param mixed $keys key(s) to retrieve
|
||||||
* @return mixed value(s) of the requested key(s), false if not set
|
* @return mixed value(s) of the requested key(s), false if not set
|
||||||
|
@ -676,16 +676,27 @@ class Cache extends Object
|
||||||
/**
|
/**
|
||||||
* Delete Key
|
* 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
|
* @return boolean status of deleting the key
|
||||||
*/
|
*/
|
||||||
public function delete($key)
|
public function delete($keys)
|
||||||
{
|
{
|
||||||
if ($this->open())
|
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;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue