Dispatcher config: how can I use a regex in a cache rules filter | Community
Skip to main content
MeasurableBusinessResults
Level 3
February 2, 2024
Solved

Dispatcher config: how can I use a regex in a cache rules filter

  • February 2, 2024
  • 4 replies
  • 2217 views

In my dispatcher config in the cache section, I have several rules filters.
The documentation describes how to use glob patterns.
But I would also like to use a regex (similar to the filters section).

E.g.

/cache
/rules
/0000 { /glob "*" /type "deny" }
/0010 { /url '^/etc/.*[/.-]([0-9a-f]{20}|[0-9a-f]{32})\.(css|js|woff2?|svg|ico|png)' /type "allow" }

But that does not work, I get an error in the log saying
Entry must have either glob or a combination of regex/path/selectors/extension/suffix.

How does it work?

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MeasurableBusinessResults

So as per the docs, only the glob option works.

Instead of the regex, a workaround using multiple rules is needed:

/0012 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].woff2" /type "allow" } /0013 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].woff2" /type "allow" } /0014 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].css" /type "allow" } /0015 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].css" /type "allow" } /0016 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].js" /type "allow" } /0017 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].js" /type "allow" } /0018 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].svg" /type "allow" } /0019 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].svg" /type "allow" } /0020 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].png" /type "allow" } /0021 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].png" /type "allow" }

 

Ugly, but it works.

4 replies

arunpatidar
Community Advisor
Community Advisor
February 2, 2024

Each item in the /rules property includes a glob pattern and a type:

  • The glob pattern is used to match the path of the document.
  • The type indicates whether to cache the documents that match the glob pattern. The value can be allow (to cache the document) or deny (to always render the document).

If you do not have dynamic pages (beyond those pages already excluded by the above rules), you can configure Dispatcher to cache everything. The rules section looks as follows:

/rules
  {
    /0000  {  /glob "*"   /type "allow" }
  }
For information about glob properties, see Designing Patterns for glob Properties.



You can try converting regex into the glob pattern

Example

 

The given regular expression '^/etc/.*/.-.(css|js|woff2?|svg|ico|png)' can be converted into a glob pattern as follows:

/^\/etc\/**/*[\/.-]@([0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]|[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])@(css|js|woff2?|svg|ico|png)


In this glob pattern:

  • ** represents any number of directories.
  • [\/.-] matches any character among '/', '.', and '-'.
  • @ is used instead of capturing groups.
  • The hex patterns for 20 and 32 characters are included.

Note : This is just an example

Arun Patidar
MeasurableBusinessResults
Level 3
February 2, 2024

The example you provided does not work. I am not sure what the "at" character is supposed to do, it's not mentioned in the glob docs.
Boolean ANDing is not supported either, e.g. (css|js|woff2?|svg|ico|png)

 

So yes, I could probably do this with the limited glob patterns instead of a regex, but then it would become super large and require several rules.
Quite a hack. I was hoping for a more elegant solution.

Kamal_Kishor
Community Advisor
Community Advisor
February 2, 2024

@measurablebusinessresults : Have you tried by specifying url, selectors, extension separately, for eg:-

/006 { /type "deny" /path "/content/*" /selectors '(feed|rss|pages|languages|blueprint|infinity|tidy|sysview|docview|query|jcr:content|_jcr_content|search|childrenlist|ext|assets|assetsearch|[0-9-]+)' /extension '(json|xml|html|feed))' }

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-configuration.html?lang=en#example-filter-filter-additional-elements-of-a-request-url

 

MeasurableBusinessResults
Level 3
February 2, 2024

Do you know or are you just speculating?

in any case it would be

 

/0011 { /type "allow" /method "GET" /url '^/etc/.*[/.-]([0-9a-f]{20}|[0-9a-f]{32})' /extension '(css|js|woff2?|svg|ico|png)' }

 

 

And no, it does not work
entry not recognized: 'method'

entry not recognized: 'url'

as these options only work in the filters section, but not in the cache rules

Kamal_Kishor
Community Advisor
Community Advisor
February 2, 2024

I was just speculating based on what works for /filters.
thanks.

MeasurableBusinessResults
Level 3
February 2, 2024

Thanks, the pattern validation tools sounds useful, but the help section above describes a lot more patterns than the AEM docs.
Is the rule engine the same? E.g. are all those supported, or only the ones mentioned in the AEM docs?

aanchal-sikka
Community Advisor
Community Advisor
February 2, 2024

@measurablebusinessresults 

 

I would suggest using only the ones mentioned in AEM docs.

I haven't used the tool myself yet. But, seemed interesting.

 

Maybe you can give it a try and let us know, if its compatible for basic scenarios.

Aanchal Sikka
MeasurableBusinessResults
MeasurableBusinessResultsAuthorAccepted solution
Level 3
February 2, 2024

So as per the docs, only the glob option works.

Instead of the regex, a workaround using multiple rules is needed:

/0012 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].woff2" /type "allow" } /0013 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].woff2" /type "allow" } /0014 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].css" /type "allow" } /0015 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].css" /type "allow" } /0016 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].js" /type "allow" } /0017 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].js" /type "allow" } /0018 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].svg" /type "allow" } /0019 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].svg" /type "allow" } /0020 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].png" /type "allow" } /0021 { /glob "/etc/*[/.-][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].png" /type "allow" }

 

Ugly, but it works.