Nginx Caching for specific location with regular expression

629 Views Asked by At

I want to cache the content from specific location only. But when i am trying to use regular expression, it is not caching.

proxy_cache_path /AINginxService/nginx-1.16.1/cache/ levels=1:2 keys_zone=one:10m max_size=8g inactive=5d use_temp_path=off;

proxy_cache one;    

    location ~* /v1/mydata/studies/[0-9.]+/series/[0-9.]+/instances/[0-9.]+/rendered {
        #rewrite http://([^/]+)/rendered break;
        proxy_cache_valid 200 120h;
        proxy_pass http://127.0.0.1:9000/v1/mydata;
        proxy_set_header Host $host;
        proxy_pass_request_headers on;
        proxy_http_version 1.1;
        proxy_set_header Origin "";
        proxy_connect_timeout 1d;
        proxy_send_timeout 1d;
        proxy_read_timeout 1d;
        send_timeout 1d;
    }

    # Rest api entry point
    location /v1/mydata {
        #proxy_cache_valid 200 120h;
        proxy_pass http://127.0.0.1:9000/v1/mydata;
        proxy_set_header Host $host;
        proxy_pass_request_headers on;
        proxy_http_version 1.1;
        proxy_set_header Origin "";
        proxy_connect_timeout 1d;
        proxy_send_timeout 1d;
        proxy_read_timeout 1d;
        send_timeout 1d;
    }
}

PS: If I uncomment proxy_cache_valid in /v1/mydata, it caches everything.
NOTE: Possible URL patterns

 1. /v1/mydata/studies/{study_id}/       # Not to cahce
 2. /v1/mydata/studies//series/{series_id}/      # Not to cache
 3. /v1/mydata/studies//series/{series_id}/instances/{instance_id}/    # Not to cahce
 4. /v1/mydata/studies//series/{series_id}/instances/{instance_id}/rendered     # Cache this
0

There are 0 best solutions below