本文整理汇总了PHP中Doctrine\Common\Cache\Cache::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::contains方法的具体用法?PHP Cache::contains怎么用?PHP Cache::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Cache\Cache
的用法示例。
在下文中一共展示了Cache::contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* @Route("/entry-point/{mac}", defaults={"mac" = null})
* @Method({"GET", "POST"})
* @Template()
*/
public function indexAction(Request $request, $mac)
{
// Attempting to do anything here as a logged in user will fail. Set the current user token to null to log user out.
$this->get('security.token_storage')->setToken(null);
if (!$mac) {
if (!$request->getSession()->get('auth-data')) {
// No MAC code, nothing in the session, so we can't help - return to front page.
return $this->redirectToRoute('barbon_hostedapi_app_index_index');
}
} else {
$cacheKey = sprintf('mac-%s', $mac);
// If MAC isn't found in the cache, it's already been processed - redirect back to this route without the MAC, and try again.
if (!$this->cache->contains($cacheKey)) {
return $this->redirectToRoute('barbon_hostedapi_landlord_authentication_entrypoint_index');
}
// store data to session and empty the cache
$authData = unserialize($this->cache->fetch($cacheKey));
$request->getSession()->set('auth-data', $authData);
$this->cache->delete($cacheKey);
}
// Decide which tab should start as visible, so that is a registration attempt is in progress it re-shows that tab.
$selectedTab = $request->query->get('action') ?: 'register';
if ($request->isMethod(Request::METHOD_POST)) {
if ($request->request->has('direct_landlord')) {
$selectedTab = 'register';
}
}
return array('selectedTab' => $selectedTab);
}
示例2: findAll
/**
* @param int $start
* @param int $maxResults
* @return Category[]|null
* @throws RepositoryException
*/
public function findAll($start = 0, $maxResults = 100)
{
$cacheKey = self::CACHE_NAMESPACE . sha1($start . $maxResults);
if ($this->isCacheEnabled()) {
if ($this->cache->contains($cacheKey)) {
return $this->cache->fetch($cacheKey);
}
}
$compiledUrl = $this->baseUrl . "?start_element={$start}&num_elements={$maxResults}";
$response = $this->client->request('GET', $compiledUrl);
$repositoryResponse = RepositoryResponse::fromResponse($response);
if (!$repositoryResponse->isSuccessful()) {
throw RepositoryException::failed($repositoryResponse);
}
$stream = $response->getBody();
$responseContent = json_decode($stream->getContents(), true);
$stream->rewind();
$result = [];
if (!$responseContent['response']['content_categories']) {
$responseContent['response']['content_categories'] = [];
}
foreach ($responseContent['response']['content_categories'] as $segmentArray) {
$result[] = Category::fromArray($segmentArray);
}
if ($this->isCacheEnabled()) {
$this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
}
return $result;
}
示例3: getTimestamp
public function getTimestamp($key)
{
if (!$this->cache->contains($key . ':timestamp')) {
return (double) 0;
}
return floatval($this->cache->fetch($key . ':timestamp'));
}
示例4: getContents
/**
* Get the contents of an URI and cache it for CACHE_LIFETIME seconds.
*
* @param string $uri
* @return string
*/
public function getContents($uri)
{
if (!$this->cache->contains($uri)) {
$this->cache->save($uri, $contents = $this->download($uri), static::CACHE_LIFETIME);
return $contents;
}
return $this->cache->fetch($uri);
}
示例5: getContext
/**
* Returns websocket context for given connection.
*
* @param ConnectionInterface $conn
*
* @return ConnectionContextInterface
*/
protected function getContext(ConnectionInterface $conn)
{
$id = ConnectionContext::getIdFromConnection($conn);
if (!$this->contexts->contains($id)) {
$this->saveContext($this->createContext($conn));
}
return $this->contexts->fetch($id);
}
示例6: internalRemoveItem
/**
* {@inheritDoc}
*/
protected function internalRemoveItem(&$normalizedKey)
{
$key = $this->getOptions()->getNamespace() . $normalizedKey;
if (!$this->cache->contains($key)) {
return false;
}
return $this->cache->delete($key);
}
示例7: fetch
/**
* @param string $txid
* @param int $vout
* @return Utxo
*/
public function fetch($txid, $vout)
{
$index = $this->getInternalIndex($txid, $vout);
if (!$this->cache->contains($index)) {
throw new \RuntimeException('Utxo not found in this cache');
}
return $this->cache->fetch($index);
}
示例8: getFromCache
/**
* @param $key
*
* @throws \LogicException
*
* @return bool|mixed
*/
public function getFromCache($key)
{
// If the results are already cached
if ($this->cache->contains($key)) {
return unserialize($this->cache->fetch($key));
}
return false;
}
示例9: remember
public function remember($key, \closure $callable, $lifeTime = 0)
{
if ($this->cache->contains($key)) {
return $this->cache->fetch($key);
}
$data = $callable();
$this->cache->save($key, $data, $lifeTime);
return $data;
}
示例10: getIpData
/**
* @param string $ip
* @return Location
*/
public function getIpData($ip)
{
if ($this->storage->contains($ip)) {
return $this->storage->fetch($ip);
}
$result = $this->provider->fetchDataForIp($ip);
$this->storage->save($ip, $result);
return $result;
}
示例11: addGroupToQueue
/**
* @param int $id
*/
public function addGroupToQueue($id)
{
$groupIds = [];
if ($this->cache->contains(self::QUEUE_CACHE_ID)) {
$groupIds = $this->cache->fetch(self::QUEUE_CACHE_ID);
}
$groupIds[$id] = $id;
$this->cache->save(self::QUEUE_CACHE_ID, $groupIds);
}
示例12: interpret
/**
* {@inheritDoc}
*/
public function interpret($rule)
{
if ($this->cache->contains($rule)) {
return unserialize($this->cache->fetch($rule));
}
$ast = $this->interpreter->interpret($rule);
$this->cache->save($rule, serialize($ast), $this->lifeTime);
return $ast;
}
示例13: findMatching
/**
* {@inheritdoc}
*/
public function findMatching($route, $host)
{
if ($this->cache->contains($this->getCacheKey())) {
return $this->cache->fetch($this->getCacheKey());
}
$rules = $this->ruleProvider->getRules();
$this->cache->save($this->getCacheKey(), $rules, $this->ttl);
return $rules;
}
示例14: getRolePermissions
/**
* {@inheritdoc}
*/
public function getRolePermissions(Role $role)
{
$cacheId = sprintf('roles/%s', $role->getRoleName());
$permissions = $this->cache->fetch($cacheId);
if (!$this->cache->contains($cacheId)) {
$permissions = $this->driver->getRolePermissions($role);
$this->cache->save($cacheId, $permissions);
}
return $permissions;
}
示例15: getThumbnail
/**
* Returns thumbnail data for the given transaction.
*
* Handles the cache layer around the creation as well.
*
* @param Transaction $transaction
*
* @return string
*/
protected function getThumbnail(Transaction $transaction)
{
$cacheKey = $transaction->getHash();
if ($this->cache->contains($cacheKey)) {
return $this->cache->fetch($cacheKey);
}
$imageData = $this->creator->create($transaction);
$this->cache->save($cacheKey, $imageData, $this->cacheTime);
return $imageData;
}