本文整理汇总了PHP中Doctrine\Common\Cache\Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: deleteAll
/**
* {@inheritdoc}
*/
public function deleteAll()
{
if ($this->cache instanceof ClearableCache) {
return $this->cache->deleteAll();
}
return false;
}
开发者ID:zientalak,项目名称:devicedetector,代码行数:10,代码来源:DoctrineCacheBridge.php
示例2: saveCached
protected function saveCached(\Money\CurrencyPair $pair)
{
if ($this->cache) {
$cacheKey = $this->getCacheKey($pair->getCounterCurrency(), $pair->getBaseCurrency());
$this->cache->save($cacheKey, $pair, self::CACHE_LIFETIME);
}
}
开发者ID:morbicer,项目名称:converter-bundle,代码行数:7,代码来源:Convert.php
示例3: clearCache
/**
* Delete the cache keys
*
* @param Cache $cache
* @param array $keys
*/
protected function clearCache(Cache $cache, $keys)
{
$keys = array_unique($keys);
foreach ($keys as $key) {
$cache->delete($key);
}
}
开发者ID:michelv,项目名称:doctrine-cache-sweeper-bundle,代码行数:13,代码来源:CacheSweeper.php
示例4: __construct
public function __construct(Cache $cache, ValidationService $validationService, Factory $factory = null)
{
$this->objects = $cache->fetch("agit.api.object") ?: [];
$this->factory = $factory;
AbstractType::setValidationService($validationService);
AbstractType::setObjectMetaService($this);
}
开发者ID:agitation,项目名称:api-bundle,代码行数:7,代码来源:ObjectMetaService.php
示例5: getStreams
/**
* Get the list of videos from YouTube
*
* @param string $channelId
* @throws \Mcfedr\YouTube\LiveStreamsBundle\Exception\MissingChannelIdException
* @return array
*/
public function getStreams($channelId = null)
{
if (!$channelId) {
$channelId = $this->channelId;
}
if (!$channelId) {
throw new MissingChannelIdException("You must specify the channel id");
}
if ($this->cache) {
$data = $this->cache->fetch($this->getCacheKey($channelId));
if ($data !== false) {
return $data;
}
}
$searchResponse = $this->client->get('search', ['query' => ['part' => 'id', 'channelId' => $channelId, 'eventType' => 'live', 'type' => 'video', 'maxResults' => 50]]);
$searchData = json_decode($searchResponse->getBody()->getContents(), true);
$videosResponse = $this->client->get('videos', ['query' => ['part' => 'id,snippet,liveStreamingDetails', 'id' => implode(',', array_map(function ($video) {
return $video['id']['videoId'];
}, $searchData['items']))]]);
$videosData = json_decode($videosResponse->getBody()->getContents(), true);
$streams = array_map(function ($video) {
return ['name' => $video['snippet']['title'], 'thumb' => $video['snippet']['thumbnails']['high']['url'], 'videoId' => $video['id']];
}, array_values(array_filter($videosData['items'], function ($video) {
return !isset($video['liveStreamingDetails']['actualEndTime']);
})));
if ($this->cache && $this->cacheTimeout > 0) {
$this->cache->save($this->getCacheKey($channelId), $streams, $this->cacheTimeout);
}
return $streams;
}
开发者ID:mcfedr,项目名称:youtubelivestreamsbundle,代码行数:37,代码来源:YouTubeStreamsLoader.php
示例6: clear
/**
* {@inheritdoc}
*/
public function clear($cacheDir)
{
if (!$this->cache instanceof ClearableCache) {
return;
}
$this->cache->deleteAll();
}
开发者ID:gabiudrescu,项目名称:Sylius,代码行数:10,代码来源:TemplatePathsCacheClearer.php
示例7: __invoke
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$key = $this->generateKey($request);
$data = $this->cache->fetch($key);
if (false !== $data) {
list($body, $code, $headers) = unserialize($this->cache->fetch($key));
$response->getBody()->write($body);
$response = $response->withStatus($code);
foreach (unserialize($headers) as $name => $value) {
$response = $response->withHeader($name, $value);
}
return $response;
}
// prepare headers
$ttl = $this->config['ttl'];
$response = $next ? $next($request, $response) : $response;
$response = $response->withHeader('Cache-Control', sprintf('public,max-age=%d,s-maxage=%d', $ttl, $ttl))->withHeader('ETag', $key);
// save cache - status code, headers, body
$body = $response->getBody()->__toString();
$code = $response->getStatusCode();
$headers = serialize($response->getHeaders());
$data = serialize([$body, $code, $headers]);
$this->cache->save($key, $data, $this->config['ttl']);
return $response;
}
开发者ID:tonis-io,项目名称:response-cache,代码行数:31,代码来源:ResponseCache.php
示例8: 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;
}
开发者ID:audiens,项目名称:appnexus-client,代码行数:35,代码来源:CategoryRepository.php
示例9: getCacheContext
/**
* get config webhook for current webinstance
*
* @param $version
*
* @return mixed
*/
public function getCacheContext($version)
{
if (!($config = $this->cache->fetch($this->getCacheKey()))) {
$config = $this->createConfig($version);
$this->cache->save($this->getCacheKey(), $config, 86400);
}
return $config;
}
开发者ID:eliberty,项目名称:api-bundle,代码行数:15,代码来源:GroupsContextLoader.php
示例10: deleteAll
/**
* Clears all cache entries.
*
* @throws \RuntimeException If the cache instance is not an instanceof Doctrine\Common\Cache\ClearableCache
*/
public function deleteAll()
{
if ($this->cache instanceof ClearableCache) {
$this->cache->deleteAll();
return;
}
throw new \RuntimeException('Cache given is not an instanceof Doctrine\\Common\\Cache\\ClearableCache');
}
开发者ID:gmo,项目名称:cache,代码行数:13,代码来源:DoctrineProxy.php
示例11: saveCache
/**
* @param \databox[] $databoxes
*/
private function saveCache(array $databoxes)
{
$rows = array();
foreach ($databoxes as $databox) {
$rows[$databox->get_sbas_id()] = $databox->getRawData();
}
$this->cache->save($this->cacheKey, $rows);
}
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:11,代码来源:CachingDataboxRepositoryDecorator.php
示例12: cache
/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @return bool true if success
*/
public function cache(RequestInterface $request, ResponseInterface $response)
{
try {
return $this->storage->save($this->getCacheKey($request), $this->getCacheObject($response));
} catch (\Exception $ignored) {
return false;
}
}
开发者ID:royopa,项目名称:guzzle-cache-middleware,代码行数:13,代码来源:PrivateCache.php
示例13: getAllProjects
public function getAllProjects()
{
$key = "{$this->cachePrefix}-all-projects";
if ($this->cache && ($projects = $this->cache->fetch($key))) {
return $projects;
}
$first = json_decode($this->client->get('projects.json', ['query' => ['limit' => 100]])->getBody(), true);
$projects = $first['projects'];
if ($first['total_count'] > 100) {
$requests = [];
for ($i = 100; $i < $first['total_count']; $i += 100) {
$requests[] = $this->client->getAsync('projects.json', ['query' => ['limit' => 100, 'offset' => $i]]);
}
/** @var Response[] $responses */
$responses = Promise\unwrap($requests);
$responseProjects = array_map(function (Response $response) {
return json_decode($response->getBody(), true)['projects'];
}, $responses);
$responseProjects[] = $projects;
$projects = call_user_func_array('array_merge', $responseProjects);
}
usort($projects, function ($projectA, $projectB) {
return strcasecmp($projectA['name'], $projectB['name']);
});
$this->cache && $this->cache->save($key, $projects);
return $projects;
}
开发者ID:stelsvitya,项目名称:server-manager,代码行数:27,代码来源:Projects.php
示例14: load
/**
* {@inheritdoc}
*/
public function load()
{
$contents = $this->doctrine->fetch($this->key);
if ($contents !== false) {
$this->setFromStorage($contents);
}
}
开发者ID:bolt,项目名称:filesystem,代码行数:10,代码来源:DoctrineCache.php
示例15: getForDay
/**
* @param float $latitude
* @param float $longitude
* @return WeatherForecastForDay
*/
public function getForDay($latitude, $longitude, $timestamp)
{
if (!$this->isValidTimestamp($timestamp)) {
throw new \Exception('Invalid timestamp: ' . $timestamp);
}
if (!$this->isValidLatitude($latitude)) {
throw new \Exception('Invalid latitude: ' . $latitude);
}
if (!$this->isValidLongitude($longitude)) {
throw new \Exception('Invalid longitude: ' . $longitude);
}
$latitude = $this->normalizeGeoCoordinate($latitude);
$longitude = $this->normalizeGeoCoordinate($longitude);
$timestamp = $this->normalizeTimestamp($timestamp);
$cacheKey = md5($latitude . $longitude . $timestamp);
if (false === ($apiData = $this->cache->fetch($cacheKey))) {
try {
$apiData = $this->provider->getForDay($latitude, $longitude, $timestamp);
$this->cache->save($cacheKey, $apiData, 3600 * 6);
//TTL 6h
} catch (\Exception $e) {
return null;
}
}
return new WeatherForecastForDay($apiData);
}
开发者ID:Kvebalas,项目名称:weather,代码行数:31,代码来源:Forecast.php
示例16: insertAccessToken
/**
* @param $token
* @param AuthUser $user
* @return AccessToken
*/
public function insertAccessToken($token, AuthUser $user)
{
$accessToken = new AccessToken();
$accessToken->setCreatedAt(new \DateTime())->setId($token)->setUsername($user->getUsername());
$this->cache->save($token, $accessToken, 604800);
return $accessToken;
}
开发者ID:Resmin,项目名称:Resmin-Api,代码行数:12,代码来源:AccessTokenService.php
示例17: save
/**
* @param BlockHeaderInterface $block
* @return bool
*/
public function save(BlockHeaderInterface $block)
{
$key = $this->cacheIndexBlk($block);
$this->blocks->save($key, $block);
$this->size++;
return $this;
}
开发者ID:rubensayshi,项目名称:bitcoin-php,代码行数:11,代码来源:HeaderStorage.php
示例18: find
public function find($id)
{
if (is_array($id)) {
$id = current($id);
}
return $this->cache->fetch($id) ?: null;
}
开发者ID:basuritas-php,项目名称:skeleton-mapper,代码行数:7,代码来源:CacheObjectDataRepository.php
示例19: getMetadataForClass
/**
* Get metadata for a certain class - loads once and caches
* @param string $className
* @throws \Drest\DrestException
* @return ClassMetaData $metaData
*/
public function getMetadataForClass($className)
{
if (isset($this->loadedMetadata[$className])) {
return $this->loadedMetadata[$className];
}
// check the cache
if ($this->cache !== null) {
$classMetadata = $this->cache->fetch($this->cache_prefix . $className);
if ($classMetadata instanceof ClassMetaData) {
if ($classMetadata->expired()) {
$this->cache->delete($this->cache_prefix . $className);
} else {
$this->loadedMetadata[$className] = $classMetadata;
return $classMetadata;
}
}
}
$classMetadata = $this->driver->loadMetadataForClass($className);
if ($classMetadata !== null) {
$this->loadedMetadata[$className] = $classMetadata;
if ($this->cache !== null) {
$this->cache->save($this->cache_prefix . $className, $classMetadata);
}
return $classMetadata;
}
if (is_null($this->loadedMetadata[$className])) {
throw DrestException::unableToLoadMetaDataFromDriver();
}
return $this->loadedMetadata[$className];
}
开发者ID:steve-todorov,项目名称:drest,代码行数:36,代码来源:MetadataFactory.php
示例20: 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);
}
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:34,代码来源:EntryPointController.php
注:本文中的Doctrine\Common\Cache\Cache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论