Forum Discussion
What is most efficient way to setup http profile with ram cache
Having not used the ram cache feature at my previous position. I want to setup a simple ram cache to take some of the load off the web serve for images and some static items. I've search around the forum and have seen you can utilize the http profile along with an irule. But then also see that just using the ram cache is enough.
I would think it would be simple to list the standard images, ie .jpeg, .jpg, png etc.
Has anyone done any testing with a http profile and verified it is working and what were the results.
Sort of looking for an example and wondering what most people do.
Thanks for any info.
13 Replies
- Phil_53695
Nimbostratus
Hi,
Thanks for the reply. I used the standard template as you suggested and then did the irule below which will cache disable anything other than the files I listed.
I am going to see if it works and enabled the logging. Any good tips on testing or gather stats? Thanks again
when HTTP_REQUEST {
switch -glob [ string tolower [HTTP::uri]] {
"text/*javascript" -
"Scripts/*.js" -
"text/*.css" -
"image/*.swf" -
"image/*.gif" -
"image/*.png" -
"image/*.jpg" -
"image/*.jpeg"
{ CACHE::enable
log local0. "Caching [HTTP::uri]" }
else { CACHE::disable
log local0. "Non Caching [HTTP::uri]" }
}
} - Phil_53695
Nimbostratus
- extra switch pattern with no body
Does anyone know what this log message means? - Phil_53695
Nimbostratus
- extra switch pattern with no body
Does anyone know what this log message means? - Peter_72728
Nimbostratus
It could be caused by the "else" case. I think you want to use "default" there. - Phil_53695
Nimbostratus
extra switch pattern with no body while executing "switch -glob? - Kevin_Davies_40
Nacreous
Peter,
- Switch does not support an else statement.
-The S in "Scripts/*.js" should be s or it will never match.
- logging all traffic generates quite a lot of data - added debug flag. Set to 1 for testing, 0 for production.
The code should look like....when HTTP_REQUEST { set debug 0 switch -glob [string tolower [HTTP::uri]] { "text/*javascript" - "scripts/*.js" - "text/*.css" - "image/*.swf" - "image/*.gif" - "image/*.png" - "image/*.jpg" - "image/*.jpeg" { CACHE::enable if {$debug} { log local0. "Caching [HTTP::uri]" } } default { CACHE::disable if {$debug} { log local0. "Non Caching [HTTP::uri]" } } } }
JarvilTip - When pasting iRules put inside "code" blocks then submit, edit, submit to get the code looking like above.
- Phil_53695
Nimbostratus
Thanks for adding the info.I really appreciate it.I'm going to test it out this morning and then read up on how to gather some stats because I think that'll be the next thing they want to see. - Phil_53695
Nimbostratus
Hi All,
I have tried to test this irule but nothing of the items that are listed seem to be getting caches as shown below at
the ltm log
I do have an http profile setup for ram cache turned on.
ltm log:
"Non Caching /app_themes/default/images/icon.check.png"
Based on my irule, shouldn't the *.png be cached?
Below is the script and I suppose I am off somewhat. All I am trying to do is setup a simple RAM cache, add this irule in to see if it's working and then turn off debug. The customers will probably want to see some stats but first I need to ensure it works.
Any one know why?
when HTTP_REQUEST {
set debug 1
switch -glob [string tolower [HTTP::uri]] {
"text/*javascript" -
"scripts/*.js" -
"text/*.css" -
"image/*.swf" -
"image/*.gif" -
"image/*.png" -
"image/*.jpg" -
"image/*.jpeg" {
CACHE::enable
if {$debug} { log local0. "Caching [HTTP::uri]" }
}
default {
CACHE::disable
if {$debug} { log local0. "Non Caching [HTTP::uri]" }
{
HTTP::header replace "Cache-Control" "private, max-age=86400" }
}
}
}
when CACHE_REQUEST { log local0. "[CACHE::hits] cache hits for document at [HTTP::uri]" } - Peter_72728
Nimbostratus
Are you trying to do this check based on the request URI? I see HTTP::uri in your switch, but some of the values in the switch cases don't look like valid URI patterns.
First, HTTP::uri always starts with a "/". Secondly, you have other folders in your example path (/app_themes/default/images/icon.check.png) before the "image" folder in your switch case. So I think you need to change some of them as follows...when HTTP_REQUEST { set debug 1 switch -glob [string tolower [HTTP::uri]] { "text/*javascript" - this looks like a content type. Do you really have a URI pattern in the site that looks like this? "*/scripts/*.js" - needs to have a leading wildcard "text/*.css" - is this a content type, too? Or should it have a leading wildcard? "*/images/*.swf" - needs to have a leading wildcard -- and the "s" in "images" "*/images/*.gif" - "*/images/*.png" - "*/images/*.jpg" - "*/images/*.jpeg" ... - Phil_53695
Nimbostratus
Thanks for taking the time to repond. I understand it much better now and will adjust it accordingly and let the group know the out come.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
