@param bool $expired

@return void
Exits.
348212
protected function cmdClear($expired = false) /*: void*/
    {
        /**
         * @see simplecomplex_cache_cli()
         */
        $container = Dependency::container();
        // Validate input. ---------------------------------------------
        $store = '';
        $all_stores = !empty($this->command->options['all']);
        if (empty($this->command->arguments['store'])) {
            if (!$all_stores) {
                $this->command->inputErrors[] = !isset($this->command->arguments['store']) ?
                    'Missing \'store\' argument, and option \'all\' not set.' :
                    'Empty \'store\' argument, and option \'all\' not set.';
            }
        } else {
            $store = $this->command->arguments['store'];
            if (!CacheKey::validate($store)) {
                $this->command->inputErrors[] = 'Invalid \'store\' argument.';
            }
            if ($all_stores) {
                $this->command->inputErrors[] = 'Ambiguous input, saw argument \'store\' plus options \'all\'.';
            }
        }
        if ($this->command->inputErrors) {
            foreach ($this->command->inputErrors as $msg) {
                $this->environment->echoMessage(
                    $this->environment->format($msg, 'hangingIndent'),
                    'notice'
                );
            }
            // This command's help text.
            $this->environment->echoMessage("\n" . $this->command);
            exit;
        }
        // Display command and the arg values used.---------------------
        if (!$this->command->preConfirmed) {
            $this->environment->echoMessage(
                $this->environment->format(
                    $this->environment->format($this->command->name, 'emphasize')
                    . "\n" . (!$all_stores ? ('store: ' . $store) : 'all stores'),
                    'hangingIndent'
                )
            );
        }
        // Check if the command is doable.------------------------------
        // Does that/these store(s) exist?
        if ($container->has('cache-broker')) {
            /** @var CacheBroker $cache_broker */
            $cache_broker_class = get_class($container->get('cache-broker'));
        } else {
            $cache_broker_class = static::CLASS_CACHE_BROKER;
        }
        $cache_class = constant($cache_broker_class . '::CACHE_CLASSES')[CacheBroker::CACHE_BASE];
        if (!method_exists($cache_class, 'listInstances')) {
            $this->environment->echoMessage('Cannot retrieve list of cache store instances via class['
                . $cache_class . '], has no static method listInstances().', 'error');
            exit;
        }
        $stores = forward_static_call($cache_class . '::listInstances');
        // Single store.
        if (!$all_stores) {
            $cache_store = null;
            foreach ($stores as $instance) {
                if ($instance->name == $store) {
                    /** @var ManageableCacheInterface $cache_store */
                    $cache_store = $instance;
                    break;
                }
            }
            if (!$cache_store) {
                $this->environment->echoMessage('That cache store doesn\'t exist, store[' . $store . '].', 'warning');
                exit;
            }
            // Request confirmation, unless user used the --yes/-y option.
            if (
                !$this->command->preConfirmed
                && !$this->environment->confirm(
                    'Delete all' . (!$expired ? '' : ' expired')
                    . ' items of a single cache store? Type \'yes\' or \'y\' to continue:',
                    ['yes', 'y'],
                    '',
                    'Aborted deleting all' . (!$expired ? '' : ' expired') . ' items of a single cache store.'
                )
            ) {
                exit;
            }
            // Do it.
            $success = !$expired ? $cache_store->clear() : $cache_store->clearExpired();
            if ($success === false) {
                $this->environment->echoMessage(
                    'Failed to delete all' . (!$expired ? '' : ' expired') . ' items of cache store[' . $store . '].',
                    'error'
                );
            } elseif (!$this->command->silent) {
                if ($success === true) {
                    $this->environment->echoMessage(
                        'Deleted all' . (!$expired ? '' : ' expired') . ' items of cache store[' . $store . '].',
                        'success'
                    );
                }
                else {
                    $this->environment->echoMessage(
                        'Deleted ' . (!$expired ? 'all' : $success) . (!$expired ? '' : ' expired')
                        . ' items of cache store[' . $store . '].',
                        'success'
                    );
                }
            }
            exit;
        } else {
            // Request confirmation, unless user used the --yes/-y option.
            if (
                !$this->command->preConfirmed
                && !$this->environment->confirm(
                    'Delete all' . (!$expired ? '' : ' expired')
                    . ' items of all cache stores? Type \'yes\' or \'y\' to continue:',
                    ['yes', 'y'],
                    '',
                    'Aborted deleting all' . (!$expired ? '' : ' expired') . ' items of all cache stores.'
                )
            ) {
                exit;
            }
            // Do it.
            $n_stores = $errors = 0;
            foreach ($stores as $instance) {
                ++$n_stores;
                /** @var ManageableCacheInterface $cache_store */
                $cache_store = $instance;
                $success = $cache_store->clearExpired();
                if ($success === false) {
                    ++$errors;
                    $this->environment->echoMessage(
                        'Failed to delete all' . (!$expired ? '' : ' expired') . ' items of cache store['
                        . $instance->name . '].',
                        'error'
                    );
                } elseif (!$this->command->silent) {
                    if ($success === true) {
                        $this->environment->echoMessage(
                            'Deleted all' . (!$expired ? '' : ' expired') . ' items of cache store['
                            . $instance->name . '].',
                            'notice'
                        );
                    }
                    else {
                        $this->environment->echoMessage(
                            'Deleted ' . (!$expired ? 'all' : $success) . (!$expired ? '' : ' expired')
                            . ' items of cache store[' . $instance->name . '].',
                            'notice'
                        );
                    }
                }
            }
            if ($errors) {
                $this->environment->echoMessage(
                    'Deleted all' . (!$expired ? '' : ' expired') . ' items of ' . $n_stores
                    . ' cache stores, encountering ' . $errors . ' errors.',
                    'warning'
                );
            } elseif (!$this->command->silent) {
                $this->environment->echoMessage(
                    'Deleted all' . (!$expired ? '' : ' expired') . ' items of ' . $n_stores . ' cache stores.',
                    'success'
                );
            }
        }
        exit;
    }
23944
public function setExpires($expires)
    {
        if (empty($expires)) {
            return $this;
        }

        $this->expires = strtotime($expires);

        return $this;
    }
141247
private function setExpiration($expires_in)
    {
        $this->expiresAtTimestamp = time() + $expires_in;
        $this->expiresAt = date('Y-m-d H:i:s', time() + $expires_in);
    }
315246
public function set($key,$value,$expired){
		if(DEBUG_MODE){
			BDebug::message('[Memcached]: Set key('.$key.')');
			}
		$mc=$this->getMemcached();
		if(empty($mc))return false;
		$this->queries_set_count++;
		return $mc->set($key,$value,$expired);
		}
1207874
public function flush(bool $final = false): void
    {
        $messages = $this->messages;
        // https://github.com/yiisoft/yii2/issues/5619
        // new messages could be logged while the existing ones are being handled by targets
        $this->messages = [];

        $this->dispatch($messages, $final);
    }
262405
public function sync($data = false)
    {
        if ($this->_exists !== null) {
            return;
        }
        $id = $this->id();
        if ($id !== null) {
            $persisted = static::load($id);
            if ($persisted && $data) {
                $this->amend($persisted->data(), ['exists' => true]);
            } else {
                $this->_exists = !!$persisted;
            }
        } else {
            $this->_exists = false;
        }
    }
990080
public function is_any_expired() : bool {
        if ($this->is_fully_expired()) {
            return true;
        }

        if (!empty($this->get_expired_roles())) {
            return true;
        }

        if ($this->is_default_expired()) {
            return true;
        }

        return false;
    }
700818
public function endIf(bool $condition, ?callable $callback = null): void
    {
        if ((bool) $condition) {
            $this->end($callback);
        }
    }
885866
protected function setCache($cachename,$value,$expired=0){
        $file = $this->cachedir . $cachename . '.cache';
        $data = array(
                'value' => $value,
                'expired' => $expired ? time() + $expired : 0
        );
        return file_put_contents( $file, serialize($data) ) ? true : false;
    }
1332668
public function deleteAllExpired()
    {
        $expiredBlacklistedTokens = $this->findAllExpired();

        foreach ($expiredBlacklistedTokens as $expiredBlacklistedToken)
        {
            $this->delete($expiredBlacklistedToken['id']);
        }
    }
497016
protected function onAfterWrite() {
        parent::onAfterWrite();
        
        
        //Clean up the expired tokens
        $expiredTokens=KapostPreviewToken::get()->filter('Created:LessThan', date('Y-m-d H:i:s', strtotime('-'.KapostService::config()->preview_token_expiry.' minutes')));
        if($expiredTokens->count()>0) {
            foreach($expiredTokens as $token) {
                $token->delete();
            }
        }
    }
257416
public function endUnless(bool $condition, ?callable $callback = null): void
    {
        $this->endIf(! $condition, $callback);
    }
266768
public function setExpiredAtAttribute($value): void
    {
        if (!is_null($value) && !$value instanceof Carbon) {
            $value = Carbon::parse($value);
        }

        $this->attributes['expired_at'] = $value;
    }
183241
protected function setCache($cachename,$value,$expired){
        Cache::put($cachename,$value,$expired/60);
        return false;
    }
353417
public function flush(bool $nl = false, $quit = false, array $opts = []): void
    {
        Console::flushBuffer($nl, $quit, $opts);
    }
702817
public function expired($onSessionExpires = false)
    {
        if (!$this->_data['expires'] && $onSessionExpires) {
            return true;
        }

        return $this->_data['expires'] < time() && $this->_data['expires'];
    }
667477
public function set($key,$value,$expired){
		$mc=$this->getMemcache();
		if(empty($mc))return false;
		$this->queries_set_count++;
		return $mc->set($key,$value,false,$expired);
		}