本文整理汇总了PHP中Doctrine\Common\Cache\Cache::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::fetch方法的具体用法?PHP Cache::fetch怎么用?PHP Cache::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Cache\Cache
的用法示例。
在下文中一共展示了Cache::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: load
/**
* {@inheritdoc}
*/
public function load()
{
$contents = $this->doctrine->fetch($this->key);
if ($contents !== false) {
$this->setFromStorage($contents);
}
}
示例3: 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;
}
示例4: fetchCached
protected function fetchCached(\Money\Currency $from, \Money\Currency $to)
{
if ($this->cache) {
$cacheKey = $this->getCacheKey($from, $to);
return $this->cache->fetch($cacheKey);
}
}
示例5: 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];
}
示例6: getMetadataFor
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
$class = $this->getClass($value);
if (!$class) {
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($value)));
}
if (isset($this->loadedClasses[$class])) {
return $this->loadedClasses[$class];
}
if ($this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) {
return $this->loadedClasses[$class];
}
if (!class_exists($class) && !interface_exists($class)) {
throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $class));
}
$classMetadata = new ClassMetadata($class);
$this->loader->loadClassMetadata($classMetadata);
$reflectionClass = $classMetadata->getReflectionClass();
// Include metadata from the parent class
if ($parent = $reflectionClass->getParentClass()) {
$classMetadata->merge($this->getMetadataFor($parent->name));
}
// Include metadata from all implemented interfaces
foreach ($reflectionClass->getInterfaces() as $interface) {
$classMetadata->merge($this->getMetadataFor($interface->name));
}
if ($this->cache) {
$this->cache->save($class, $classMetadata);
}
return $this->loadedClasses[$class] = $classMetadata;
}
示例7: 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);
}
示例8: fetch
/**
* {@inheritdoc}
*/
public function fetch($key)
{
if (false === ($value = $this->cache->fetch($key))) {
return null;
}
return $value;
}
示例9: 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;
}
示例10: find
public function find($id)
{
if (is_array($id)) {
$id = current($id);
}
return $this->cache->fetch($id) ?: null;
}
示例11: __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;
}
示例12: cachedInstance
/**
* Return cached injected instance
*
* @param string $class
* @param string $key
*
* @return array
*/
private function cachedInstance($class, $key)
{
$classDir = $this->cache->fetch($key);
$this->classLoader->register($classDir);
$instance = $this->cache->fetch("{$key}{$class}");
return $instance;
}
示例13: contains
/**
* {@inheritdoc}
*/
public function contains($id)
{
if ($stored = $this->decorated->fetch($id)) {
return $this->isDataDecryptable($stored, $id);
}
return false;
}
示例14: getMetadataFor
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
$class = $this->getClass($value);
if (isset($this->loadedClasses[$class])) {
return $this->loadedClasses[$class];
}
if ($this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) {
return $this->loadedClasses[$class];
}
$classMetadata = new ClassMetadata($class);
$this->loader->loadClassMetadata($classMetadata);
$reflectionClass = $classMetadata->getReflectionClass();
// Include metadata from the parent class
if ($parent = $reflectionClass->getParentClass()) {
$classMetadata->merge($this->getMetadataFor($parent->name));
}
// Include metadata from all implemented interfaces
foreach ($reflectionClass->getInterfaces() as $interface) {
$classMetadata->merge($this->getMetadataFor($interface->name));
}
if ($this->cache) {
$this->cache->save($class, $classMetadata);
}
return $this->loadedClasses[$class] = $classMetadata;
}
示例15: getArguments
public function getArguments(Request $request, $controller)
{
if (!is_array($controller)) {
throw new \InvalidArgumentException('Can not resolve arguments ' . 'for the controller type: "' . ($controller instanceof \Closure ? 'closure' : gettype($controller)) . '" for URI "' . $request->getPathInfo() . '"');
}
$id = get_class($controller[0]) . '::' . $controller[1] . '#method-parameters';
if (($parameters = $this->cacheProvider->fetch($id)) === false) {
$parameters = $this->getParameters($controller[0], $controller[1]);
$this->cacheProvider->save($id, $parameters);
}
$attributes = $request->attributes->all();
$arguments = array();
foreach ($parameters as $name => $options) {
if (array_key_exists($name, $attributes)) {
$arguments[] = $attributes[$name];
continue;
}
if (array_key_exists('defaultValue', $options)) {
$arguments[] = $options['defaultValue'];
continue;
}
throw new \RuntimeException('Controller ' . get_class($controller[0]) . '::' . $controller[1] . ' requires that you provide a value ' . 'for the "$' . $name . '" argument (because there is no default value or ' . 'because there is a non optional argument after this one).');
}
return $arguments;
}