You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/10/28 00:59:16 UTC

[apisix] branch master updated: perf(proxy-cache): flush the body chunk during caching (#5340)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new bba6a00  perf(proxy-cache): flush the body chunk during caching (#5340)
bba6a00 is described below

commit bba6a0012b317bff656bdb614ae5e33150fc1920
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Thu Oct 28 08:57:49 2021 +0800

    perf(proxy-cache): flush the body chunk during caching (#5340)
---
 apisix/core/response.lua                      | 7 +++++--
 apisix/plugins/proxy-cache/memory_handler.lua | 4 +---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/apisix/core/response.lua b/apisix/core/response.lua
index 7b1128d..e1f0f4d 100644
--- a/apisix/core/response.lua
+++ b/apisix/core/response.lua
@@ -164,7 +164,7 @@ end
 --  ...
 --
 -- Inspired by kong.response.get_raw_body()
-function _M.hold_body_chunk(ctx)
+function _M.hold_body_chunk(ctx, hold_the_copy)
     local body_buffer
     local chunk, eof = arg[1], arg[2]
     if eof then
@@ -193,7 +193,10 @@ function _M.hold_body_chunk(ctx)
         end
     end
 
-    arg[1] = nil
+    if not hold_the_copy then
+        -- flush the origin body chunk
+        arg[1] = nil
+    end
     return nil
 end
 
diff --git a/apisix/plugins/proxy-cache/memory_handler.lua b/apisix/plugins/proxy-cache/memory_handler.lua
index 2fd4d11..5a76f9e 100644
--- a/apisix/plugins/proxy-cache/memory_handler.lua
+++ b/apisix/plugins/proxy-cache/memory_handler.lua
@@ -299,7 +299,7 @@ function _M.body_filter(conf, ctx)
         return
     end
 
-    local res_body = core.response.hold_body_chunk(ctx)
+    local res_body = core.response.hold_body_chunk(ctx, true)
     if not res_body then
         return
     end
@@ -318,8 +318,6 @@ function _M.body_filter(conf, ctx)
     if not res then
         core.log.error("failed to set cache, err: ", err)
     end
-
-    ngx.arg[1] = res_body
 end