Forum Discussion
Robert_47833
Altostratus
Nov 14, 2011how to use switch to match datagroup
1:there is a datagroup:cjj
how to use switch to match this group
switch -glob [HTTP::path] {
"cjj" xxxx ???
2:
switch -glob [HTTP::path] { "*jpg" - "*bmp" - "*gif" - "*png" - "*img" - "*ico" - "*js" - "*css" - "*swf" - "*swz" - "*vbs" - "*html" - "*htm" - "*csv" - "*txt" - "*crossdomain.xml" {pool xyz}
in this case,should I create a variable uri to replace [HTTP::path] to make the irule more efficent?
25 Replies
- nitass
Employee
in this case ,I can save the output of HTTP::path to a variable,right? because I run [HTTP::path] 3 times
hmm,I should use variable if one command run more than 1 time,right?
as i understand, even you call HTTP::path three times, you do not run function against it. so, no i do not think you should use variable. - Robert_47833
Altostratus
hmm,can u show me in which case I should use variable to make it more efficent? - nitass
Employee
can u show me in which case I should use variable to make it more efficent?it is in 6 - Use Variables which you have mentioned.
uri variable is used instead of keep calling [string tolower [HTTP::uri]].
Ten Steps to iRules Optimization by Joe
http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/281/Ten-Steps-to-iRules-Optimization.aspx - Robert_47833
Altostratus
in my case,it is like 6
why do u tell me it is better to use[HTTP::path] instead of variable
switch -glob [HTTP::path] {
"*gif" -
"*png" {
switch -glob [HTTP::path] {
"/static.*" -
"/s.*" {
switch -glob [HTTP::path] {
"*cswebtool*" -
"*cobrands*" {
persist none
pool SRWD52-STATIC
return
}
}
}
}
} - nitass
Employee
it is like 5 rather than 6. - Robert_47833
Altostratus
hmm,I am a little confused
so if I use [string tolower [HTTP::uri]] many times,then,I need to use variable
but if I use [HTTP::uri] many times,then,I don't need to use variables,right?
oh
but u see Aaron's comment:
As you're only referencing HTTP::path once there isn't any reason to use a variable. If you were running an operation against a command multiple times you'd want to run it just once and then save the output to a variable. For example, if you were setting a URI to lower case and checking it multiple times, you'd want to save the lower case URI rather than running string tolower multiple times.
I do use [HTTP::path] many times - nitass
Employee
so if I use [string tolower [HTTP::uri]] many times,then,I need to use variable
but if I use [HTTP::uri] many times,then,I don't need to use variables,right?yes, that is what i understand.
If you were running an operation against a command multiple times you'd want to run it just once and then save the output to a variable.i understand operation means something such as string tolower ...
hope this helps. - hoolio
Cirrostratus
The value for [HTTP::path] is cached in memory the first time the command is run. However, if you perform an operation on the path, like [string tolower [HTTP::path]] that output is not cached. So in your example, if you're running [HTTP::path] multiple times, it's better to not save the value to a variable.
If you were checking the path set to lower case in multiple locations in the iRule, it would be more efficient to save the value to a variable versus running string tolower more than once.
Here are examples of the two different scenarios. I hope this is clearer for you.Example using no variable as [HTTP::path] is cached: switch -glob [HTTP::path] { "*gif" - "*png" { switch -glob [HTTP::path] { "/static.*" - "/s.*" { switch -glob [HTTP::path] { "*cswebtool*" - "*cobrands*" { persist none pool SRWD52-STATIC return } } } } } }
OrExample using a variable as [string tolower [HTTP::path]] is not cached: set path [string tolower [HTTP::path]] switch -glob $path { "*gif" - "*png" { switch -glob $path { "/static.*" - "/s.*" { switch -glob $path { "*cswebtool*" - "*cobrands*" { persist none pool SRWD52-STATIC return } } } } } }
Aaron - Robert_47833
Altostratus
ahhhh
Aaron and Nitass,thank u very much
this time I understand this well
hahha
it is a depth explanation of this question. - Robert_47833
Altostratus
Hi,Aaron
in this case
Example using no variable as [HTTP::path] is cached:
switch -glob [HTTP::path] {
"*gif" -
"*png" {
switch -glob [HTTP::path] {
"/static.*" -
"/s.*" {
switch -glob [HTTP::path] {
"*cswebtool*" -
"*cobrands*" {
persist none
pool SRWD52-STATIC
return
}
}
}
}
}
}
because [HTTP::path] is cached,so we don't need to set variable.
hmm,if I set uri [HTTP::path],it means every connection we have $uri and [HTTP::path] in memeory,right?(I am not sure this cached stuff can be used by other connection.)
so it is better not to use set uri [HTTP::path] to cache output of [HTTP::path] again,right?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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