Habari\FileCache::_expire PHP Method

_expire() protected method

Expires the named value from the cache.
protected _expire ( string $name, string $group, string $match_mode = 'strict' )
$name string The name of the cached item
$group string The name of the cache group
$match_mode string (optional) how to match bucket names ('strict', 'regex', 'glob') (default 'strict')
    protected function _expire($name, $group, $match_mode = 'strict')
    {
        if (!$this->enabled) {
            return null;
        }
        // prime the variable cache.
        // dirty, dirty hack. we should *never* load all the data in, especially when we only care about the expirey
        // alas, this crappy code requires it
        $this->_get_group($group);
        $keys = array();
        switch (strtolower($match_mode)) {
            case 'glob':
                if (array_key_exists($group, $this->cache_data)) {
                    $keys = preg_grep(Utils::glob_to_regex($name), array_keys($this->cache_data[$group]));
                }
                break;
            case 'regex':
                if (array_key_exists($group, $this->cache_data)) {
                    $keys = preg_grep($name, array_keys($this->cache_data[$group]));
                }
                break;
            case 'strict':
            default:
                $keys = array($name);
                break;
        }
        $ghash = $this->get_group_hash($group);
        foreach ($keys as $key) {
            Plugins::act('cache_expire_before', $name, $group);
            $hash = $this->get_name_hash($key);
            if (isset($this->cache_files[$ghash][$hash]) && file_exists($this->cache_files[$ghash][$hash]['file'])) {
                unlink($this->cache_files[$ghash][$hash]['file']);
                unset($this->cache_files[$ghash][$hash]);
                unset($this->cache_data[$group][$name]);
            }
            Plugins::act('cache_expire_after', $name, $group);
        }
        $this->clear_expired();
        file_put_contents($this->index_file, serialize($this->cache_files));
    }