Forum Discussion
Emre_27149
May 03, 2011Nimbostratus
disable ram cache while when get http error codes
Hi All, I have the below irule code but I also want to disable the ram cache feature when a backend server returned a http error codes (404, 303... ) to clients.So how can I need to update the rule t...
hooleylist
May 03, 2011Cirrostratus
Hi Emre,
Here's an option:
when HTTP_REQUEST {
set uri [HTTP::uri]
if { [ class match [HTTP::path] starts_with cache_obj] } {
CACHE::enable
log local0. "Caching [HTTP::path]"
} else {
log local0. "NON Caching [HTTP::path]"
CACHE::disable
}
}
when HTTP_RESPONSE {
Check the response status code
switch [HTTP::status] {
404 -
500 -
503 {
CACHE::disable
log local0. "Disabled cache for [HTTP::status] response to $uri"
}
default {
CACHE::enable
log local0. "Enabled cache for [HTTP::status] response to $uri"
}
}
}
If you wanted to enable caching only for 200, 301, 302, etc responses, you could flip the CACHE::enable/disable statements:
when HTTP_REQUEST {
set uri [HTTP::uri]
if { [ class match [HTTP::path] starts_with cache_obj] } {
CACHE::enable
log local0. "Caching [HTTP::path]"
} else {
log local0. "NON Caching [HTTP::path]"
CACHE::disable
}
}
when HTTP_RESPONSE {
Check the response status code
switch [HTTP::status] {
200 -
301 -
302 {
CACHE::enable
log local0. "Enabled cache for [HTTP::status] response to $uri"
}
default {
CACHE::disable
log local0. "Disabled cache for [HTTP::status] response to $uri"
}
}
}
Aaron
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