Skip to content

Custom Cache Resolver

Edit this page

You can define your own custom cache resolvers to handle cache resolution using your storage backend. Creating a custom cache resolver begins by creating a class that implements the ResolverInterface:

1
2
3
4
5
6
7
interface ResolverInterface
{
    public function isStored($path, $filter);
    public function resolve($path, $filter);
    public function store(BinaryInterface $binary, $path, $filter);
    public function remove(array $paths, array $filters);
}

Once you have defined your custom cache resolver, you need to define it as a service and tag it with liip_imagine.cache.resolver:

1
2
3
4
5
6
7
8
9
10
# app/config/services.yml

services:
    imagine.cache.resolver.my_custom:
        class: App\Service\MyCustomResolver
        arguments:
            - "@filesystem"
            - "@router"
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: my_custom_cache }

Note

For more information on the Service Container, reference the official Symfony Service Container documentation.

Now your custom cache resolver can be set as the global default using the name defined in the resolver attribute of the tags key.

1
2
liip_imagine:
    cache: my_custom_cache

Alternatively you can only set the custom cache resolver for just a specific filter set:

1
2
3
4
liip_imagine:
    filter_sets:
        my_special_style:
            cache: my_custom_cache
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version