Writing a cache module

I need to write cache module that’s not upstream based. (Long story…)

Reading through the upstream code and the proxy and fastcgi modules, it
looks fairly simple.

Just so I know I’m on the right track:

  • to get something from cache I should generate a key for r->cache, try
    to
    open file using ngx_http_file_cache_open, then “serve” it using
    ngx_http_cache_send (or replicate what it does).

-to store something in cache, create a ngx_temp_file_t store my data in
there, generate a key, then call ngx_http_file_cache_update to add that
file
to cache.

Is that reasonable? Any gotchas?

On Mon, Sep 28, 2009 at 03:06:25PM -0400, Akins, Brian wrote:

-to store something in cache, create a ngx_temp_file_t store my data in
there, generate a key, then call ngx_http_file_cache_update to add that file
to cache.

Is that reasonable?

Yes.

Any gotchas?

Do not forget ngx_http_file_cache_free() for noncacheable responses.

On 9/28/09 3:06 PM, “Brian A.” [email protected] wrote:

I need to write cache module that’s not upstream based. (Long story…)

Actually maybe someone else has some pointers so I may not have to start
from scratch.

Basically, I need to replicate how apache’s mod_cache works (but faster
of
course - that’s why I’m playing with nginx.)

What it does, is the handler runs really early in the response. On a
cache
hit, it short circuits the filter stack (skipping gzip, ssi, etc.) and
serves to client.

It stores things in cache after most of the filter stack (after, ssi,
gzip,
etc.)

It uses vary. I think in nginx, for my purposes at least, I could just
use
configuration to control behavior of the cache key.

Here’s a talk from apachecon I did a few years ago to give a hint at
what
I’m wanting to do: http://www.akins.org/files/apachecon-cnn-good.pdf

I’m pretty sure I can get equal, and actually better, functionality from
nginx, but just wondering if someone else had attempted it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs