Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Last active February 11, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/69c23e94273a7ea2d358 to your computer and use it in GitHub Desktop.
Save guilhermeblanco/69c23e94273a7ea2d358 to your computer and use it in GitHub Desktop.
<?php
namespace Doctrine\Cache\Driver\InMemory\Processor;
class GetEntryProcessor implements EntryProcessor
{
public function process(MutableEntry $entry, ...$arguments) : EntryProcessorResult
{
$now = microtime(true);
$valueConverter = $this->cache->getConfiguration()->getValueConverter();
$keyConverter = $this->cache->getConfiguration()->getKeyConverter();
$internalKey = $keyConverter->toInternal($entry->getKey());
$cachedValue = $this->cache->internalGet($internalKey);
if ($cachedValue !== null && ! $cachedValue->isExpiredAt($now)) {
$internalValue = $cachedValue->getInternalValue();
$value = $valueConverter->fromInternal($internalValue);
$entry->setValue($value);
return new EntryProcessorResult($entry);
}
$value = $this->cache->getConfiguration()->isReadThrough()
? $this->cache->getConfiguration()->getCacheLoader()->load($key)
: null;
if ($value === null) {
return new EntryProcessorResult(null);
}
$entry->setValue($value);
$expiryPolicy = $this->cache->getConfiguration()->getExpiryPolicy();
$creationDuration = $expiryPolicy->getExpiryForCreation();
$expiryTime = $creationDuration->getAdjustedTime($now);
$internalValue = $valueConverter->toInternal($value);
$cachedValue = new CachedValue($internalValue, $now, $expiryTime);
$this->cache->internalSet($internalKey, $cachedValue);
return new EntryProcessorResult($entry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment