Forum Discussion

Leslie_South_55's avatar
Leslie_South_55
Icon for Nimbostratus rankNimbostratus
Jul 26, 2007

caching with class

I have defined the following class's in my bigip.conf


class CacheableURI  {
   "/config/CacheableURI"
}
class CacheableObjects  {
   "/config/CacheableObjects"

the CacheableURI file contains 2 lines like


"/DIR1/DIR2/Portal/en_US/items.workflow"
"/DIR1/DIR2/Portal/en_US/offers.workflow"

the CacheableObjects file contains these lines


".css"
".gif"
".jpg"
".js"
".png"

and have the following iRule


when HTTP_REQUEST {
set uri [HTTP::uri]
if { [HTTP::version] eq "1.0" } {
  log local0. "HTTP::version = [HTTP::version]"
  log local0. "diabling cache"
  CACHE::disable
return
}
if { [matchclass [HTTP::uri] starts_with $::CacheableURI] and [matchclass [HTTP::uri] ends_with $::CacheableURI] }
 {
      log local0. "enabling cache for URI: [HTTP::uri]"
      CACHE::enable
    }
else {
CACHE::disable
log local0. "disabling cache for URI: [HTTP::uri]"
}
  }

I am getting some items in cache but others are not caching like I intend them to.

Here is some sample log output


Jul 26 14:23:06 tmm tmm[8636]: Rule rule_cache_disable : disabling cache for URI: /DIR1/DIR2/Portal/en_US/items.workflow:java-configure?x=x&sb=%3A00000025%3A0000005E%3A
Jul 26 14:22:59 tmm tmm[8636]: Rule rule_cache_disable : disabling cache for URI: /Static/images/floater/128.gif

can anyone see why these items are not being cached? and I am also not getting any hits on my


log local0. "enabling cache for URI: [HTTP::uri]"

Thanks

-L
  • Now that I look at it, I am not seeing anything in cache

     

     

    [root@ltm-1:Active] ramcache b profile http profile_test.test.com_http ramcache dump

     

    No RAM cache entries were found.

     

  • I have tried to "slim down" the rule to this

     

    when HTTP_REQUEST {

     

    set uri [HTTP::uri]

     

    if { $uri starts_with "CachableURI" and $uri ends_with "CachableObjects" } {

     

    CACHE::enable}

     

    else {

     

    CACHE::disable

     

    log local0. "disabling cache for URI $uri"

     

    }

     

    }

     

     

    and I am still getting log messages where the LTM is diabling cache for all requests
  • I am trying to match items in the external class files, either of the conditions can apply, so I changed my "and" statement between the "matchclass" statements to "or"...still does not appear to be working. If I remove the "else" statement at the end of the rule, it seems to work, but not all the time on the "CacheableURI" class.
  • Another quick clarification....and forgive me if my question seems simple, but...Caching HAS to be ENABLED in the HTTP profile for this to work..correct?

     

    -L
  • Yes. Your error log will confirm this and your site will probably not work.

    I've actually found that the best way to do this is to order your logic to where you "CACHE::disable" URI that shouldn't be cached and have a catchall. Be wary of "CACHE::enable" as it will override some of the cache directives in the profile. Look in the sample iRules for some idea's:

    http://devcentral.f5.com/wiki/default.aspx/iRules/UsingIRulesToManipulateCache.html

    I generally use the following format and it seems to work for our application:

    
     switch -glob [string tolower [HTTP::uri]] {
      "/uri1*" -
      "/uri2*" -
      "/uri3*" {
       CACHE::disable
       pool www.my.com_pool
      }
      default {
       pool www.my.com_pool
      }
     }
  • I agree it would be nice to specify the URIs that should not be cached, however in our app, the one's that should be cached consist of 2 URI strings and images, and the one's that should not be cached is everything else. So you can see that identifying the URI's that should not be cached is not possible.

     

     

    What about an "if {not [matchclass....]" statement, I could then use the CACHE::disable statement..thoughts?

     

     

    -L
  • Yup, that would probably be your best bet.

    
    when HTTP_REQUEST {
     if { !([matchclass [string tolower [HTTP::uri]] contains $::myclass]) } {
      CACHE::disable
      pool www.my.com_pool
     }
     else { 
      pool www.my.com_pool 
     }
    }
  • Finally got it. I realized that I was defining my external classes incorrectly in the bigip.conf, corrected by

     

    class CacheableURI {

     

    type string

     

    filename "/config/CacheableURI"

     

    }

     

    class CacheableObjects {

     

    type string

     

    filename "/config/CacheableObjects"

     

     

     

    and then calling the classes via the $::CacheableObjects using the if {not [matchclass ....CACHE:disable

     

     

    It all appears to be working now, many thanks to all the input and assistance.

     

     

    -L