diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-24 15:34:45 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-25 09:02:58 +0200 |
commit | 90f3da7d8debb64a35be283df9e6b96e24fe282f (patch) | |
tree | ef807dc857cb4db154852f65080f18bfee4def68 /aconf | |
parent | c1993c6f11df64f53239e246412e3ff09927651d (diff) | |
download | aconf-90f3da7d8debb64a35be283df9e6b96e24fe282f.tar.bz2 aconf-90f3da7d8debb64a35be283df9e6b96e24fe282f.tar.xz |
model: cache TreeNode instances after fetching
Diffstat (limited to 'aconf')
-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 |