From dab62fab34b29389d1b27b1394e41b755c998201 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 23 Aug 2022 09:22:35 +0800 Subject: [PATCH 1/4] bump lua-resty-mlcache to 2.6.0 --- kong-3.0.0-0.rockspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong-3.0.0-0.rockspec b/kong-3.0.0-0.rockspec index eb97cb890b4..a4dfce706e2 100644 --- a/kong-3.0.0-0.rockspec +++ b/kong-3.0.0-0.rockspec @@ -34,7 +34,7 @@ dependencies = { "lua-protobuf == 0.3.3", "lua-resty-worker-events == 1.0.0", "lua-resty-healthcheck == 1.6.1", - "lua-resty-mlcache == 2.5.0", + "lua-resty-mlcache == 2.6.0", "lua-messagepack == 0.5.2", "lua-resty-openssl == 0.8.10", "lua-resty-counter == 0.2.1", From 7c312f5850e5f46ca07a381c4d67251c39e2abda Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 23 Aug 2022 09:26:19 +0800 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeaa0ba03ed..db31ec23201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -288,6 +288,8 @@ [#8845](https://github.com/Kong/kong/pull/8845) - Bumped penlight from 1.12.0 to 1.13.1 [#9206](https://github.com/Kong/kong/pull/9206) +- Bumped lua-resty-mlcache from 2.5.0 to 2.6.0 + [#9287](https://github.com/Kong/kong/pull/9287) ### Additions From af0214558581f38b7c283b1ec1aa60a211a80915 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 23 Aug 2022 15:39:41 +0800 Subject: [PATCH 3/4] cache marshall with string.buffer --- kong/cache/marshall.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kong/cache/marshall.lua b/kong/cache/marshall.lua index 2cc904d1bb9..cca9a70f6c1 100644 --- a/kong/cache/marshall.lua +++ b/kong/cache/marshall.lua @@ -1,15 +1,23 @@ ------------------------------------------------------------------------------- -- NOTE: the following is copied from lua-resty-mlcache: -- ------------------------------------------------------------------------ cut -- -local cjson = require "cjson.safe" +local codec +do + local pok + pok, codec = pcall(require, "string.buffer") + if not pok then + codec = require "cjson" + end +end local type = type +local pcall = pcall local error = error local tostring = tostring local fmt = string.format local now = ngx.now -local cjson_encode = cjson.encode +local encode = codec.encode local TYPES_LOOKUP = { @@ -42,12 +50,12 @@ local marshallers = { end, [4] = function(t) -- table - local json, err = cjson_encode(t) - if not json then - return nil, "could not encode table value: " .. err + local pok, str = pcall(encode, t) + if not pok then + return nil, "could not encode table value: " .. str end - return json + return str end, } From 407782e6efa6da0e8ca3893e8edf144cd3afd658 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 23 Aug 2022 15:44:37 +0800 Subject: [PATCH 4/4] style fix --- kong/cache/marshall.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kong/cache/marshall.lua b/kong/cache/marshall.lua index cca9a70f6c1..31c15be1c24 100644 --- a/kong/cache/marshall.lua +++ b/kong/cache/marshall.lua @@ -3,11 +3,11 @@ ------------------------------------------------------------------------ cut -- local codec do - local pok - pok, codec = pcall(require, "string.buffer") - if not pok then - codec = require "cjson" - end + local pok + pok, codec = pcall(require, "string.buffer") + if not pok then + codec = require "cjson" + end end