Back to MemcachedStorage class

Method clean

public bool
clean
(mixed $group, mixed $mode = null)
Clean cache for a group given a mode.
Parameters
  • string $group The cache data group
  • string $mode The mode for cleaning cache [group|notgroup]
Returns
  • bool
Since
  • 3.0.0

Method clean - Source code

/**
 * Clean cache for a group given a mode.
 *
 * group mode    : cleans all cache in the group
 * notgroup mode : cleans all cache not in the group
 *
 * @param   string  $group  The cache data group
 * @param   string  $mode   The mode for cleaning cache [group|notgroup]
 *
 * @return  boolean
 *
 * @since   3.0.0
 */
public function clean($group, $mode = null)
{
    if (!$this->lockindex()) {
        return false;
    }
    $index = static::$_db->get($this->_hash . '-index');
    if (\is_array($index)) {
        $prefix = $this->_hash . '-cache-' . $group . '-';
        foreach ($index as $key => $value) {
            if (strpos($value->name, $prefix) === 0 xor $mode !== 'group') {
                static::$_db->delete($value->name);
                unset($index[$key]);
            }
        }
        static::$_db->set($this->_hash . '-index', $index, 0);
    }
    $this->unlockindex();
    return true;
}