Last active
February 11, 2016 16:07
-
-
Save guilhermeblanco/69c23e94273a7ea2d358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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