Skip to content

Commit

Permalink
Use FilterService in ResolveCacheProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkamp committed May 10, 2017
1 parent d5abad7 commit 05afc99
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 139 deletions.
36 changes: 10 additions & 26 deletions Async/ResolveCacheProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,38 @@
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Service\FilterService;

class ResolveCacheProcessor implements PsrProcessor, TopicSubscriberInterface, QueueSubscriberInterface
{
/**
* @var CacheManager
*/
private $cacheManager;

/**
* @var FilterManager
*/
private $filterManager;

/**
* @var DataManager
* @var FilterService
*/
private $dataManager;
private $filterService;

/**
* @var ProducerInterface
*/
private $producer;

/**
* @param CacheManager $cacheManager
* @param FilterManager $filterManager
* @param DataManager $dataManager
* @param FilterService $filterService
* @param ProducerInterface $producer
*/
public function __construct(
CacheManager $cacheManager,
FilterManager $filterManager,
DataManager $dataManager,
FilterService $filterService,
ProducerInterface $producer
) {
$this->cacheManager = $cacheManager;
$this->filterManager = $filterManager;
$this->dataManager = $dataManager;
$this->filterService = $filterService;
$this->producer = $producer;
}

Expand All @@ -77,20 +68,13 @@ public function process(PsrMessage $psrMessage, PsrContext $psrContext)
$path = $message->getPath();
$results = [];
foreach ($filters as $filter) {
if ($this->cacheManager->isStored($path, $filter) && $message->isForce()) {
$this->cacheManager->remove($path, $filter);
if ($message->isForce()) {
$this->filterService->bustCache($path, $filter);
}

if (false == $this->cacheManager->isStored($path, $filter)) {
$binary = $this->dataManager->find($filter, $path);
$this->cacheManager->store(
$this->filterManager->applyFilter($binary, $filter),
$path,
$filter
);
}
$this->filterService->createFilteredImage($path, $filter);

$results[$filter] = $this->cacheManager->resolve($path, $filter);
$results[$filter] = $this->filterService->getUrlOfFilteredImage($path, $filter);
}

$this->producer->send(Topics::CACHE_RESOLVED, new CacheResolved($path, $results));
Expand Down
3 changes: 1 addition & 2 deletions Resources/config/enqueue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

<services>
<service id="liip_imagine.async.resolve_cache_processor" class="Liip\ImagineBundle\Async\ResolveCacheProcessor">
<argument type="service" id="liip_imagine.cache.manager" />
<argument type="service" id="liip_imagine.filter.manager" />
<argument type="service" id="liip_imagine.data.manager" />
<argument type="service" id="liip_imagine.service.filter" />
<argument type="service" id="enqueue.producer" />

<tag name="enqueue.client.processor" />
Expand Down
13 changes: 13 additions & 0 deletions Service/FilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ public function createFilteredImageWithRuntimeFilters($path, $filter, array $run
);
}

/**
* @param string $path
* @param string $filter
*/
public function bustCache($path, $filter)
{
if (!$this->cacheManager->isStored($path, $filter)) {
return;
}

$this->cacheManager->remove($path, $filter);
}

/**
* @param string $path
* @param string $filter
Expand Down
Loading

0 comments on commit 05afc99

Please sign in to comment.