cancel
Showing results for 
Search instead for 
Did you mean: 

Http cache and setkey

Highlighted
Occasional Contributor

Http cache and setkey

Hi

 

I have this rule enabled, but it does not work.

 

I want to set a cache key that is the same for all URLs even if they have one or more of the 4 paramters listed in the blaclist.

 

So a url of

/hello/world/?icid=1234567890

/hello/world/

/hello/world/?icid=1234567890&icid=abcdefgh

 

would all be cached in the same cachekey. /hello/world/& (the & from the query I rewrite to just have opne regex and not two)

 

But a

/hello/world/?icid=1234567890&myvar=1

 

Would be cached under a key of /hello/world/&myvar=1&

 

Rule:

 

$hostheader = string.lowercase(http.getHostHeader());
$query = http.getQueryString();
$orig = $query;
$hexed=0;

if (string.contains($hostheader, "domain.com")) {
   $path = http.getPath();
   $blacklist = ['icid=', 'gclid=', 'qcid=', 'cid='];
   $query=$query.'&';
   foreach ($q in $blacklist) {
      if (string.containsI($query, $q)) {
         $hexed=1;
         $rex = $q.'.*?&';
         $query = string.regexsub( $query, $rex, "" );
      }
   }
   if ($hexed==1) {
      log.info("Cache-setkey rule: " . $orig . " #### " . $path.$query);
      http.cache.setkey( $path.$query );
   }

}

 

Hope one of you guys have a suggestion. I can say that the log.info() actually tells me this works. The $path.$query contains the correct values for all of the above examples.

 

André

 

5 REPLIES
Occasional Contributor

Re: Http cache and setkey

Found it ... I have misunderstood the setkey function. I thought it was pr request/url I could set it. But it is much more general.

 

André

Contributor

Re: Http cache and setkey

Hi Andre,

 

http.cache.setkey() is used to make requests for the same URL return different cache elements depending on the key, so unfortunately it can't be used to accomplish what you're trying to do.  Let me think about this for a bit and see if there is a good way to have different URLs return the same cache element.

 

Faisal

Occasional Contributor

Re: Http cache and setkey

Thank you for your answer

 

We are also looking into doing something in our application, so the request hitting our servers is served from an application cache, tweaking our response times that way.

 

But if there is a genereal way to do something like that in the loadbalancer, that would be sweet.

 

So I have made a feature request for this. On a nice-to-have basis.

 

André

Contributor

Re: Http cache and setkey

Hi Andre,

 

The only way I can see to have different requests return the same cached object is to make the URL the same.  If you can modify the application, how about moving the query string out of the URL and into a custom HTTP header?  That way the URL will still match and the content should be served from the cache.

 

Faisal

Occasional Contributor

Re: Http cache and setkey

Yes, that is a way to go. Only, I don't have the power to change the application. We are a fairly large company, and I have made some suggestions to not use the url for client side tracking services, but that is pretty hard to convince people about.

 

Thank you for your time, I will try and prep people here to do these parameters in a different way than through the URL.

 

André