Query Parameter caching on Dispatcher

Here  I will discuss a very interesting question generally asked during interview & the question is – 
“How will we cache query parameters in Dispatcher cache?”
 
As we are working on AEM and it have a “Sling Script Resolution” concept.  So if you have some value that you want it to be cached then you should use either selectors or suffixes because there responses will be cached on dispatcher.
It’s a bad practice to cache query parameters but if you still want to do that then follow these steps.

Step I – Open dispatcher.any fileThere is a configuration shown as – 

#/ignoreUrlParams
#       {
#           /0001 { /glob “*” /type “deny” }
#           /0002 { /glob “q” /type “allow” }
#     }

Use this configuration for query parameters caching. As you can see this configuration is commented. So first remove comments from this configuration i.e.

/ignoreUrlParams
  {
       /0001 { /glob “*” /type “deny” }
      /0002 { /glob “q” /type “allow” }
}

and add the query parameter for those you want to cache the response. for example – 

/ignoreUrlParams
  {
        /0001 { /glob “*” /type “deny” }
        /0002 { /glob “q” /type “allow” }
        /0003 { /glob “x” /type “allow” } 
}

Step 2 –  Restart you Apache server.

Because of this configuration if you add “q” or “x” or both as a query parameters, then there responses will be cached successfully.

 

 

Happy Coding
Namah Shivay