Forum Discussion
May 11, 2007
There are several ways you can cleanly add multiple extensions to compare against..pdf
1. Use a switch statement with file globbing (much more optimal than regular expressions.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"*.jpg" -
"*.gif" -
"*.swf" -
"*.pdf" -
"*.xml" {
CACHE::uri [HTTP::host][HTTP::path]
}
}
}
I'm not sure how this performs compared to an equivalent set of chained "or" expressions using the ends_with operator. It's most likely fairly equal so I'd go with the approach that is easier to read to you.
2. using a data group (aka class) to contain the extensions and then using the matchclass command to search that list. Only go this route if you need to externalize your list and/or the items in your list number more than 100. It's been calculated that for items under 100 a switch with globbing is a little faster than a matchclass.
bigip.conf rendering on the class
class cache_extensions {
.jpg
.gif
.swf
.xml
}
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::path]] ends_with $::cache_extensions] } {
CACHE::uri [HTTP::host][HTTP::path]
}
}
We've got a topic in the wiki that goes over some general rules of thumb for writing fast iRules.
http://devcentral.f5.com/wiki/default.aspx/iRules/HowToWriteFastRules.html
Click hereGood luck and let us know if you find anything interesting during your implementation.
-Joe