public function init() { $this->app->configs->setDefaultConfig($this->id, new TranslatorConfig(), $this); $this->translator = $translator = new Translator(); /** @var TranslatorConfig $config */ $this->moduleConfig = $config = $this->app->configs->getConfig($this->id); if (!$this->app->getConfig()->developmentMode) { $c = new Filesystem(); $o = new FilesystemOptions(); $o->setCacheDir($this->app->cacheStorage->createStorage($this->id)); $c->setOptions($o); $c->addPlugin(new Serializer()); $translator->setCache($c); } $translator->setLocale($config->defaultLanguage); $folder = $this->app->parseUri($config->translationsDirectory); foreach ($config->contexts as $context => $file) { if (is_int($context)) { $context = $file; $file .= '.mo'; } $translator->addTranslationFilePattern('gettext', $folder, '%s/' . $file, $context); } $this->translator = $translator; }
/** * @param array $facets * @param string $treeKey * * @return array */ public function getTree(array $facets = array(), $treeKey = '') { $cacheTreeId = 'simpleTree-' . $treeKey; $cachedTree = $this->objectCache->getItem($cacheTreeId); if (is_array($cachedTree)) { return $cachedTree; } if ($treeKey === '') { return $this->generatePageTree($this->orderAndFilter($facets)); } $tree = $this->generatePageTree($this->orderAndFilter($facets)); $this->objectCache->setItem($cacheTreeId, $tree); return $tree; }
/** * Triggers an option event if this options instance has a connection to * an adapter implements EventsCapableInterface. * * @param string $optionName * @param mixed $optionValue * @return void */ protected function triggerOptionEvent($optionName, $optionValue) { if ($this->adapter instanceof EventsCapableInterface) { $event = new Event('option', $this->adapter, new ArrayObject(array($optionName => $optionValue))); $this->adapter->events()->trigger($event); } }
public function __construct($sm) { $this->sm = $sm; $fileCacheConfig = $sm->get('config')['file-cache-config']; $this->fileOption = $fileOptions = new FilesystemOptions($fileCacheConfig); parent::__construct($fileOptions); }
/** * Update target capabilities * * Returns immediately if no adapter is present. * * @return void */ protected function updateCapabilities() { if (!$this->adapter) { return; } $this->adapter->updateCapabilities(); }
/** * Retorna o frontend para gravar o cache * * @return \Zend\Cache\Storage\Adapter\Filesystem */ public function getCache() { if (!isset($this->_cache)) { $this->_cache = new \Realejo\App\Model\Cache(); } return $this->_cache->getFrontend(get_class($this)); }
/** * Triggers an option.change event * if the this options instance has a connection too an adapter instance * * @param string $optionName * @param mixed $optionValue * @return void */ protected function triggerOptionEvent($optionName, $optionValue) { if (!$this->adapter) { return; } $event = new Event('option', $this->adapter, new ArrayObject(array($optionName => $optionValue))); $this->adapter->events()->trigger($event); }
/** * Flush language cache */ protected function clearLanguageCache() { $this->result->addInfo('Clear language cache'); try { $this->languageCache->flush(); $this->result->addSuccess('Cache cleared'); } catch (\Exception $e) { $this->result->addError('Clearing language cache failed'); $this->result->addError($e->getMessage()); } }
/** * Get current key, value or metadata. * * @return mixed */ public function current() { if ($this->mode == IteratorInterface::CURRENT_AS_SELF) { return $this; } $key = $this->key(); if ($this->mode == IteratorInterface::CURRENT_AS_VALUE) { return $this->storage->getItem($key); } elseif ($this->mode == IteratorInterface::CURRENT_AS_METADATA) { return $this->storage->getMetadata($key); } return $key; }
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); if (!isset($config['cache']['file']['path'])) { throw new \RuntimeException('Unable to initialize file cache service, the `cache.file.path` config is not set.'); } $cachePath = $config['cache']['file']['path']; if (!is_dir($cachePath) || !is_writable($cachePath)) { throw new \RuntimeException('Cache dir is not valid or not writable.'); } if (!is_dir($cachePath)) { mkdir($cachePath); } if (!is_dir($cachePath)) { throw new \RuntimeException(sprintf('Directory `%s` does not exists.', $cachePath)); } if (!is_writable($cachePath)) { throw new \RuntimeException(sprintf('Directory `%s` is not writable.', $cachePath)); } $cache = new Filesystem(); $cache->getOptions()->setCacheDir($cachePath); return $cache; }
/** * Adds the caching mechanism to the dependency injection container with key 'descriptor.cache'. * * @param Application $app * * @return void */ protected function addCache(Application $app) { $app['descriptor.cache'] = $app->share(function () { $cache = new Filesystem(); $cache->setOptions(array('namespace' => 'phpdoc-cache', 'cache_dir' => sys_get_temp_dir())); $plugin = new SerializerPlugin(); if (extension_loaded('igbinary')) { $options = new PluginOptions(); $options->setSerializer('igbinary'); $plugin->setOptions($options); } $cache->addPlugin($plugin); return $cache; }); }
/** * Remove multiple items. * * @param array $keys * @return array Array of not removed keys * @throws Exception\ExceptionInterface * * @triggers removeItems.pre(PreEvent) * @triggers removeItems.post(PostEvent) * @triggers removeItems.exception(ExceptionEvent) */ public function removeItems(array $keys) { $options = $this->getOptions(); if ($options->getWritable() && $options->getClearStatCache()) { clearstatcache(); } return parent::removeItems($keys); }
public function tearDown() { $this->storage->flush(); }
/** * Retorna o frontend para gravar o cache * * @return \Zend\Cache\Storage\Adapter\Filesystem */ public function getCache() { if (!isset($this->_cache)) { $this->_cache = new Cache(); } return $this->_cache->getFrontend(get_class($this)); }
/** * Adds the caching mechanism to the dependency injection container with key 'descriptor.cache'. * * @param Application $app * * @return void */ protected function addCache(Application $app) { $app['descriptor.cache'] = $app->share(function () { $cache = new Filesystem(); $cache->setOptions(array('namespace' => 'phpdoc-cache', 'cache_dir' => sys_get_temp_dir())); $cache->addPlugin(new SerializerPlugin()); return $cache; }); }
/** * @param int $ttl * @return Filesystem */ public static function getAdapter($ttl = 14400) { $cache = new Filesystem(); $cache->getOptions()->setTtl($ttl); return $cache; }