# Status module – cache expiration, invalidation & poisoning

**URL:** <https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694>\
**Category:** NGINX\
**Created:** [October 14, 2012, 8:12pm UTC](https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694 "2012-10-14T20:12:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 14, 2012, 8:12pm UTC](https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694/1 "2012-10-14T20:12:20Z")

</div>

Hi all,

I have a website thats heavily cached or intended to be heavily cached  
via Nginx .

But somehow looking at the page response time I feeling there is a very  
high eviction/invalidation rate.

Now is there way I can look at the cache status in Nginx for different.  
I  
dont use the purge module.

The only way I check cache status is through

add\_header X-Cache-Status $upstream\_cache\_status;

I want to o/p the cache status to a RRD tool and look at the metrics.

Is this possible?

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 14, 2012, 8:33pm UTC](https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694/2 "2012-10-14T20:33:22Z")

</div>

On 14 Out 2012 20h11 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The only way I check cache status is through
> 
> add\_header X-Cache-Status $upstream\_cache\_status;
> 
> I want to o/p the cache status to a RRD tool and look at the  
> metrics.
> 
> Is this possible?

With Lua shouldn’t be that difficult. You just inspect the value of  
$upstream\_cache\_status.

ngx.var.upstream\_cache\_status paired with

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

to use a specific location to write to RRDtool.

Just an idea,  
— appa

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 14, 2012, 11:12pm UTC](https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694/3 "2012-10-14T23:12:56Z")

</div>

On 14 Out 2012 21h06 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Antonio,
> 
> Can you help me a bit more? I have never written in lua
> 
> Say for every hit I want to hit a rrd proxy like this
> 
> echo “$location\_url:1” | nc -w 1 -u [host.com](http://host.com) 8125

This is not the ideal option because AFAIK (agentzh can chime in to  
clarify things) the adding of the data to RRDtool will “hang” your  
reply.

Ideally you should have a “frontend” location that issues two  
subrequests one to write to RRDtool and another to get the response. I  
don’t think that in this particular case it will be dramatic. Try it  
and see if you can live with it.

> how do I go about doing this in lua?

Try:

location /whatever-is-your-location {  
header\_filter\_by\_lua ’  
if ngx.var.upstream\_cache\_status == “HIT” and os.execute("echo "  
.. ngx.var.location\_url .. “:1 | nc -w 1 -u [host.com](http://host.com) 8125”) == 0 then  
ngx.header[“X-RRDtool”] = “YES”  
end  
';  
}

This adds a header X-RRDtool if successfull. I stress that this is not  
the most performant way to do this. The Lua module can create sockets,  
so the best option would be to use that facility and get rid of netcat  
IMO.

This is more of a hack than aything else. Perhaps is performant enough  
for your application.

YMMV,  
— appa

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 14, 2012, 9:07pm UTC](https://www.ruby-forum.com/t/status-module-cache-expiration-invalidation-poisoning/223694/4 "2012-10-14T21:07:15Z")

</div>

Hi Antonio,

Can you help me a bit more? I have never written in lua

Say for every hit I want to hit a rrd proxy like this

echo “$location\_url:1” | nc -w 1 -u [host.com](http://host.com) 8125

how do I go about doing this in lua?
