delete() public static méthode

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.
Résultat 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 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);
 }
 public function testCacheWriteAndDeleteWithConditions()
 {
     $config = array('default' => array('adapter' => 'Memory', 'filters' => array()));
     Cache::config($config);
     $result = Cache::config();
     $expected = $config;
     $this->assertEqual($expected, $result);
     $anonymous = function () use(&$config) {
         return isset($config['default']);
     };
     $result = Cache::delete('non_existing', 'key_value', $anonymous);
     $this->assertFalse($result);
     $result = Cache::write('default', 'to delete', 'dead data', '+1 minute');
     $this->assertTrue($result);
     $result = Cache::delete('default', 'to delete', function () {
         return false;
     });
     $this->assertFalse($result);
     $result = Cache::delete('default', 'to delete', $anonymous);
     $this->assertTrue($result);
 }
Exemple #3
0
 public static function cache_delete($key, $cache_name = 'default')
 {
     $key = self::_get_cache_name($key);
     return Cache::delete($cache_name, $key);
 }
Exemple #4
0
 /**
  * Rebuild asset cache file
  * @param  string $filename The name of the file to cache or test caching on
  * @param  string $content  File contents to be cached
  * @param  array  $options  Options to handle cache length, location, so on.
  */
 private function setCache($filename, $content, $options = array())
 {
     // Create css cache dir if it doesnt exist.
     if (!is_dir($cache_location = CACHE_DIR . "/{$options['location']}")) {
         mkdir($cache_location, 0755, true);
     }
     $defaults = array('length' => '+1 year', 'location' => 'templates');
     $options += $defaults;
     $name_sections = explode('_', $filename);
     $like_files = $name_sections[0];
     // loop thru cache and delete old cache file
     if (!$this->_production && ($handle = opendir($cache_location))) {
         while (false !== ($oldfile = readdir($handle))) {
             if (preg_match("/^{$like_files}/", $oldfile)) {
                 Cache::delete('default', "{$options['location']}/{$oldfile}");
             }
         }
         closedir($handle);
     }
     Cache::write('default', "{$options['location']}/{$filename}", $content, $options['length']);
 }