lithium\storage\Cache::delete PHP Method

delete() public static method

Can handle single- and multi-key deletes.
public static delete ( string $name, mixed $key, array $options = [] ) : boolean
$name string The cache configuration to delete from.
$key mixed Key to be deleted or an array of keys to delete.
$options array Options for the method and strategies. - `'conditions'` _mixed_: A function or item that must return or evaluate to `true` in order to continue write operation.
return boolean `true` on successful cache delete, `false` otherwise. When deleting multiple items and an error occurs deleting any of the items the whole operation fails and this method will return `false`.
    public static function delete($name, $key, array $options = array())
    {
        $options += array('conditions' => null, 'strategies' => true);
        if (is_callable($options['conditions']) && !$options['conditions']()) {
            return false;
        }
        try {
            $adapter = static::adapter($name);
        } catch (ConfigException $e) {
            return false;
        }
        $key = static::key($key);
        if (is_array($key)) {
            $keys = $key;
        } else {
            $keys = array($key);
        }
        $params = compact('keys');
        return static::_filter(__FUNCTION__, $params, function ($self, $params) use($adapter) {
            return $adapter->delete($params['keys']);
        });
    }

Usage Example

 public function testDelete()
 {
     Cache::write($this->cachedName, 'foo', 'bar');
     Cache::write($this->cachedName, 'foobar', 'baz');
     $result = Cache::read($this->cachedName, 'foo');
     $this->assertEqual('bar', $result);
     $result = Cache::read($this->cachedName, 'foobar');
     $this->assertEqual('baz', $result);
     Cache::delete($this->cachedName, 'foobar');
     $result = Cache::read($this->cachedName, 'foo');
     $this->assertEqual('bar', $result);
     $result = Cache::read($this->cachedName, 'foobar');
     $this->assertEqual(null, $result);
 }
All Usage Examples Of lithium\storage\Cache::delete