# iRule RAM CACHE odd behaviour

**URL:** <https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707>\
**Category:** Technical Forums\
**Tags:** performance, irules, devops, application-delivery\
**Created:** [January 28, 2014, 4:36pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707 "2014-01-28T16:36:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 28, 2014, 4:36pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/1 "2014-01-28T16:36:51Z")

</div>

Hi, I am trying to cache and serve some content from the static contents of my .Net app. I have enabled the Cache on the HTTP profile, and applied the following rule to my Virtual Server:-

when HTTP\_REQUEST {

```tcl
set hostname [string tolower [HTTP::host]]
set uriadd [string tolower [HTTP::uri]]

if { [TCP::local_port clientside] == "443" } {

    if { $hostname == "someURL.test.co.uk" } {
        if { !([class match [IP::remote_addr] equals CUST_IP_Addresses])
          and !([class match [IP::remote_addr] equals MIC_IP_Addresses])
          and !([class match [IP::remote_addr] equals private_net]) } {
            drop  
        } else {
            CACHE::disable
            pool CUST-someURL.test.co.uk_443_POOL
        }

    } else {
        if { ( $uriadd ends_with ".js" ) ||
          ( $uriadd ends_with ".pdf" ) ||
          ( $uriadd ends_with ".css" ) ||
          ( $uriadd ends_with ".jpg" ) ||
          ( $uriadd ends_with ".png" ) ||
          ( $uriadd ends_with ".gif" ) } {
             enable the cache
            CACHE::enable
        } else {
             disable the cache
            CACHE::disable
        }

         mobile site
        if { $hostname == "someAURL.test.co.uk" } {
            pool CUST-someAURL.test.co.uk_443_POOL
        } elseif { ($hostname ends_with "test.co.uk") } {
            pool CUST-www.test.co.uk_443_POOL
        } elseif { ($hostname ends_with "test1.co.uk") } {
            pool CUST-test1.co.uk_443_POOL
        } else {
            pool CUST-test2.co.uk_443_POOL
        }

    }

 -----------------------------------------------------
 Handle HTTP requests
} else {

    if { $hostname == "someURL.test.co.uk" } {
        if { !([class match [IP::remote_addr] equals CUST_IP_Addresses])
          and !([class match [IP::remote_addr] equals MIC_IP_Addresses])
          and !([class match [IP::remote_addr] equals private_net]) } {
            drop  
        } else {
            CACHE::disable
            pool CUST-someURL.test.co.uk_80_POOL
        }

    } else {
        if { ( $uriadd ends_with ".js" ) ||
          ( $uriadd ends_with ".pdf" ) ||
          ( $uriadd ends_with ".css" ) ||
          ( $uriadd ends_with ".jpg" ) ||
          ( $uriadd ends_with ".png" ) ||
          ( $uriadd ends_with ".gif" ) } {
             enable the cache
            CACHE::enable

        } else {
             disable the cache
            CACHE::disable
        }

         mobile site
        if { $hostname == "someAURL.test.co.uk" } {
            pool CUST-someAURL.test.co.uk_80_POOL
        } elseif { ($hostname ends_with "test.co.uk") } {
            pool CUST-www.test.co.uk_80_POOL
        } elseif { ($hostname ends_with "test1.co.uk") } {
            pool CUST-test1.co.uk_80_POOL
        } else {
            pool CUST-test2.co.uk_80_POOL
        }

    }
}

 -----------------------------------------------------
 Tidy up variables
unset hostname uriadd

```

}

So i expect all assets that end in js, pdf, css, jpg, png, or gif to be cached and then served from the cache. however when i turn on log these cache hits in the local log, it lists the assets but says 0 cache hits for the identical assets over and over again. : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images-css/btn-close.png](http://www.bla.co.uk/Assets/bla/Images-css/btn-close.png) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/products/H/O/N/HONIPUPB\_AV2\_st.jpg](http://www.bla.co.uk/Assets/bla/products/H/O/N/HONIPUPB_AV2_st.jpg) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images-css/right-tab-selected.png](http://www.bla.co.uk/Assets/bla/Images-css/right-tab-selected.png) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images-css/left-tab-selected.png](http://www.bla.co.uk/Assets/bla/Images-css/left-tab-selected.png) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images-css/bg-resultsmenu.png](http://www.bla.co.uk/Assets/bla/Images-css/bg-resultsmenu.png) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images-css/bg-add-to-basket.png](http://www.bla.co.uk/Assets/bla/Images-css/bg-add-to-basket.png) : 0 cache hits for document at [www.bla.co.uk/Assets/bla/Images/btn-go.png](http://www.bla.co.uk/Assets/bla/Images/btn-go.png)

We have pretty much exactly the same rule running for the site serving the CMS and these are clearly showing cache hits of more than 0. if anyone can explain what is happening that would be great. we use 10.2.3, and dont have webaccelerator. Many thanks

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [January 29, 2014, 6:22am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/2 "2014-01-29T06:22:13Z")

</div>

Hi Bijan,

What does your HTTP profile look like? How do you view cache hits?

Have you tried adding the following (it will not fix your problem but may help shine light on why it’s not working as expected);-

```tcl
when CACHE_REQUEST {
    log local0. "Request for cached object $uriadd"
}
when CACHE_RESPONSE {
    log local0. "About to send cached response for $uriadd"
}

```

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 29, 2014, 9:46am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/3 "2014-01-29T09:46:03Z")

</div>

I’ve just added the cache response and there are no returned hits in the log.

Worth mentioning perhaps that this site has multiple white labels that run from the same IIS site and thus the same assets folder. so you could hit the same assets folder from 3 seperate [HTTP::HOSTS] but be sent to the same place. not sure what difference that will make?

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [January 29, 2014, 10:13pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/4 "2014-01-29T22:13:46Z")

</div>

See if this makes a difference - explicitly enabling/disabling CACHE from HTTP\_RESPONSE - apologies in advance - I have taken some liberties with the format of your original iRule (although retained the logic I hope);-

```tcl
when HTTP_REQUEST {
    set fCache 0
    switch -glob [string tolower [HTTP::host]] {
        "someURL.test.co.uk" {
            if { !([class match [IP::remote_addr] equals CUST_IP_Addresses])
            and !([class match [IP::remote_addr] equals MIC_IP_Addresses])
            and !([class match [IP::remote_addr] equals private_net]) } {
                drop 
                return
            } else {
                CACHE::disable
                pool "CUST-someURL.test.co.uk_[TCP::local_port]_POOL"
                return
            }
        }
        "someAURL.test.co.uk" {
            pool "CUST-someAURL.test.co.uk_[TCP::local_port]_POOL"
        }
        "*test.co.uk" {
            pool "CUST-www.test.co.uk_[TCP::local_port]_POOL"
        }
        "*test1.co.uk" {
            pool "CUST-test1.co.uk_[TCP::local_port]_POOL"
        } 
        default {
            pool "CUST-test2.co.uk_[TCP::local_port]_POOL"
        }
    }

    switch [getfield [string tolower [URI::basename [HTTP::path]]] "." 2] {
        "js" -
        "pdf" -
        "css" -
        "jpg" -
        "png" {
             enable the cache
            CACHE::enable
            set fCache 1
        }       
        default {
             disable the cache
            CACHE::disable
        }
    }
}
when HTTP_RESPONSE {
    if {$fCache} {
        CACHE::enable
    } else {
        CACHE::disable
    }
}

```

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 30, 2014, 9:30am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/5 "2014-01-30T09:30:19Z")

</div>

Thanks for that, I will attempt this on a staging site to see if it works. Worth mentioning though that the original code is in use and working for other sites, although slightly different logic, but the cache enable and disable rules are the same. Just this one customer that it is refusing to utilise the cache properly. Really appreciate your time. will let you know how it goes. thanks

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 30, 2014, 1:50pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/6 "2014-01-30T13:50:00Z")

</div>

no difference ☹ i suspect perhaps the RAM CACHE to be at fault in some way, either it has run out of space or it has some limitation that i am unaware of. I have added more sites to the RAM CACHE, they simply aren’t doing anything now, when i log cache request or response, not a sausage.

---

<div class="post-metadata">

**Author:** ![Scott\_Hopkins](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@Scott\_Hopkins](https://community.f5.com/u/Scott_Hopkins)\
**Post date:** [January 30, 2014, 2:35pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/7 "2014-01-30T14:35:19Z")

</div>

Quick thought… you’re using HTTP::uri, not HTTP::path. The URI could have other data (query strings, etc…) at the end, which could be messing with the ends\_with setting. We usually do something more like (where ‘static\_content’ is a data group of extensions we want cached):

```tcl
set VsRAMCacheState [PROFILE::http ramcache]
set content_extension [string range [HTTP::path] [string last . [HTTP::path]] end]
if { $VsRAMCacheState == 1 } {
    CACHE::disable
    if { [class match $content_extension equals static_content] }{
        enable
    } 
}

```

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [January 31, 2014, 12:49am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/8 "2014-01-31T00:49:38Z")

</div>

Bijan,

Could it be that the HTTP profile applied for the VIP for which caching IS working is different?

q Have you checked the profile?

tmsh ltm show profile http

Then look for “Cache Size” to tell if it has been allocated as you requested.

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [January 31, 2014, 12:50am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/9 "2014-01-31T00:50:24Z")

</div>

Sorry;

Have you checked the profile?

```tcl
tmsh 
ltm 
show profile http

```

Then look for “Cache Size” to tell if it has been allocated as you requested.

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 8:33am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/10 "2014-01-31T08:33:59Z")

</div>

I will see if I can get command line access and try this out. in terms of the GUI the profiles that are assigned have the same RAM CACHE details applied.

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 9:55am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/11 "2014-01-31T09:55:11Z")

</div>

you are right, it hasnt been assigned! RAM Cache Cache Size (in Bytes) 0 Total Cached Items 0 Total Evicted Items 0 Inter-Stripe Size (in Bytes) 0 Inter-Stripe Cached Items 0 Inter-Stripe Evicted Items 0 RAM Cache Hits/Misses Count Bytes Hits 11 5.4K Misses (Cacheable) 48 11.1K Misses (Total) 49 56.9G Inter-Stripe Hits 3 1.8K Inter-Stripe Misses 1.8M - Remote Hits 3 1.8K Remote Misses 1.8M -

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 10:04am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/12 "2014-01-31T10:04:03Z")

</div>

This is one that is working: RAM Cache Cache Size (in Bytes) 17.9M Total Cached Items 1.9K Total Evicted Items 12.5M Inter-Stripe Size (in Bytes) 3.0M Inter-Stripe Cached Items 393 Inter-Stripe Evicted Items 14.3M RAM Cache Hits/Misses Count Bytes Hits 142.5M 968.4G Misses (Cacheable) 13.8M 387.7G Misses (Total) 15.3M 1.8T Inter-Stripe Hits 92.0M 540.7G Inter-Stripe Misses 85.2M - Remote Hits 14.9M 186.0G Remote Misses 67.1M -

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 10:37am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/13 "2014-01-31T10:37:37Z")

</div>

GLOBAL HTTP STATISTICS | requests (total, max in conn, GET, POST) = (6.476G, 1.789M, 6.000G, 171.3M) | requests (v0.9, v1.0, v1.1) = (9375, 96.36M, 6.380G) | responses (v0.9, v1.0, v1.1) = (1983, 736752, 6.322G) | responses (2xx, 3xx, 4xx, 5xx) = (5.515G, 693.2M, 108.2M, 5.657M) | response size ( \<1k, 1-4k, 4-16k, 16-32k, 32-64k, 64-128k, 128-512k, 512k-2M, \>2M) | (1.937G, 1.354G, 1.632G, 592.3M, 366.1M, 229.5M, 168.7M, 24.13M, 14.48M) | Set-Cookie header insertions = 2 | RAM cache (entries, size, evict) = (17195, 363.9M, 12.54M) | RAM cache hit count (hits, misses, misses all) = (143.7M, 13.86M, 15.40M) | RAM cache byte count (hits, misses, misses all) = (978.0G, 388.6G, 1.941T) | Inter-stripe cache (entries, size, evict) = (17390, 162.2M, 14.37M) | Inter-stripe cache hit count (hits, misses, hit bytes) = (92.94M, 88.34M, 547.3G) | Remote cache hit count (hits, misses, hit bytes) = (14.96M, 70.06M, 186.7G)

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 10:47am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/14 "2014-01-31T10:47:54Z")

</div>

I’ve posted our RAM availability below as well. I’m really confused as i expect to be able to utilise a lot more RAM for the cache as there is about 4GB free and we can use 50% of it for RAM CACHE. if there are 4 tmm’s running then each should have 500MB. we are not close to the limits so why won’t it cache? I am now more confused than i was before getting SSH access to the machine 🙂

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 10:50am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/15 "2014-01-31T10:50:08Z")

</div>

here is the Free RAM stats from the machine:- [bijan@LMIC-BIGIP01:Active] ~ free total used free shared buffers cached Mem: 8187088 8120224 66864 0 77500 707412 -/+ buffers/cache: 7335312 851776 Swap: 1048568 850336 198232

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [January 31, 2014, 11:33am UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/16 "2014-01-31T11:33:33Z")

</div>

I think I have cracked it. We are out of available RAM in the units so it cannot assign any more RAM CACHE. The errors I expect based on the documentation from F5 are not appearing in the logs but this is my best guess. I’m waiting for our support contracts to be sorted out so that I can get an F5 engineer to confirm my suspicions, and then request more RAM and a software update.

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [February 2, 2014, 11:08pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/17 "2014-02-02T23:08:12Z")

</div>

Go and look at all the profiles you have assigned and add up the “Maximum Cache sizes” from the config. That’s the figure that you are using actually using per-TMM.

I assume you have seen this [404 Page not found | BIG-IP Documentation](http://support.f5.com/kb/en-us/solutions/public/12000/200/sol12225.html?sr=11064657)

Check your log for the error message - if you can’t find it as you have lost the logs try updating the profile that didn’t allocate (just change one thing) and save - you should see the error message then.

Go and look at what you are actually using compared to you Maximum cache size - you’ll probably find a few you can reduce the Maximum Cache Size on.

---

<div class="post-metadata">

**Author:** ![IheartF5\_45022](https://avatars.discourse-cdn.com/v4/letter/i/3be4f8/32.png) [@IheartF5\_45022](https://community.f5.com/u/IheartF5_45022)\
**Post date:** [February 2, 2014, 11:08pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/18 "2014-02-02T23:08:39Z")

</div>

I keep track of all mine in a spreadsheet.

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [February 4, 2014, 3:00pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/19 "2014-02-04T15:00:56Z")

</div>

so yes as per the previous post you can see that the utilised RAM is not yet at the 50% value. The red line isnt half way to the blue line yet 🙂 so in fact it isnt that we are out of RAM. I have raised a ticket with our suppliers to see if they can figure this one out. the free ram stats from the machine, show the overall used RAM, so i was really clutching at straws there.

---

<div class="post-metadata">

**Author:** ![Bijan\_141511](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Bijan\_141511](https://community.f5.com/u/Bijan_141511)\
**Post date:** [February 4, 2014, 3:06pm UTC](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707/20 "2014-02-04T15:06:20Z")

</div>

just to be sure i amended a http profile that wasnt working and looked for the errors in the log. no such luck sadly ☹ thanks for all your advice iHeartF5

[Next page](https://community.f5.com/t/irule-ram-cache-odd-behaviour/18707.md?page=2)
