Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom cache resolver issue. Default resolver is being called even if custom is specified #265

Closed
svscorp opened this issue Nov 6, 2013 · 16 comments
Labels
Attn: Blocker This item blocks other issue(s) or PR(s) and therefore must be resolved prior. Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Milestone

Comments

@svscorp
Copy link

svscorp commented Nov 6, 2013

Hello

I am writing a custom cache resolver according to the documentation: https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/cache-resolvers.md

I am storing cropped images in the project/web/images/thumbnails

my config.yml:
liip_imagine:
driver: gmagick
cache: my_custom_cache
cache_prefix: /images/thumbnails
filter_sets:
model_preview_thumbnail:
path: /100x100
quality: 75
filters:
thumbnail: { size: [100, 100], mode: outbound }

And in my custom cache resolver (which is almost copy of WebPathResolver) I do nothing in 'clear' method, because I wont delete my thumbnails.

But when I clearing the cache I experience a problem. My custom resolver executes, and then - default one from the bundle is being called. And it tries to clean 'cache' directory:

svs: /var/www/project$ app/console cache:clear -v
Clearing the cache for the dev environment with debug true

[Symfony\Component\Filesystem\Exception\IOException]                                  
Failed to remove directory /var/www/project/web/images/thumbnails


Exception trace:
 () at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Filesystem.php:143
 Symfony\Component\Filesystem\Filesystem->remove() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Filesystem.php:140
 Symfony\Component\Filesystem\Filesystem->remove() at /var/www/project/vendor/liip/imagine-bundle/Liip/ImagineBundle/Imagine/Cache/Resolver/WebPathResolver.php:57
 Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver->clear() at /var/www/project/vendor/liip/imagine-bundle/Liip/ImagineBundle/Imagine/Cache/CacheManager.php:238
 Liip\ImagineBundle\Imagine\Cache\CacheManager->clearResolversCache() at /var/www/project/vendor/liip/imagine-bundle/Liip/ImagineBundle/Imagine/Cache/CacheClearer.php:43
 Liip\ImagineBundle\Imagine\Cache\CacheClearer->clear() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php:42
 Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer->clear() at /var/www/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:70
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244
 Symfony\Component\Console\Command\Command->run() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:904
 Symfony\Component\Console\Application->doRunCommand() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
 Symfony\Component\Console\Application->doRun() at /var/www/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
 Symfony\Component\Console\Application->run() at /var/www/project/app/console:27


cache:clear [--no-warmup] [--no-optional-warmers]

The question is this behavior is expected? I expect only specified custom resolver should be called. Is there a way to not call the default one?

@LouTerrailloune
Copy link
Contributor

To avoid the cache clearing, just set this in your config:

liip_imagine:
    cache_clearer: false

I do this in every project.

@svscorp
Copy link
Author

svscorp commented Nov 6, 2013

@LouTerrailloune so, this option prevent cache cleaning with default resolver only (and if you have custom clear method implemented it will executes)? Or it disable cache cleaning completely?

If last case, it would be good to know how to disable clear cache calling only for default cache resolver.

@LouTerrailloune
Copy link
Contributor

I think this will prevent cache clearing completely.

The bundled cache clearer service will call all loaded resolver (even if not used), that means liip_imagine.cache.resolver.web_path and liip_imagine.cache.resolver.no_cache.

If you need to do something special, you can define your own cache clearer service.

@havvg
Copy link
Contributor

havvg commented Nov 11, 2013

The Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface::clear method is compatible with the Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface::clear. So you only need to add the kernel.cache_clearer tag to your custom resolver service in order to activate the clearing for a specific resolver (and implement the interface with your resolver class).

@LouTerrailloune
Copy link
Contributor

I think the problem is that he is not using liip_imagine.cache.resolver.web_path but the clear function is called (which cause an error).

I think we should register liip_imagine.cache.resolver.web_path and liip_imagine.cache.resolver.no_cache to the DIC only if they are used (ie: explicitely specified in global config or if nothing specified in config and there is a filter without cache specified).

@havvg
Copy link
Contributor

havvg commented Dec 4, 2013

Seems reasonable to me.

@svscorp
Copy link
Author

svscorp commented Mar 25, 2014

Yes, that was exactly as described.

I am using custom cache resolver, extended from web_path one. But after last update I have an error: Unrecognized options "cache_prefix, cache_clearer" under "liip_imagine"

Did I miss those parameters were removed? What is the analog?

@makasim
Copy link
Collaborator

makasim commented Mar 25, 2014

@svscorp They were removed in 1.0

@makasim
Copy link
Collaborator

makasim commented Mar 25, 2014

@havvg @LouTerrailloune there is no more no cache and web path resolver defined. You have explicitly add them using config or as a service with tag.

@svscorp
Copy link
Author

svscorp commented Mar 25, 2014

@makasim Cool, now I need to find out how to specify cache_prefix to store the files in a location different from 'cache/media' (without using custom resolver. There also a change btw, second argument in a service for custom resolver has changed).

@svscorp
Copy link
Author

svscorp commented Mar 25, 2014

It's very strange. Even specifying:

liip_imagine:
    ...
    driver:       gmagick
    cache: default
    filter_sets:
        thumbnail_160:
            path: /thumbnail/160x120
            quality: 75
            filters:
                thumbnail: { size: [160, 120], mode: outbound }

it continues to store the cached image using filter name in the path.

@makasim
Copy link
Collaborator

makasim commented Mar 26, 2014

@svscorp

Cool, now I need to find out how to specify cache_prefix to store the files in a location different from 'cache/media

https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/cache-resolver/web_path.md#create-resolver

There also a change btw, second argument in a service for custom resolver has changed).

There are many BC breaks, not only you mentioned: https://github.com/liip/LiipImagineBundle/blob/master/UPGRADE.md

@svscorp
Copy link
Author

svscorp commented Mar 26, 2014

@makasim Ok, thanks. Only filter path issue left. It is not being applied when store a cached image. It stores it here $webPath . $cachePrefix . $filterName . $sourceImgPath instead of $webPath . $cachePrefix . $filterPath . $sourceImgPath

@svscorp
Copy link
Author

svscorp commented Mar 26, 2014

It's not possible to get the 'path' option in Resolver, because it's not aware of filter configuration.

@makasim
Copy link
Collaborator

makasim commented Mar 29, 2014

@svscorp may be closed?

@svscorp
Copy link
Author

svscorp commented Mar 31, 2014

Clear. Removed in 1.0
Hope will be implemented as feature soon :)

Discussion: #366

@svscorp svscorp closed this as completed Mar 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: Blocker This item blocks other issue(s) or PR(s) and therefore must be resolved prior. Level: Bug 🐞 This item involves a legitimate regression (bug) to existing functionality.
Projects
None yet
Development

No branches or pull requests

4 participants