Hello,
I am integrating my OpenResty based proxy with Oracle coherence cache server. Below is the logic.
1. Check if exist in the proxy_cache, if found return response. If not, proxy_pass to internal coherence_cache location
2. Check if exist in the coherence cache using ngx.capture.location, if response found, return response. If not ngx.location.capture to upstream location
3. In upstream location, proxy pass to upstream server and return the response
4. In coherence_cache location, read the response and store into coherence cache using ngx.capture.location
5. Send the response back
Here, to use the proxy_cache, I am using proxy_pass to route to internal location. Ideally ngx.location.capture would be more efficient as there is no new HTTP request/body needs to be created + it doubles numbe of HTTP connections. I assume it will use two additional (client/upstream) connection per proxy_pass.
Is there any way to use ngx.location.capture + proxy_cache?
location /
{
proxy_cache data_cache;
#other proxy cache related settings
proxy_pass http://127.0.0.1/coherence;
more_headers "X-Status: $upstream_cache_response"
}
location /coherence
{
rewrite_by_lua_block {
-- check coherence cache
res = ngx.location.capture("/coherence_read/key", .....)
if res then
return ngx.say(res.body)
ngx.header["X-Cache-Coherence"]="HIT"
end
---send it to upstream server
res = ngx.location.capture("/upstream_server")
if res then
-- save to coherence server
ngx.location.capture("/coherence_write/key", {method=ngx.PUT, res.body})
end
-- return response
ngx.header["X-Cache-Coherence"]="MIT"
return ngx.say(res.body)
}
}
location /coherence_read
{
proxy_pass http://coherence_server/key;
}
location /coherence_write
{
proxy_method PUT;
proxy_pass http://coherence_server/key;
}
location /upstream_server
{
proxy_pass http://external_server;
}