Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 2

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?

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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.

View solution in original post

9 Replies

Avatar

Community Advisor

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

Avatar

Level 2

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.

Avatar

Level 7

@curious2improve : 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-c...

 

Avatar

Level 2

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

Avatar

Community Advisor

@curious2improve 

As per the documentation, /rules only supports glob patterns.

 

Documentation to construct globs are here: https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-c...

 

There is an online tool to verify Glob patterns https://www.digitalocean.com/community/tools/glob?comments=true&glob=%2F%2A%2A%2F%2A.js&matches=fals...

 

Please check if it helps.


Aanchal Sikka

Avatar

Level 2

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?

Avatar

Community Advisor

@curious2improve 

 

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

Avatar

Correct answer by
Level 2

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.