Sets the namespace to prefix all cache ids with.
public setNamespace ( string $namespace ) : void | ||
$namespace | string | |
return | void |
private function init($namespace) { $prefix = self::$namespacePrefix; $namespace = "{$prefix}:{$namespace}"; $type = 0; if (static::$TYPE_PREFER_DEFAULT == 0) { if (isset(static::$_TYPE)) { $type = static::$_TYPE; } else { $type = static::$TYPE_DEFAULT; } } else { $type = static::$TYPE_PREFER_DEFAULT; } if ($type == static::$TYPE_APC) { $this->_cacheImplement = new ApcCache(); } else { if ($type == static::$TYPE_MEMCACHE) { $m = new MemcacheCache(); $memcache = new \Memcache(); $memcache->connect('localhost', 11211); $m->setMemcache($memcache); $this->_cacheImplement = $m; } else { if ($type == static::$TYPE_XCACHE) { $this->_cacheImplement = new XcacheCache(); } else { $this->_cacheImplement = new ArrayCache(); } } } $this->_cacheImplement->setNamespace($namespace); }
/** * @param string $name * @param \Doctrine\Common\Cache\CacheProvider $cache * @param integer $lifetime */ public function __construct($name, CacheProvider $cache, $lifetime = 0) { $this->cache = $cache; $this->name = (string) $name; $this->lifetime = (int) $lifetime; $this->cache->setNamespace($this->name); }
/** * Constructor * * @param CacheProvider $cache */ public function __construct(CacheProvider $cache = null) { $this->cache = $cache; if ($this->cache !== null && $this->cache->getNamespace() === '') { $this->cache->setNamespace(self::CACHE_NAMESPACE); } }
/** * @param ConfigProvider $securityConfigProvider * @param ConfigProvider $entityConfigProvider * @param CacheProvider|null $cache */ public function __construct(ConfigProvider $securityConfigProvider, ConfigProvider $entityConfigProvider, CacheProvider $cache = null) { $this->securityConfigProvider = $securityConfigProvider; $this->entityConfigProvider = $entityConfigProvider; $this->cache = $cache; if ($this->cache !== null && $this->cache->getNamespace() === '') { $this->cache->setNamespace(self::CACHE_NAMESPACE); } }
/** * Constructor * * @param array $owningEntityNames * @param ConfigProvider $configProvider * @param EntityClassResolver $entityClassResolver * @param CacheProvider|null $cache * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __construct(array $owningEntityNames, ConfigProvider $configProvider, EntityClassResolver $entityClassResolver = null, CacheProvider $cache = null) { $this->organizationClass = $entityClassResolver === null ? $owningEntityNames['organization'] : $entityClassResolver->getEntityClass($owningEntityNames['organization']); $this->businessUnitClass = $entityClassResolver === null ? $owningEntityNames['business_unit'] : $entityClassResolver->getEntityClass($owningEntityNames['business_unit']); $this->userClass = $entityClassResolver === null ? $owningEntityNames['user'] : $entityClassResolver->getEntityClass($owningEntityNames['user']); $this->configProvider = $configProvider; $this->cache = $cache; if ($this->cache !== null && $this->cache->getNamespace() === '') { $this->cache->setNamespace(self::CACHE_NAMESPACE); } $this->noOwnershipMetadata = new OwnershipMetadata(); }
/** * @param string $type * @param string $namespace * * @throws \InvalidArgumentException * @internal param string $storeId */ public function __construct($type = CacheTypes::ARRAY_CACHE, $namespace = null) { if (!CacheTypes::contains($type)) { throw new \InvalidArgumentException('The $type "' . $type . '" is not valid.'); } $_class = static::STORE_NAMESPACE . $type . 'Cache'; $_mirror = new \ReflectionClass($_class); $this->_store = $_mirror->getConstructor() ? $_mirror->newInstanceArgs($this->_getCacheTypeArguments($type)) : $_mirror->newInstance(); if (null !== $namespace) { $this->_store->setNamespace($namespace); } $this->_initializeCache($type); }
/** * Constructor * * $injector function () {return Injector::create([new Module])}; * $initialization function ($instance, InjectorInterface $injector) {}; * * @param callable $injector * @param callable $initialization * @param string $cacheNamespace * @param CacheProvider $cache * @param ClassLoaderInterface $classLoader */ public function __construct(callable $injector, callable $initialization, $cacheNamespace, CacheProvider $cache, ClassLoaderInterface $classLoader = null) { $this->injector = $injector; $this->initialization = $initialization; $this->cacheNamespace = $cacheNamespace; $this->cache = $cache; $cache->setNamespace($cacheNamespace); $this->cache = $cache; $this->classLoader = $classLoader ?: new AopClassLoader(); }
/** * 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_setting = $this->config->get('system.cache.driver'); $this->driver = $this->getCacheDriver(); // Set the cache namespace to our unique key $this->driver->setNamespace($this->key); // Dump Cache state $grav['debugger']->addMessage('Cache: [' . ($this->enabled ? 'true' : 'false') . '] Setting: [' . $this->driver_setting . '] Driver: [' . $this->driver_name . ']'); }
/** * Initializes the application instance. * * This method * starts the session, * call Slim constructor, * set the custom log writer (if is defined in config), * bootstraps the Doctrine, * bootstraps the Auth Manager, * creates the cache and rcache components, * sets the file storage, * adds midlewares, * instantiates the Route Manager and * includes the theme.php file of the active theme if the file exists. * * * If the application was previously initiated, this method returns the application in the first line. * * @return \MapasCulturais\App */ public function init($config = []) { if ($this->_initiated) { return $this; } $this->_initiated = true; if ($config['slim.debug']) { error_reporting(E_ALL ^ E_STRICT); } session_start(); if ($config['app.offline']) { $bypass_callable = $config['app.offlineBypassFunction']; if (!is_callable($bypass_callable) || !$bypass_callable()) { http_response_code(307); header('Location: ' . $config['app.offlineUrl']); } } // =============== CACHE =============== // if (key_exists('app.cache', $config) && is_object($config['app.cache']) && is_subclass_of($config['app.cache'], '\\Doctrine\\Common\\Cache\\CacheProvider')) { $this->_cache = $config['app.cache']; } else { $this->_cache = new \Doctrine\Common\Cache\ArrayCache(); } $this->_cache->setNamespace($config['app.cache.namespace']); spl_autoload_register(function ($class) use($config) { $cache_id = "AUTOLOAD_CLASS:{$class}"; if ($config['app.useRegisteredAutoloadCache'] && $this->cache->contains($cache_id)) { $path = $this->cache->fetch($cache_id); require_once $path; return true; } foreach ($config['namespaces'] as $namespace => $base_dir) { if (strpos($class, $namespace) === 0) { $path = str_replace('\\', '/', str_replace($namespace, $base_dir, $class) . '.php'); if (\file_exists($path)) { require_once $path; if ($config['app.useRegisteredAutoloadCache']) { $this->cache->save($cache_id, $path, $config['app.registeredAutoloadCache.lifetime']); } return true; } } } }); $config['app.mode'] = key_exists('app.mode', $config) ? $config['app.mode'] : 'production'; $this->_config = $config; $this->_config['path.layouts'] = APPLICATION_PATH . 'themes/active/layouts/'; $this->_config['path.templates'] = APPLICATION_PATH . 'themes/active/views/'; $this->_config['path.metadata_inputs'] = APPLICATION_PATH . 'themes/active/metadata-inputs/'; if (!key_exists('app.sanitize_filename_function', $this->_config)) { $this->_config['app.sanitize_filename_function'] = null; } $theme_class = $config['themes.active'] . '\\Theme'; parent::__construct(['log.level' => $config['slim.log.level'], 'log.enabled' => $config['slim.log.enabled'], 'debug' => $config['slim.debug'], 'templates.path' => $this->_config['path.templates'], 'view' => new $theme_class($config['themes.assetManager']), 'mode' => $this->_config['app.mode']]); $config = $this->_config; // custom log writer if (isset($config['slim.log.writer']) && is_object($config['slim.log.writer']) && method_exists($config['slim.log.writer'], 'write')) { $log = $this->getLog(); $log->setWriter($config['slim.log.writer']); } // creates runtime cache component $this->_rcache = new \Doctrine\Common\Cache\ArrayCache(); // ===================================== // // ========== BOOTSTRAPING DOCTRINE ========== // // annotation driver $doctrine_config = Setup::createConfiguration($config['doctrine.isDev']); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); $driver = new AnnotationDriver(new AnnotationReader()); $driver->addPaths([__DIR__ . '/Entities/']); // tells the doctrine to ignore hook annotation. AnnotationReader::addGlobalIgnoredName('hook'); // driver must be pdo_pgsql $config['doctrine.database']['driver'] = 'pdo_pgsql'; // registering noop annotation autoloader - allow all annotations by default AnnotationRegistry::registerLoader('class_exists'); $doctrine_config->setMetadataDriverImpl($driver); $proxy_dir = APPLICATION_PATH . 'lib/MapasCulturais/DoctrineProxies'; $proxy_namespace = 'MapasCulturais\\DoctrineProxies'; $doctrine_config->setProxyDir($proxy_dir); $doctrine_config->setProxyNamespace($proxy_namespace); \Doctrine\ORM\Proxy\Autoloader::register($proxy_dir, $proxy_namespace); /** DOCTRINE2 SPATIAL */ $doctrine_config->addCustomStringFunction('st_asbinary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsBinary'); $doctrine_config->addCustomStringFunction('st_astext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STAsText'); $doctrine_config->addCustomNumericFunction('st_area', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STArea'); $doctrine_config->addCustomStringFunction('st_centroid', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCentroid'); $doctrine_config->addCustomStringFunction('st_closestpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STClosestPoint'); $doctrine_config->addCustomNumericFunction('st_contains', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContains'); $doctrine_config->addCustomNumericFunction('st_containsproperly', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STContainsProperly'); $doctrine_config->addCustomNumericFunction('st_covers', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCovers'); $doctrine_config->addCustomNumericFunction('st_coveredby', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCoveredBy'); $doctrine_config->addCustomNumericFunction('st_crosses', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STCrosses'); $doctrine_config->addCustomNumericFunction('st_disjoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDisjoint'); $doctrine_config->addCustomNumericFunction('st_distance', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STDistance'); $doctrine_config->addCustomStringFunction('st_envelope', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STEnvelope'); $doctrine_config->addCustomStringFunction('st_geomfromtext', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STGeomFromText'); $doctrine_config->addCustomNumericFunction('st_length', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLength'); $doctrine_config->addCustomNumericFunction('st_linecrossingdirection', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STLineCrossingDirection'); $doctrine_config->addCustomStringFunction('st_startpoint', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STStartPoint'); $doctrine_config->addCustomStringFunction('st_summary', 'CrEOF\\Spatial\\ORM\\Query\\AST\\Functions\\PostgreSql\\STSummary'); $doctrine_config->addCustomStringFunction('string_agg', 'MapasCulturais\\DoctrineMappings\\Functions\\StringAgg'); $doctrine_config->addCustomStringFunction('unaccent', 'MapasCulturais\\DoctrineMappings\\Functions\\Unaccent'); $doctrine_config->addCustomStringFunction('recurring_event_occurrence_for', 'MapasCulturais\\DoctrineMappings\\Functions\\RecurringEventOcurrenceFor'); $doctrine_config->addCustomNumericFunction('st_dwithin', 'MapasCulturais\\DoctrineMappings\\Functions\\STDWithin'); $doctrine_config->addCustomNumericFunction('st_makepoint', 'MapasCulturais\\DoctrineMappings\\Functions\\STMakePoint'); $doctrine_config->setMetadataCacheImpl($this->_cache); $doctrine_config->setQueryCacheImpl($this->_cache); $doctrine_config->setResultCacheImpl($this->_cache); // obtaining the entity manager $this->_em = EntityManager::create($config['doctrine.database'], $doctrine_config); \MapasCulturais\DoctrineMappings\Types\Frequency::register(); \MapasCulturais\DoctrineMappings\Types\Point::register(); \MapasCulturais\DoctrineMappings\Types\Geography::register(); \MapasCulturais\DoctrineMappings\Types\Geometry::register(); if (@$config['app.log.query']) { $doctrine_config->setSQLLogger($config['app.queryLogger']); } $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point'); $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geography', 'geography'); $this->_em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('geometry', 'geometry'); // ============= STORAGE =============== // if (key_exists('storage.driver', $config) && class_exists($config['storage.driver']) && is_subclass_of($config['storage.driver'], '\\MapasCulturais\\Storage')) { $storage_class = $config['storage.driver']; $this->_storage = key_exists('storage.config', $config) ? $storage_class::i($config['storage.config']) : $storage_class::i(); } else { $this->_storage = \MapasCulturais\Storage\FileSystem::i(); } // ===================================== // // add middlewares if (is_array($config['slim.middlewares'])) { foreach ($config['slim.middlewares'] as $middleware) { $this->add($middleware); } } // instantiate the route manager $this->_routesManager = new RoutesManager(key_exists('routes', $config) ? $config['routes'] : []); $this->applyHookBoundTo($this, 'mapasculturais.init'); $this->register(); // =============== AUTH ============== // $auth_class_name = strpos($config['auth.provider'], '\\') !== false ? $config['auth.provider'] : 'MapasCulturais\\AuthProviders\\' . $config['auth.provider']; $this->_auth = new $auth_class_name($config['auth.config']); $this->_auth->setCookies(); // initialize theme $this->view->init(); // ===================================== // // run plugins foreach ($config['plugins.enabled'] as $plugin) { include PLUGINS_PATH . $plugin . '.php'; } // ===================================== // if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) { $this->_dbUpdates(); } return $this; }
/** * @param CacheProvider $cache * @param PermissionGrantingStrategyInterface $permissionGrantingStrategy * @param string $prefix */ public function __construct(CacheProvider $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, $prefix = DoctrineAclCache::PREFIX) { $this->cache = $cache; $this->cache->setNamespace($prefix); parent::__construct($this->cache, $permissionGrantingStrategy, $prefix); }
public function __construct(CacheProvider $provider, $namespace = '', $defaultLifetime = 0) { parent::__construct('', $defaultLifetime); $this->provider = $provider; $provider->setNamespace($namespace); }
/** * {@inheritdoc} */ public function setNamespace($namespace) { $this->provider->setNamespace($namespace); }
/** * @param CacheProvider $cache * @return Configuration */ public function setCache(CacheProvider $cache) { // Set namespace for doctrine cache provider to avoid collisions $namespace = !is_null($this->cacheNamespace) ? $this->cacheNamespace : md5($this->getProxyDir() . \Shopware::REVISION); $cache->setNamespace("dc2_" . $namespace . "_"); $this->setMetadataCacheImpl($cache); $this->setQueryCacheImpl($cache); $this->setResultCacheImpl($cache); return $this; }
function __construct(CacheProvider $cacheProvider) { $this->cacheProvider = $cacheProvider; $this->cacheProvider->setNamespace('KayueEssenceBundle'); }
/** * @inheritDoc * * @param CacheProvider $cache doctrine cache provider * @param string $cacheNamespace cache namespace * @param int $cacheLifetime cache lifetime * * @return void */ public function setCache(CacheProvider $cache, $cacheNamespace, $cacheLifetime) { $this->cache = $cache; $this->cache->setNamespace($cacheNamespace); $this->cacheLifetime = $cacheLifetime; }
protected function withNamespace() { $this->doctrineCache->setNamespace($this->namespace); return $this->doctrineCache; }
/** * Setter method to set key (Advanced) */ public function setKey($key) { $this->key = $key; $this->driver->setNamespace($this->key); }
public static function delete($key, $group = '') { self::$cacheDriver->setNamespace($group); self::$cacheDriver->delete($key); }
/** * Set cache instance * * @param \Doctrine\Common\Cache\CacheProvider $cache */ public function setCache(CacheProvider $cache) { $this->cache = $cache; $this->cache->setNamespace('oro_menu_instance'); }
/** * @param CacheProvider $cache * @return Configuration */ public function setCache(CacheProvider $cache) { $cache->setNamespace("dc2_" . md5($this->getProxyDir() . \Shopware::REVISION) . "_"); // to avoid collisions $this->setMetadataCacheImpl($cache); $this->setQueryCacheImpl($cache); $this->setResultCacheImpl($cache); return $this; }