/** * Initialization that sets a base key and the driver based on configuration settings * * @param Grav $grav * @return void */ public function init(Grav $grav) { /** @var Config $config */ $this->config = $grav['config']; /** @var Uri $uri */ $uri = $grav['uri']; $prefix = $this->config->get('system.cache.prefix'); $this->enabled = (bool) $this->config->get('system.cache.enabled'); // Cache key allows us to invalidate all cache on configuration changes. $this->key = substr(md5(($prefix ? $prefix : 'g') . $uri->rootUrl(true) . $this->config->key . GRAV_VERSION), 2, 8); $this->driver = $this->getCacheDriver(); // Set the cache namespace to our unique key $this->driver->setNamespace($this->key); }
public function flush() { foreach ($this->objects as $className => $objects) { $this->cache->setNamespace($className); $this->cache->saveMultiple($objects); } }
/** * Initialization that sets a base key and the driver based on configuration settings * * @param Grav $grav * @return void */ public function init(Grav $grav) { /** @var Config $config */ $this->config = $grav['config']; $this->now = time(); $this->cache_dir = $grav['locator']->findResource('cache://doctrine', true, true); /** @var Uri $uri */ $uri = $grav['uri']; $prefix = $this->config->get('system.cache.prefix'); $this->enabled = (bool) $this->config->get('system.cache.enabled'); // Cache key allows us to invalidate all cache on configuration changes. $this->key = ($prefix ? $prefix : 'g') . '-' . substr(md5($uri->rootUrl(true) . $this->config->key() . GRAV_VERSION), 2, 8); $this->driver = $this->getCacheDriver(); // Set the cache namespace to our unique key $this->driver->setNamespace($this->key); }
/** * Changes the credentials used to authenticate with QBank. * * Changing the credentials will effectively switch the user using QBank and is useful when implementing some tiered * service. * * @param string $user Username of the new user. * @param string $password Password of the new user. * * @return void */ public function updateCredentials($user, $password) { $oldUser = $this->credentials->getUsername(); $this->credentials = new Credentials($this->credentials->getClientId(), $user, $password); unset($password); if ($this->client instanceof Client) { $this->client->getEmitter()->detach($this->oauth2Subscriber); $this->oauth2Subscriber = null; $this->client->getEmitter()->attach($this->getOAuth2Subscriber()); } if ($this->cache instanceof CacheProvider) { $this->cache->setNamespace(md5($this->basepath . $this->credentials->getUsername() . $this->credentials->getPassword())); } $this->logger->notice('Updated user!', ['old' => $oldUser, 'new' => $user]); }
/** * set namespace to prevent cache naming collision. * * @param string $cache_namespace * @return type */ public function setNamespace($cache_namespace) { return $this->CacheDriver->setNamespace($cache_namespace); }
/** * @param array $criteria * * @return object[] */ public function findOneBy(array $criteria) { $this->cache->setNamespace($this->className); $id = $this->getId($criteria); return $this->cache->fetch($id); }