本文整理汇总了PHP中Doctrine\Common\Cache\CacheProvider类的典型用法代码示例。如果您正苦于以下问题:PHP CacheProvider类的具体用法?PHP CacheProvider怎么用?PHP CacheProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CacheProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $file
* @param \Doctrine\Common\Cache\CacheProvider $cache
* @throws \Heystack\Core\Exception\ConfigurationException
*/
public function __construct($file, CacheProvider $cache)
{
// if it isn't an absolute path (detected by the file not existing)
if (!file_exists($file)) {
$file = BASE_PATH . '/' . $file;
}
if (!file_exists($file)) {
throw new ConfigurationException(sprintf("Your file '%s' doesn't exist", $file));
}
// Use the contents as the key so invalidation happens on change
$key = md5(file_get_contents($file));
if (($config = $cache->fetch($key)) === false) {
$config = $this->parseFile($file);
$cache->save($key, $config);
}
if (!is_array($config)) {
throw new ConfigurationException(sprintf("Your config is empty for file '%s'", $file));
}
if (!array_key_exists('id', $config)) {
throw new ConfigurationException(sprintf("Identifier missing for file '%s'", $file));
}
if (!array_key_exists('flat', $config)) {
throw new ConfigurationException(sprintf("Flat config missing for file '%s'", $file));
}
$this->config = $config;
}
示例2: decorateWithConnectable
/**
* @param CacheProvider $cacheProvider
*
* @return CacheProvider
*/
protected function decorateWithConnectable(CacheProvider $cacheProvider)
{
$memcached = $this->getMemcachedAdapter();
$settings = $this->config->getSettings();
$memcached->addserver($settings['host'], $settings['port']);
$cacheProvider->setMemcached($memcached);
return $cacheProvider;
}
示例3: clearCacheDriver
protected function clearCacheDriver(CacheProvider $cacheDriver = null, $description = "")
{
if ($cacheDriver !== null) {
$this->output .= 'Doctrine ' . $description . ' cache: ' . $cacheDriver->getNamespace() . ' — ';
$this->output .= $cacheDriver->deleteAll() ? '<info>OK</info>' : '<info>FAIL</info>';
$this->output .= PHP_EOL;
}
}
示例4: decorateWithConnectable
/**
* @param CacheProvider $cacheProvider
*
* @return CacheProvider
*/
protected function decorateWithConnectable(CacheProvider $cacheProvider)
{
$redis = $this->getRedisAdapter();
$settings = $this->config->getSettings();
$redis->connect($settings['host'], $settings['port']);
$cacheProvider->setRedis($redis);
return $cacheProvider;
}
示例5: __construct
/**
* 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();
}
示例6: get
/**
* Build menu.
*
* @param string $alias
* @param array $options
* @return ItemInterface
*/
public function get($alias, array $options = [])
{
$this->assertAlias($alias);
if (!array_key_exists($alias, $this->menus)) {
if ($this->cache && $this->cache->contains($alias)) {
$menuData = $this->cache->fetch($alias);
$this->menus[$alias] = $this->factory->createFromArray($menuData);
} else {
$menu = $this->factory->createItem($alias);
/** @var BuilderInterface $builder */
// try to find builder for the specified menu alias
if (array_key_exists($alias, $this->builders)) {
foreach ($this->builders[$alias] as $builder) {
$builder->build($menu, $options, $alias);
}
}
// In any case we must run common builder
if (array_key_exists(self::COMMON_BUILDER_ALIAS, $this->builders)) {
foreach ($this->builders[self::COMMON_BUILDER_ALIAS] as $builder) {
$builder->build($menu, $options, $alias);
}
}
$this->menus[$alias] = $menu;
$this->eventDispatcher->dispatch(ConfigureMenuEvent::getEventName($alias), new ConfigureMenuEvent($this->factory, $menu));
$this->sort($menu);
if ($this->cache) {
$this->cache->save($alias, $menu->toArray());
}
}
}
return $this->menus[$alias];
}
示例7: getVersion
/**
* @param string $packageName
* @return string
*/
public function getVersion($packageName = OroPlatformBundle::PACKAGE_NAME)
{
// Get package version from local cache if any
if (isset($this->packageVersions[$packageName])) {
return $this->packageVersions[$packageName];
}
// Try to get package version from persistent cache
if ($this->cache && $this->cache->contains($packageName)) {
$version = $this->cache->fetch($packageName);
} else {
// Get package version from composer repository
$packages = $this->factory->getLocalRepository()->findPackages($packageName);
if ($package = current($packages)) {
/** @var PackageInterface $package */
$version = $package->getPrettyVersion();
} else {
$version = self::UNDEFINED_VERSION;
}
//Save package version to persistent cache
if ($this->cache) {
$this->cache->save($packageName, $version);
}
}
// Save package version to local cache
$this->packageVersions[$packageName] = $version;
return $version;
}
示例8: loadSettings
/**
* @return array
*/
private function loadSettings()
{
/** @var Setting $setting */
foreach ($this->repository->findAll() as $setting) {
$this->cache->save($setting->getKey(), $setting->getValue());
}
}
示例9: clearCache
/**
*
*/
private function clearCache()
{
$container = $this->getConfigurationPool()->getContainer();
$container->get('harentius_blog.router.category_slug_provider')->clearAll();
$this->cache->deleteAll();
$container->get('harentius_blog.controller.feed_cache')->deleteAll();
}
示例10: clean
/**
* Removes items from the cache by conditions.
*
* @param array $conditions
* @return void
*/
public function clean(array $conditions)
{
if (!isset($conditions[Nette\Caching\Cache::ALL])) {
throw new NotImplementedException();
}
$this->provider->deleteAll();
}
示例11: getTcmbData
/**
* TCMB sitesi üzerinden XML'i okur.
*
* @param Curl $curl
*
* @throws Exception\ConnectionFailed
*/
private function getTcmbData(Curl $curl = null)
{
if (is_null($curl)) {
$curl = new Curl();
}
$curl->setOption(CURLOPT_URL, 'http://www.tcmb.gov.tr/kurlar/today.xml');
$curl->setOption(CURLOPT_HEADER, 0);
$curl->setOption(CURLOPT_RETURNTRANSFER, 1);
$curl->setOption(CURLOPT_FOLLOWLOCATION, 1);
$response = $curl->exec();
if ($response === false) {
throw new Exception\ConnectionFailed('Sunucu Bağlantısı Kurulamadı: ' . $curl->error());
}
$curl->close();
$this->data = $this->formatTcmbData((array) simplexml_load_string($response));
$timezone = new \DateTimeZone('Europe/Istanbul');
$now = new \DateTime('now', $timezone);
$expire = $this->data['today'] == $now->format('d.m.Y') ? 'Tomorrow 15:30' : 'Today 15:30';
$expireDate = new \DateTime($expire, $timezone);
$this->data['expire'] = $expireDate->getTimestamp();
if (!is_null($this->cacheDriver)) {
$lifetime = $expire - $now->getTimestamp();
// Eğer dosyanın geçerlilik süresi bitmişse veriyi sadece 5 dakika önbellekte tutuyoruz.
$this->cacheDriver->save($this->cacheKey, $this->data, $lifetime > 0 ? $lifetime : 300);
}
}
示例12: clear
public function clear()
{
if (!$this->hasNamespace()) {
$this->doctrineCache->flushAll();
} else {
$this->withNamespace()->deleteAll();
}
}
示例13: build
/**
* (non-PHPdoc)
* @see Generator/Admingenerator\GeneratorBundle\Generator.GeneratorInterface::build()
*/
public function build()
{
if ($this->cacheProvider->fetch($this->getCacheKey())) {
return;
}
$this->doBuild();
$this->cacheProvider->save($this->getCacheKey(), true);
}
示例14: getCachedAssetVersion
/**
* @param string $packageName
*
* @return int
*/
protected function getCachedAssetVersion($packageName)
{
if (!array_key_exists($packageName, $this->localCache)) {
$version = $this->cache->fetch($packageName);
$this->localCache[$packageName] = false !== $version ? $version : 0;
}
return $this->localCache[$packageName];
}
示例15: FetchWithNamespace_StoreInformation
/**
* @test
*/
public function FetchWithNamespace_StoreInformation()
{
$this->cacheProvider->save('namespaceId', 'namespace_id');
$this->cacheProvider->save('namespace_idid', 'data-test');
$this->decorator->fetchWithNamespace('id', 'namespaceId');
$this->decorator->fetchWithNamespace('id', 'namespaceId');
$this->assertCollectedData([new FetchWithNamespaceCacheCollectedData('id', 'namespaceId', 'data-test', 0)], $this->decorator->getCollectedData());
}