@@ -631,3 +631,47 @@ Use php \intval function on input
631631``` twig
632632{% set size = app.request.query.get('size', 0)|ems_int %}
633633```
634+
635+ ### ems_clear_http_caches
636+
637+ Calls the configured reverse proxy services to invalidate part or all of their caches.
638+
639+ It accepts one optional argument:
640+
641+ - ** ` URL or Tags ` (optional)** :
642+ - If it contains an empty array (default value), a full cache purge will be sent.
643+ - If it is a string starting with ` / ` , a cache clear by URL will be sent.
644+ - Otherwise, a cache clear by tags will be sent.
645+
646+ #### Example of a cache clear route
647+
648+ The URL is triggered by a ` clear-cache ` webhook event, at the endpoint ` //localhost/_clear_cache ` .
649+
650+ Depending on the event data:
651+
652+ - If it contains a ** ` tags ` ** attribute (string or array of strings), a tag-based cache clear will
653+ be sent.
654+ - If it contains a ** ` url ` ** attribute (string), a URL-based cache clear will be sent.
655+ - Otherwise, a full cache purge will be sent.
656+
657+ The ` emsch_clear_cache ` route:
658+
659+ ``` yaml
660+ emsch_clear_cache :
661+ config :
662+ path : ' /_clear_cache'
663+ method : [POST]
664+ host : ' localhost'
665+ template_static : template/admin/clear-cache.html.twig
666+ ` ` `
667+
668+ The ` template/admin/clear-cache.html.twig` twig:
669+
670+ ` ` ` twig
671+ {%- set event = emsch_webhook_event() -%}
672+ {%- if event.name == 'clear-cache' -%}
673+ {%- do ems_clear_http_caches(event.data.tags|default(event.data.url|default([]))) -%}
674+ {%- set success = true -%}
675+ {%- endif -%}
676+ {{- { success: success|default(false) }|json_encode|raw -}}
677+ ` ` `
0 commit comments