I tried using ngx.location.capture inside body_rewrite_by_lua to send request to coherence cache but getting error ngx.timer is disabled.
I tried replacing body_filter_by_lua with log_by_lua but getting errors.
body_filter_by_lua '
local function write_to_coherence(resp_headers)
ngx.log(ngx.DEBUG, "Timer expired. invoking write_to_coherence()")
local capi_util = require("common.utils")
local chunk, eof = ngx.arg[1], ngx.arg[2]
local buffered = ngx.ctx.buffered
if not buffered then
buffered = {}
ngx.ctx.buffered = buffered
end
if chunk ~= "" then
buffered[#buffered + 1] = chunk
ngx.arg[1] = nil
end
if eof then
local resp_body = table.concat(buffered)
ngx.ctx.buffered = nil
ngx.arg[1] = resp_body
local resp = {}
resp["headers"] = resp_headers
resp["body"] = resp_body
resp["status"] = ngx.status
local resp_json = capi_util.lua_to_json(resp)
local options = { copy_all_vars = true, method = ngx.HTTP_PUT, body=resp_json }
local result = ngx.location.capture("/coherence_set" .. "?key=" .. ngx.var.custom_cache_key , options)
end
end -- function write_to_coherence() end
local resp_headers = ngx.resp.get_headers(100, true)
local ok, err = ngx.timer.at(0, write_to_coherence, resp_headers)
';