added cache-invalidator-listener service #42

Merged
merged 5 commits into from Mar 14, 2013

Projects

None yet

2 participants

@dbu
Member
dbu commented Mar 12, 2013

we started with a listener service to go with the image document. whenever the image changes, the imagine cache should be invalidated.

@dbu dbu and 1 other commented on an outdated diff Mar 12, 2013
EventListener/ImagineCacheInvalidatorSubscriber.php
+ *
+ * @param LifecycleEventArgs $args
+ */
+ private function invalidateCache(LifecycleEventArgs $args)
+ {
+ $document = $args->getDocument();
+ if ($document instanceof Resource) {
+ $document = $document->getParent();
+ }
+ if ($document instanceof File) {
+ $document = $document->getParent();
+ }
+ if ($document instanceof Image) {
+ // TODO: this does not work, what do we need to pass to manager->remove?
+ // TODO: can we invalidate all caches? otherwise inject filter name(s)? by config
+ $this->manager->remove($document->getId(), 'image_upload_thumbnail');
@dbu
dbu Mar 12, 2013 Member

@havvg @lsmith77 is the phpcr support in LiipImagineBundle incomplete? or what do i need to pass to the cache manager? and is there a way to clear all cached images for a specific document or do i need to know a specific filter name?

@havvg
havvg Mar 13, 2013

On 0.9.x you need to resolve the name first, see liip/LiipImagineBundle#135 (comment)

@dbu
Member
dbu commented Mar 13, 2013

ok, this would be ready to merge. i will wait until tomorrow if you want to give some feedback /cc @rryter @lsmith77

@dbu dbu commented on the diff Mar 13, 2013
EventListener/ImagineCacheInvalidatorSubscriber.php
+ */
+ private function invalidateCache(LifecycleEventArgs $args)
+ {
+ $document = $args->getDocument();
+ if ($document instanceof Resource) {
+ $document = $document->getParent();
+ }
+ if ($document instanceof File) {
+ $document = $document->getParent();
+ }
+ if ($document instanceof Image) {
+ foreach ($this->filters as $filter) {
+ $path = $this->manager->resolve($this->container->get('request'), $document->getId(), 'image_upload_thumbnail')->getTargetUrl();
+ // TODO: this might not be needed https://github.com/liip/LiipImagineBundle/issues/162
+ if (false !== strpos($path, $filter)) {
+ $path = substr($path, strpos($path, $filter) + strlen($filter));
@dbu
dbu Mar 13, 2013 Member

if i get a reply on that issue today, i will clean this up if possible.

@dbu dbu merged commit d12d8d8 into doctrine:master Mar 14, 2013
@dbu dbu deleted the unknown repository branch Mar 14, 2013
@dbu
Member
dbu commented Mar 14, 2013

also cleaned up the configuration. you now need to explicitly enable imagine to have this block.

the full config options for imagine are now

doctrine_phpcr:
    ...
    imagine:
        enabled: true
        filter: preview_filter_name
        extra_filters:
            - imagine_filter_name1
            - imagine_filter_name2

guess i have to update the doc as well...

/cc @rryter @elhornair

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment