Merge pull request #605 from NebulousLabs/add-registry-entries-resolution-caching
Add registry entries resolution caching
This commit is contained in:
commit
abbcb1a7d8
|
@ -192,7 +192,7 @@ server {
|
||||||
local datakey = hnsres_json.registry.datakey
|
local datakey = hnsres_json.registry.datakey
|
||||||
|
|
||||||
-- make a get request to /skynet/registry endpoint with the credentials from text record
|
-- make a get request to /skynet/registry endpoint with the credentials from text record
|
||||||
local registry_res = ngx.location.capture("/skynet/registry?publickey=" .. publickey .. "&datakey=" .. datakey)
|
local registry_res = ngx.location.capture("/skynet/registry/cached?publickey=" .. publickey .. "&datakey=" .. datakey)
|
||||||
|
|
||||||
-- we want to fail with a generic 404 when /skynet/registry returns anything but 200 OK
|
-- we want to fail with a generic 404 when /skynet/registry returns anything but 200 OK
|
||||||
if registry_res.status ~= ngx.HTTP_OK then
|
if registry_res.status ~= ngx.HTTP_OK then
|
||||||
|
@ -250,6 +250,24 @@ server {
|
||||||
proxy_pass http://handshake-api:3100;
|
proxy_pass http://handshake-api:3100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# internal registry endpoint that caches calls for a certain period of time
|
||||||
|
# it is not suitable for every registry call but some requests might be cached
|
||||||
|
# and we are using it currently for caching registry resolutions from /hns calls
|
||||||
|
location /skynet/registry/cached {
|
||||||
|
internal; # internal endpoint only
|
||||||
|
access_log off; # do not log traffic
|
||||||
|
|
||||||
|
proxy_cache skynet;
|
||||||
|
proxy_http_version 1.1; # upgrade if necessary
|
||||||
|
proxy_cache_key publickey=$arg_publickey&datakey=$arg_datakey; # cache based on publickey and datakey
|
||||||
|
proxy_cache_valid 200 30s; # cache only 200 responses and only for 30 seconds
|
||||||
|
proxy_cache_lock on; # queue cache requests for the same resource until it is fully cached
|
||||||
|
proxy_cache_bypass $cookie_nocache $arg_nocache; # add cache bypass option
|
||||||
|
add_header X-Proxy-Cache $upstream_cache_status; # add response header to indicate cache hits and misses
|
||||||
|
|
||||||
|
http://127.0.0.1/skynet/registry$is_args$args;
|
||||||
|
}
|
||||||
|
|
||||||
location /skynet/registry {
|
location /skynet/registry {
|
||||||
include /etc/nginx/conf.d/include/cors;
|
include /etc/nginx/conf.d/include/cors;
|
||||||
include /etc/nginx/conf.d/include/sia-auth;
|
include /etc/nginx/conf.d/include/sia-auth;
|
||||||
|
|
Reference in New Issue