本文整理汇总了PHP中Doctrine\Common\Cache\CacheProvider::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheProvider::contains方法的具体用法?PHP CacheProvider::contains怎么用?PHP CacheProvider::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Cache\CacheProvider
的用法示例。
在下文中一共展示了CacheProvider::contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* @param string $key
* @return mixed|null
*/
public function get($key)
{
if (!$this->cache->contains($key)) {
$this->loadSettings();
}
return $this->cache->fetch($key);
}
示例2: 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;
}
示例3: 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];
}
示例4: isRated
/**
* @param Article $article
* @return bool
*/
public function isRated(Article $article)
{
$ip = $this->getRequest()->getClientIp();
if ($this->cache->contains($ip)) {
return true;
}
return $this->isLiked($article) || $this->isDisLiked($article);
}
示例5: deleteItems
/**
* {@inheritdoc}
*/
public function deleteItems(array $keys)
{
foreach ($keys as $key) {
if (true === $this->provider->contains($key)) {
$this->provider->delete($key);
}
}
return $this;
}
示例6: __construct
/**
* @param \Doctrine\Common\Cache\CacheProvider $cacheDriver
*/
public function __construct($cacheDriver = null)
{
if (!is_null($cacheDriver) && class_exists('\\Doctrine\\Common\\Cache\\CacheProvider')) {
if ($cacheDriver instanceof \Doctrine\Common\Cache\CacheProvider) {
$this->cacheDriver = $cacheDriver;
if ($this->cacheDriver->contains($this->cacheKey)) {
$this->data = $this->cacheDriver->fetch($this->cacheKey);
}
}
}
}
示例7: preFind
/**
* @param EventInterface $event
*/
public function preFind(EventInterface $event)
{
if (!preg_match('/\\d$/', $this->cacheId)) {
return;
//The current route is a POST, do not cache new resources with this cache ID
}
if ($this->cache->contains($this->cacheId)) {
$event->stopPropagation(true);
return $this->cache->fetch($this->cacheId);
}
}
示例8: loadSourceData
/**
* @return array
*/
public function loadSourceData()
{
if (null === $this->cache) {
return $this->formatDataLoader->load($this->getUrl());
}
$key = $this->getObjectKey();
if (!$this->cache->contains($key)) {
$this->cache->save($key, $this->formatDataLoader->load($this->getUrl()), $this->getTtl());
}
return $this->cache->fetch($key);
}
示例9: testInvalidate
public function testInvalidate()
{
$key = 'test';
// create a fake list
$this->cache->register($key, uniqid());
$this->cache->register($key, uniqid());
$this->ormCache->save($key, 'bar');
$this->cache->invalidate($key);
// now both the orm cache and our cache should not contain this list
$this->assertFalse($this->ormCache->contains($key));
$this->assertNotContains($key, $this->cache->getRegisteredKeys($key));
}
示例10: call
public function call()
{
if (!in_array($this->app->request()->getMethod(), ['GET', 'HEAD'])) {
return $this->next->call();
}
$cacheKey = $this->app->request()->getPathInfo();
if ($this->cache->contains($cacheKey)) {
$resource = $this->cache->fetch($cacheKey);
$lastModified = strtotime($resource['last_updated_at']);
$this->app->lastModified($lastModified);
}
$this->next->call();
}
示例11: get
/**
* @return string
*/
public function get()
{
$key = 'feed';
if ($this->cache->contains($key)) {
return $this->cache->fetch($key);
}
$articles = $this->articleRepository->findPublishedOrderedByPublishDate();
$feed = $this->feedManager->get('article');
$feed->addFromArray($articles);
$renderedFeed = $feed->render('rss');
$this->cache->save($key, $renderedFeed);
return $renderedFeed;
}
示例12: getAll
/**
* @return array
*/
public function getAll()
{
$key = 'statistics';
if ($this->cache->contains($key)) {
return $this->cache->fetch($key);
}
$statistics = $this->articleRepository->findStatistics();
$mostPopularArticle = $this->articleRepository->findMostPopular();
if ($mostPopularArticle) {
$statistics['mostPopularArticleData'] = ['slug' => $mostPopularArticle->getSlug(), 'title' => $mostPopularArticle->getTitle(), 'viewsCount' => $mostPopularArticle->getViewsCount()];
}
$this->cache->save($key, $statistics, $this->cacheLifetime);
return $statistics;
}
示例13: checkDeploy
public function checkDeploy(GetResponseEvent $event)
{
if (null === $this->cache || $this->cache->contains(self::CHECK_DEPLOY_KEY)) {
return;
}
$clients = $this->clientRepository->countClients();
$cities = $this->cityRepository->countCities();
$hasDefaultClient = $this->clientRepository->findOneByUid($this->defaultClientUid) instanceof Client;
if ($clients <= 0 || $cities <= 0 || !$hasDefaultClient) {
$this->cache->delete(self::CHECK_DEPLOY_KEY);
throw new \RuntimeException('Make sure you did run the populate database command.');
} else {
$this->cache->save(self::CHECK_DEPLOY_KEY, true);
}
}
示例14: process
/**
*
* @param string $name
* @param string $processor
* @param \Heyday\CacheInclude\KeyCreators\KeyCreatorInterface $keyCreator
* @throws \InvalidArgumentException
* @return mixed
*/
public function process($name, $processor, KeyCreatorInterface $keyCreator)
{
if (!$processor instanceof ProcessorInterface && !is_callable($processor)) {
throw new \InvalidArgumentException('The argument $processor must be an instance of ProcessorInterface or a callable');
}
if (!$this->enabled) {
return $processor($name);
}
$config = $this->getCombinedConfig($name);
$key = $this->getKey($name, $keyCreator, $config);
if ($this->forceExpire) {
$this->cache->delete($key);
$this->removeStoredKey($name, $key);
$result = $processor($name);
$type = "EXPIRE";
} elseif ($this->cache->contains($key)) {
$result = $this->cache->fetch($key);
$type = "HIT";
} else {
$this->cache->save($key, $result = $processor($name), $this->getExpiry($config));
$this->addStoredKey($name, $key, $keyCreator);
$type = "MISS";
}
$this->log($type, $name, $key);
return $result;
}
示例15: contains
/**
* Returns a boolean state of whether or not the item exists in the cache based on id key
*
* @param string $id the id of the cached data entry
* @return bool true if the cached items exists
*/
public function contains($id)
{
if ($this->enabled) {
return $this->driver->contains($id);
}
return false;
}