Forum Discussion

b_seweryn_15157's avatar
b_seweryn_15157
Icon for Nimbostratus rankNimbostratus
Dec 30, 2015

expiresByType caching

hi,

can i configure caching like in apache? I have to implement below few lines for one VS.

ExpiresByType text/javascript "access plus 12 hours"
ExpiresByType image/gif "access plus 12 hours"
ExpiresByType image/jpg "access plus 12 hours"
ExpiresByType image/jpeg "access plus 12 hours"
ExpiresByType image/png "access plus 12 hours"
ExpiresByType application/x-shockwave-flash "access plus 12 hours"

can you help me with this?

3 Replies

  • Here's an old detailed example of what it appears you are trying to accomplish. I've swapped out the findclass command (deprecated in v10+) with the class command:

    when HTTP_REQUEST { 
      if {[HTTP::method] eq "GET" and [HTTP::uri] eq "/"}{ 
        set expire_content_timeout 300 
      } else {
          set extention [string tolower [string range [HTTP::path] [string last . [HTTP::path]] end]]
          set expire_content_timeout [class match -value $extention equals cache_timers_by_filetype] 
      } 
    } 
    
    when HTTP_RESPONSE { 
      if { $expire_content_timeout ne "" } { 
        HTTP::header replace "Cache-Control" "max-age=$expire_content_timeout, public" 
        HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+$expire_content_timeout)] -format "%a, %d %h %Y %T GMT" -gmt true]" 
      } else {    
          HTTP::header replace Expires {-1}     
      } 
    }
    

    The data-group format from that old example has changed as well:

    ltm data-group internal cache_timers_by_filetype {
        records {
            .bmp {
                data 86400
            }
            .css {
                data 3600
            }
            .gif {
                data 86400
            }
            .htm {
                data 300
            }
            .html {
                data 300
            }
            .ico {
                data 604800
            }
            .jpeg {
                data 86400
            }
            .jpg {
                data 86400
            }
            .js {
                data 3600
            }
            .pdf {
                data 604800
            }
            .png {
                data 86400
            }
            .swf {
                data 604800
            }
        }
        type string
    }
    
  • i see below warning/errors. nothing else:

     

    Warning generated : /Common/cache_2:13: warning: [use curly braces to avoid double substitution][([clock seconds]+$expire_content_timeout)]

     

    and i don't know why from time to time this one (but it is rare error): err tmm[9390]: 01220001:3: TCL error: /Common/cache_2 - can't read "expire_content_timeout": no such variable while executing "if { $expire_content_timeout ne "" } { HTTP::header replace "C ache-Control" "max-age=$expire_content_timeout, public" HTTP::header replace "..."

     

  • ok, i fixed above errors. now logs is clear. It should looks like that:

     HTTP::header replace "Expires" "[clock format [expr {[clock seconds]+$expire_content_timeout}] -format "%a, %d %h %Y %T GMT" -gmt true]" 
    

    now all data types have such age:

    Cache-Control:max-age=300, public