Cache::reset PHP Method

reset() public method

Clear contents of cache backend
public reset ( $suffix = NULL, $lifetime ) : boolean
$suffix string
$lifetime int
return boolean
    function reset($suffix = NULL, $lifetime = 0)
    {
        if (!$this->dsn) {
            return TRUE;
        }
        $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/';
        $parts = explode('=', $this->dsn, 2);
        switch ($parts[0]) {
            case 'apc':
            case 'apcu':
                $info = apc_cache_info('user');
                if (!empty($info['cache_list'])) {
                    $key = array_key_exists('info', $info['cache_list'][0]) ? 'info' : 'key';
                    $mtkey = array_key_exists('mtime', $info['cache_list'][0]) ? 'mtime' : 'modification_time';
                    foreach ($info['cache_list'] as $item) {
                        if (preg_match($regex, $item[$key]) && $item[$mtkey] + $lifetime < time()) {
                            apc_delete($item[$key]);
                        }
                    }
                }
                return TRUE;
            case 'redis':
                $fw = Base::instance();
                $keys = $this->ref->keys($this->prefix . '.*' . $suffix);
                foreach ($keys as $key) {
                    $val = $fw->unserialize($this->ref->get($key));
                    if ($val[1] + $lifetime < time()) {
                        $this->ref->del($key);
                    }
                }
                return TRUE;
            case 'memcache':
                $fw = Base::instance();
                foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) {
                    foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) {
                        foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) {
                            if (is_array($data)) {
                                foreach (array_keys($data) as $key) {
                                    if (preg_match($regex, $key) && ($val = $fw->unserialize(memcache_get($this->ref, $key))) && $val[1] + $lifetime < time()) {
                                        memcache_delete($this->ref, $key);
                                    }
                                }
                            }
                        }
                    }
                }
                return TRUE;
            case 'wincache':
                $info = wincache_ucache_info();
                foreach ($info['ucache_entries'] as $item) {
                    if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) {
                        wincache_ucache_delete($item['key_name']);
                    }
                }
                return TRUE;
            case 'xcache':
                xcache_unset_by_prefix($this->prefix . '.');
                return TRUE;
            case 'folder':
                if ($glob = @glob($parts[1] . '*')) {
                    foreach ($glob as $file) {
                        if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) {
                            @unlink($file);
                        }
                    }
                }
                return TRUE;
        }
        return FALSE;
    }

Usage Example

コード例 #1
0
 public function execute()
 {
     if (Session::get_state() != Session::ST_LIFE) {
         self::set_client_command('refresh', array('url' => 'self'));
         self::set_result(FALSE);
         return;
     }
     if (strlen($this->message) > 65000) {
         throw new Command_exception('text length error', get_string('errors', 'text_length_error'));
     }
     $captcha_lib = Loader::get_library('captcha');
     if (!$captcha_lib->check($this->captcha)) {
         throw new Command_exception('captcha error', get_string('errors', 'captcha_error'));
     }
     require_once BASEPATH . 'global/cache.php';
     $query = array();
     $query['%text'] = Security::sanitize_text($this->message);
     $query['%name'] = Security::sanitize_text($this->name);
     $query['%email'] = Security::sanitize_text($this->email);
     $query['%quote_id'] = intval($this->quote_id);
     $query['%page'] = Cache::generate_key(TRUE);
     $query['%avatar'] = abs(crc32($this->email)) % self::AVATAR_COUNT;
     foreach ($query as $key => $value) {
         if (!in_array($key, array('%quote_id', '%avatar')) and empty($value)) {
             throw new Command_exception('empty text error', get_string('errors', 'empty_field'));
         }
     }
     db::simple_query(self::Q_SET_COMMENT, $query, TRUE);
     Cache::reset($query['%page']);
     self::set_client_command('refresh', array('url' => 'self'));
 }
All Usage Examples Of Cache::reset