diff options
-rw-r--r-- | aconf/model/node.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/aconf/model/node.lua b/aconf/model/node.lua index 0ce5016..bd62470 100644 --- a/aconf/model/node.lua +++ b/aconf/model/node.lua @@ -110,12 +110,20 @@ function M.TreeNode:init(context, params) return getmetatable(next)._fetch(path, create) end + local cache = {} + function mt.fetch(path, create) + local res = cache[path] + if res then return res end + if pth.is_absolute(path) and mt.path > '/' then assert(not create) - return mt.txn:fetch(path, mt.privileged) - end - return mt._fetch(pth.split(path), create) + res = mt.txn:fetch(path, mt.privileged) + + else res = mt._fetch(pth.split(path), create) end + + if isinstance(res, M.TreeNode) then cache[path] = res end + return res end |