2 locations, 2 _different_ cache valid settings, but same cache & pass-through

randyorbs randyorbs at protonmail.com
Fri Mar 27 18:59:05 UTC 2020


> What is the thing that you want to achieve?

I have two clients, foo and bar. I charge foo to hit /foo and bar to hit /bar at different rates/costs. They've both agreed that the data can be stale, but how stale is different for each - 5 minutes for foo, 10 minutes for bar. Very often, foo and bar (though using different end-points) are making the exact same requests and getting the exact same responses.

I too get charged for hitting /myhost.io/go when my clients hit /foo and /bar.

I want to limit how often I hit /myhost.io/go to reduce costs, but also ensure I fulfill my "how stale is OK" agreements with my clients.

What I need is a cache of data that is aware that the validity of its data is dependent on who - foo or bar - is retrieving it. In practice, this means that requests from both foo and bar may be responded to with cache data from the other's previous request, but most likely the cache will be populated with responses to foo's requests to the benefit of bar, which is fine.

It would be great if I could config my way into a solution to my use-case using NGINX.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, March 27, 2020 1:21 AM, Francis Daly <francis at daoine.org> wrote:

> On Tue, Mar 24, 2020 at 11:15:59PM +0000, randyorbs wrote:
>
> Hi there,
>
> > 4.  use different cache valid settings...
> >     location /foo {
> >     proxy_pass "http://myhost.io/go";
> >     proxy_cache shared_cache;
> >     proxy_cache_valid any 5m;
> >     }
> >     location /bar {
> >     proxy_pass "http://myhost.io/go";
> >     proxy_cache shared_cache;
> >     proxy_cache_valid any 10m;
> >     }
> >
> >
> > What I have found is that I can request /foo, then /bar and the /bar result will be an immediate HIT on the cache, which is good - the keys are the same and they are both aware of the cache. However, now that I've requested /bar any requests to /foo will result in cache HITs for 10 minutes instead of the 5 minutes I want. If I never hit /bar, then /foo will cache HIT for the correct 5 minutes.
> > Any thoughts on how I can use NGINX to configure my way into a solution for my unusual (?) use-case?
>
> The nginx cache file structure includes the validity period within the
> stored object file.
>
> The system does not care how the object file got there; it cares about
> the file name and file contents.
>
> So, "no".
>
> (At least, not without writing your own special-case caching system.)
>
> What is the thing that you want to achieve? Perhaps there is an alternate
> way to get to the same desired end result.
>
> f
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Francis Daly francis at daoine.org
>
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx




More information about the nginx mailing list