From 90f3da7d8debb64a35be283df9e6b96e24fe282f Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Mon, 24 Mar 2014 15:34:45 +0200 Subject: model: cache TreeNode instances after fetching --- aconf/model/node.lua | 14 +++++++++++--- 1 file 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 -- cgit v1.2.3