Welcome! Log In Create A New Profile

Advanced

Checking multiple caches before forwarding request to upstream

April 06, 2017 06:45AM
Hi,

We want to define multiple caches based on certain request headers (time stamp) so that we can put files modified in last 10 days on SSDs, last 30 days on HDDs and so on. I understand that we could use map feature to pick a cache dynamically which is good and works for us.

But when serving a file, we want to check in all the caches because file modified in last 11 days could still be on SSDs, so we don't wan't to unnecessarily pull it out from backend and put it on HDDs.

so net, net we want to check multiple caches before pulling from the backend. Is there a way to do that? We can only define one proxy_cache in a location block, so I figured if we some how use try files or error page attribute to failover multiple blocks and check one cache in each block, we could check multiple caches.

following is my simplified config:

server {
listen 7800 ;
server_name localhost;
resolver 8.8.8.8 ipv6=off;

location / {

set $served_by "cache";
set $cache_key $request_uri;
proxy_cache cache_recent;
proxy_cache_key $cache_key;

error_page 418 = @go-to-cloud-storage; return 418;
#try_files /does-not-exist @go-to-cloud-storage;

}

location @go-to-cloud-storage {
set $served_by "cloud";

proxy_cache cache_recent;
proxy_cache_key $cache_key;

proxy_set_header Host $host;
proxy_pass https://$http_host$request_uri;
}

}

But in the above config, @go-to-cloud-storage storage is always executed even when object is in cache for the / block.

Thanks
Sachin
Subject Author Posted

Checking multiple caches before forwarding request to upstream

sachin.shetty@gmail.com April 06, 2017 06:45AM

Re: Checking multiple caches before forwarding request to upstream

Maxim Dounin April 06, 2017 10:56AM

Re: Checking multiple caches before forwarding request to upstream

sachin.shetty@gmail.com April 06, 2017 11:04AM

Re: Checking multiple caches before forwarding request to upstream

sachin.shetty@gmail.com April 07, 2017 11:53AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 310
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready