Francis Daly
February 05, 2019 07:34PM
On Fri, Jan 25, 2019 at 03:28:42PM -0500, nenaB wrote:

Hi there,

None of the suggestions below are fully tested by me, so they are not
drop-in answers to your questions.

> I have nginx configured to cache certain requests mapped by
> tenant/host/uri/args - these files wouldn't change often, but if they do, i
> want nginx to fetch them new.
>
> I don't have NginxPlus - and I'm running Nginx docker. Some things that I
> have investigated, but not sure how I could configure to make it work is:
> the proxy_cache_bypass and the expires settings.

"Normal" caching involves nginx accepting what the upstream says the
expiry time of the response is.

If you want nginx to check upstream for new content before that expiry
time, you either need to purge nginx's cache for that request, or to
bypass the cache for the request.

I think that there is not an explicit "purge" facility in the stock
nginx. But there is the proxy_cache_bypass directive.

You can perhaps try a third-party module for purging elements from the
cache. Or set up your system such that big or expensive content never
expires, and instead have small or lightweight content that links to
the "current" big content, and the link is updated when new big content
is available.

Or you can just use proxy_cache_bypass.

If you know by some external means that the content that claimed to
be valid for the next month, is now in fact stale; then you can make
a request of nginx for the content while including some "please bypass
the cache" flags in the request, and nginx should make the request of
upstream, and store the response such that the next "normal" request
will get the new response.

> What exactly do I need to configure if
> I want to test whether for a given cache-key on the upstream server, is
> there new content? (I can implement an api that could test whether new
> content is available.)

I am assuming that you know when content has been changed, and you want
to tell nginx to refresh its cache even though nginx was previously told
that the content would not have changed yet.

In that case: ignore the cache key. Just make the normal request; but
make it from a specific source IP address and/or include a specific header
in the request, that causes your proxy_cache_bypass variable to be non-zero.


If you do not know whether the upstream content has changed or not,
perhaps you could set a short "expiry" time within nginx, and use
proxy_cache_revalidate to "refresh" the validity without re-fetching
the content?

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

bypassing and replacing cache if origin changed - or purging cache when origin changed?

nenaB January 25, 2019 03:28PM

Re: bypassing and replacing cache if origin changed - or purging cache when origin changed?

Francis Daly February 05, 2019 07:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 69
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready