/** * Initializes this component by ensuring the existence of the cache path. */ public function init() { parent::init(); $this->cachePath = Leaps::getAlias($this->cachePath); if (!is_dir($this->cachePath)) { FileHelper::createDirectory($this->cachePath, $this->dirMode, true); } }
/** * Initializes the FragmentCache object. */ public function init() { parent::init(); $this->cache = $this->enabled ? Instance::ensure($this->cache, Cache::className()) : null; if ($this->cache instanceof Cache && $this->getCachedContent() === false) { $this->getView()->cacheStack[] = $this; ob_start(); ob_implicit_flush(false); } }
/** * Checks if given class is a Cache class. * @param string $className class name. * @return boolean */ private function isCacheClass($className) { return is_subclass_of($className, Cache::className()); }
/** * Initializes the DbMessageSource component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * Configured [[cache]] component would also be initialized. * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); if ($this->enableCaching) { $this->cache = Instance::ensure($this->cache, Cache::className()); } }
/** * Initializes the DbCache component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); }
/** * Initializes the application component. */ public function init() { parent::init(); $this->cache = Instance::ensure($this->cache, Cache::className()); }
/** * Stores multiple key-value pairs in cache. * @param array $data array where key corresponds to cache key while value is the value stored * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire. * @return array array of failed keys. Always empty in case of using memcached. */ protected function setValues($data, $duration) { if ($this->useMemcached) { $this->_cache->setMulti($data, $duration > 0 ? $duration + time() : 0); return []; } else { return parent::setValues($data, $duration); } }
/** * This method is invoked right before an action is to be executed (after all possible filters.) * You may override this method to do last-minute preparation for the action. * @param Action $action the action to be executed. * @return boolean whether the action should continue to be executed. */ public function beforeAction($action) { if (!$this->enabled) { return true; } $this->cache = Instance::ensure($this->cache, Cache::className()); if (is_array($this->dependency)) { $this->dependency = Leaps::createObject($this->dependency); } $properties = []; foreach (['cache', 'duration', 'dependency', 'variations'] as $name) { $properties[$name] = $this->{$name}; } $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__; $response = Leaps::$app->getResponse(); ob_start(); ob_implicit_flush(false); if ($this->view->beginCache($id, $properties)) { $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']); return true; } else { $data = $this->cache->get($this->calculateCacheKey()); if (is_array($data)) { $this->restoreResponse($response, $data); } $response->content = ob_get_clean(); return false; } }