Invalidate just one page under a location directive

Hi all,

A section of my virtual(say /industry) is cached with

proxy_cache_key $scheme$host$request_uri;

key. This will cache all pages under this virtual. I do cache
invalidation
by firing a request with

proxy_cache_bypass

Now if I need to invalidate cache for a page under this virtual, how
should
I go about doing it?

Say /industry is the location directive

I need to invalidate just

/industry/category/cars

How do I do this?

-Quintin

On Wednesday 08 February 2012 11:44:04 Quintin P. wrote:

The best way would be to create a location for this particular page:

location /industry/category/cars {

}

http://nginx.org/en/docs/http/ngx_http_core_module.html#location

also, you can utilize the map directive functionality, e.g:

map $uri $is_cached_uri {
default 1;
/industry/category/cars 0;
}

proxy_cache_bypass $is_cached_uri;

http://wiki.nginx.org/HttpMapModule

wbr, Valentin V. Bartenev

Thanks would be difficult because my intention is to maintain per page
cache. So we are talking about 1000+ pages and more being created
dynamically.

-Quintin

2012/2/8 Валентин Бартенев [email protected]

On Wednesday 08 February 2012 13:36:31 Quintin P. wrote:

Thanks would be difficult because my intention is to maintain per page
cache. So we are talking about 1000+ pages and more being created
dynamically.

Probably, I misunderstood. My solution switches cache off completely for
particular uri.

Maybe this module is useful for you:
http://labs.frickle.com/nginx_ngx_cache_purge/

wbr, Valentin V. Bartenev

08 февраля 2012, 13:37 от Quintin P. : > Thanks would be difficult
because my intention is to maintain per page > cache. So we are talking
about 1000+ pages and more being created > dynamically. > > -Quintin > >
2012/2/8 Валентин Бартенев > > > On Wednesday 08 February 2012 11:44:04
Quintin P. wrote: > > > Hi all, > > > > > > A section of my virtual(say
/industry) is cached with > > > > > > proxy_cache_key
$scheme$host$request_uri; > > > > > > key. This will cache all pages
under this virtual. I do cache > > invalidation > > > by firing a
request with > > > > > > proxy_cache_bypass > > > > > > Now if I need to
invalidate cache for a page under this virtual, how > > should > > > I
go about doing it? > > > > > > Say /industry is the location directive >

I need to invalidate just > > > > > > /industry/category/cars

How do I do this? Do you want to do per-request cache
invalidation based on client information (header values, cookies,
originating IP etc.), so the cache is bypassed whenever a client sends a
request that matches your cache invalidation criteria, or do you want to
be able to invalidate a certain URI for all future clients and requests
by sending some kind of “switch caching off for this URI” request? Max

Simples way to say this would be, invalidate proxy_cache_key but not all
of
the cache.

I was hoping for a solution from the vanilla builds

Can someone help? My small site on a tiny VM is being bombarded and the
cache invalidation is clearing up everything. Which means warming up the
caching takes a lot of expensive queries.

-Quintin

On 8 Fev 2012 15h59 WET, [email protected] wrote:

Can someone help? My small site on a tiny VM is being bombarded and
the cache invalidation is clearing up everything. Which means
warming up the caching takes a lot of expensive queries.

What cache invalidation? What caching strategy are you using?
Are working with a content based expiration logic or from a
microcaching perspective?

You can inspect the cache using a small shell script:

https://github.com/perusio/nginx-cache-inspector

— appa

I don’t think I made that clear.

To put it simply, Invalidate cache for a particular key entry but not
all
of the cache

e.g for

location = /vehicles {

proxy_cache_key $request_uri;

}

Hashtable for cache:

[

hittp://jj.com/vehicles/cars => hittp://jj.com/vehicles/cars

hittp://jj.com/vehicles/bus => hittp://jj.com/vehicles/bus

hittp://jj.com/vehicles/bike=> hittp://jj.com/vehicles/bike

]

I should be able to invalidate just cars because my page for cars have
changed but not others.

Hope you got the point.

Quintin

Invalidate a cache page using the bypass mechanism proxy_cache_bypass,
not
expiration

To put it simply, Invalidate cache for a particular key entry but not
all
of the cache

e.g for

location = /vehicles {

proxy_cache_key $request_uri;

}

Hashtable for cache:

[

http://jj.com/vehicles/cars => cached page for cars

http://jj.com/vehicles/bus => cached page for bus

http://jj.com/vehicles/bike=> cached page for bike

  • 10,000 key, values
    ]

I should be able to invalidate just “cars” because my page for cars have
changed but not others. Say a person added a comment in the cars page.
Another analogy is to invalidate cache for a single blog post when all
the
blog posts have been cached under a single location directive.
-Quintin

Thanks Antonio.

Great deal of help.

Looking into the wiki I see

“The following response headers flag a response as uncacheable unless
they
are ignored
http://wiki.nginx.org/HttpProxyModule#proxy_ignore_headers:

Set-Cookie

Cache-Control containing “no-cache”, “no-store”, “private”, or a
“max-age”
with a non-numeric or 0 value

Expires with a time in the past

X-Accel-Expires: 0“

This also means that if I send a curl call from my backend with a
Cache-Control : max-age=1, then the corresponding request/page in cache
will get invalidated the next second.

X-Accel-Expires also does the same thing I suppose. That solves my
dilemma.

-Quintin

On 8 Fev 2012 16h22 WET, [email protected] wrote:

Invalidate a cache page using the bypass mechanism
proxy_cache_bypass, not expiration

IMHO the best option would be from the application side send a
‘X-Accel-Expires: 0’ header. But this needs to be done at the app
level
.

Unless you place something in the headers that the application returns
Nginx there’s no way of Nginx to know what is going on.

To put it simply, Invalidate cache for a particular key entry but
not all of the cache

[

http://jj.com/vehicles/cars => cached page for cars

http://jj.com/vehicles/bus => cached page for bus

http://jj.com/vehicles/bike=> cached page for bike

  • 10,000 key, values
    ]

I should be able to invalidate just “cars” because my page for cars
have changed but not others. Say a person added a comment in the
cars page. Another analogy is to invalidate cache for a single blog
post when all the blog posts have been cached under a single
location directive. -Quintin

Send a ‘X-Accel-Expires: 0’ header from the application at:

http://jj.com/vehicles/cars

— appa

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