Forum Discussion

Henrik_Janhagen's avatar
Icon for Nimbostratus rankNimbostratus
Sep 16, 2011

HTTP::uri rewrites in combination with RAM cache

Hello, I have bit of a problem with HTTP::uri rewrites in combination with RAM cache.



My problem is that the application I have running on my VIP is called with uri's like this:



...but the developers wants this to hit the underlying realservers with the "unique=6_26&" part removed. (I asked them to remove it from the calling application but no dice :) )



So. I wrote a little iRule like this:




regsub -nocase unique=.*& [HTTP::uri] "" HTTP::uri




...and that worked just fine for awhile.



Now however these same developers want me to cache the responses to these rewitten calls in RAM cache on the F5. I.e. if two end-users makes two calls each like this:


user 1 calls ,




user 2 callstwice.


(note the difference in the links? The only difference is the value of 'unique')



The loadbalancer should then only make ONE call to the real servers. (Since once the uri has been re-written "in-flight" for these two calls they are exactly the same).



However that is not what is happening when I enable caching on my VIP. Instead both users have 1 call each passed to the realservers. My gut feeling is that I need to play with CACHE::uri somehow so that the cache created from user 1's first call is used when user 2 makes his calls.


But I just can't figure out how to do that.



I hope my question makes sense... English is not my native language. :)



Best Regards




3 Replies

  • Hi Janhagen,



    Try using: CACHE::uri [HTTP::path]



    This should cache and return the base path (minus the [HTTP::query]), thereby removing the uniqueness.



    You can reference the CACHE::uri command here:

  • Hello Michael and thanks for your reply!

    But if I do that won't I reply to ALL requests for '.../service?' with the same cache?


    .../service?unique=1&lang=en&market=1 and .../service?unique=2&lang=en&market=1 should get the same cache

    .../service?unique=1&lang=en&market=1 and .../service?unique=1&lang=da&market=2 should not see the same cache (since here the market and language have changed.

    I tried this:

    when HTTP_REQUEST {
      if { [string tolower [HTTP::uri]] contains "unique" } {
        regsub -nocase {unique=.*&} [HTTP::uri] "" uri
        CACHE::uri $uri
        HTTP::uri $uri

    But that doesn't seem to work. (In fact it seems to kill the cache completely since then all requests to .../service? then hit the realservers)

    Best Regards

    Henrik Janhagen

  • Hehe...

    As an old Perl-miscreant I should have read my own rule more carefully. It appears that tcl (like Perl) prefers "greedy match" to "sparse match". So my error was in :


    It should of course have read


    The iRule posted above works now. Still; Thank you Michael for wanting to help me!

    Best Regards

    Henrik Janhagen