Forum Discussion

dan_6764's avatar
dan_6764
Icon for Nimbostratus rankNimbostratus
Feb 09, 2009

Caching with an Irule issue

Hi,

 

I have a need to cache items that contain a certain uri and nothing else.

 

 

E.g I want to cache anything that has "f5" in it and let the rest pass through.

 

 

www.mydomain.com/f5/help - cache

 

www.mydomain.com/surround - don;t cache.

 

 

I an using a http-wan-optimized-compression-caching profile with the " http" as its parent. Ramcache is enabled.

 

 

My irule is as follows (applied to the relevant VIP, all that happens is that i cache everything. Can anyone help?

 

 

thanks

 

dan

 

 

 

 

 

when RULE_INIT {

 

set ::one_day 86400

 

}

 

when HTTP_REQUEST {

 

 

if { [HTTP::uri] contains "f5"} {

 

set cachetime $::one_day

 

} elseif { [HTTP::host] starts_with "http://" } {

 

CACHE::disable

 

}

 

}

 

 

 

 

 

2 Replies

  • The first problem is the line:

     

     

    } elseif { [HTTP::host] starts_with "http://" } {

     

     

    HTTP::host will never, ever 'start_with "http://" since HTTP::host is the hostname of the URL - i.e. www.domain.com. It does not include the protocol specifier.

     

     

    The second problem is that you can't set cache headers on HTTP_REQUEST since that rule is run when the connection comes _in_. Instead you need to apply your rule to the when HTTP_RESPONSE block.

     

     

    Then comes the issue that you're not actually setting the cache at all. All you're doing is setting a $cachetiem variable in your script, but you're not using it.

     

     

    What isn't clear is whether you're trying to control the LTM's caching of the object (how long LTM keeps the object in its cache) or whether you're trying to manipulate the client's browser cache. There are different solutions to the two approaches.

     

     

    The first one requires that you use CACHE:age to find out the age of the object in the LTM's cache, then use CACHE::expire to force the LTM to expire its current cached copy and fetch a fresh object from the server.

     

     

    The second option requires that you replace the Cache header in the HTTP response, using something like:

     

     

    HTTP::header replace Expires [clock format [expr ([clock seconds]+$cachetime)] -gmt true -format "%a, %d %b %Y %T %Z"]

     

  • Hi Thanks for this... think i know what i now need to do.

     

    thanks for your time.