Forum Discussion
David_Patino_20
May 04, 2012Nimbostratus
Instructing BigIP to expire RAM Cache when it receives a URL Query
Howdy Everyone.
I've an issue I've been working on.
I'm trying to develop a irule that will check the URI::query for an expire entry. If it finds one, it will instruct the system to do a CACHE...
GavinW_29074
May 21, 2012Nimbostratus
Caleb
I've done some testing here, and think I've got a working iRule...
Apologies, i've striped out some of your logic, however it should be easy enough to put back in...
Anyways, here's a copy of my iRule...
when RULE_INIT {
Debug variable
set static::ExpireRAMCacheDebug 1
}
when HTTP_REQUEST {
if { $static::ExpireRAMCacheDebug } { log local0. "Processing HTTP_REQUEST at Priority 500." }
Set default cache trigger value.
set expire_cache_trigger 0
Check if from authorized IP address.
if { [class match [IP::client_addr] equals Authorized_IPs] } {
Check HTTP::query for the expire param.
if { [string tolower [HTTP::query]] contains "expire" } {
Param present in HTTP::query
if { $static::ExpireRAMCacheDebug } { log "Request to expire [HTTP::uri] received." }
Set the expire trigger.
set expire_cache_trigger 1
Save a copy of the URI with the param and value removed
set uri [string map [list "expire" ""] [HTTP::uri]]
Replace && with & in the updated query string if && is present and set the URI to this
set uri [string map "&& &" $uri]
Check if there are no other query items
if { $uri contains "&" } {
Another query param exists
set uri [string map [list "?&" "?"] $uri]
Log the cached and updated values for the URI
log local0. "Other Query params present. Original URI: [HTTP::uri], updated URI: $uri"
HTTP::uri $uri
} else {
set uri [string map [list "?" ""] $uri]
Log the cached and updated values for the URI
log local0. "No Query params present. Original URI: [HTTP::uri], updated URI: $uri"
HTTP::uri $uri
}
}
}
}
when CACHE_REQUEST {
if { $static::ExpireRAMCacheDebug } { log local0. "Processing CACHE_REQUEST at Priority 500." }
Check for expire_cache_trigger
if { $expire_cache_trigger } {
Expire the CACHE entry.
if { $static::ExpireRAMCacheDebug } { log local0. "Expiring CACHE item $uri." }
CACHE::expire
Record the item expiry.
log "Cache Item $host$uri Expired"
Tidy up
unset expire_cache_trigger
}
}
It seems to work for me on some quick testing... Will give it a better run-down tomorrow...
Comments/Improvements welcome...
Cheers
Gavin
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects