Using iRules To Manipulate Cache¶
Description¶
when CACHE_REQUEST {
if { [CACHE::age] > 60 } {
switch -glob [string tolower [HTTP::uri]] {
"/shorttimer1/*" -
"/shorttimer2/*" -
"/shorttimer3/*" {
CACHE::expire
log local0. "Matched 60 seconds"
}
}
}
elseif { [CACHE::age] > 300 } {
switch -glob [string tolower [HTTP::uri]] {
"/fiveminutes1/*" -
"/fiveminutes2/*" -
"/fiveminutes3/*" {
CACHE::expire
log local0. "Matched 5 minutes"
}
}
}
}
when HTTP_REQUEST {
set mytime [clock seconds]
}
when HTTP_RESPONSE {
HTTP::header insert Last-Modified "[clock format $mytime -format "%a, %d %b %Y %T %Z"]"
HTTP::header insert Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
HTTP::header insert Cache-Control "post-check=0, pre-check=0, false"
HTTP::header insert Pragma "no-cache"
}
when HTTP_REQUEST {
if { [HTTP::cookie exists "tk_commenter"]} {
if { [string length [HTTP::cookie value "tk_commenter"]] } {
switch -glob [string tolower [HTTP::uri]] {
default {
log local0. "tk_commenter cookie exists, [IP::client_addr] has been passed to origin with cookie: [HTTP::cookie value "tk_commenter"]"
CACHE::disable
pool mypool
}
}
}
}
switch [string tolower [HTTP::path]] {
"/mt-comments.cgi" -
"/mt-search.cgi" -
"/mt.cgi" {
log local0. "mt-comments or mt.cgi accesses from [IP::client_addr]"
CACHE::disable
pool mypool
}
default {
pool mypool
}
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == 301 }{
CACHE::enable
}
}
The BIG-IP API Reference documentation contains community-contributed content. F5 does not monitor or control community code contributions. We make no guarantees or warranties regarding the available code, and it may contain errors, defects, bugs, inaccuracies, or security vulnerabilities. Your access to and use of any code available in the BIG-IP API reference guides is solely at your own risk.