From e7a7a084b2224b8c65ab522c1e5497048b48e89a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 8 Feb 2017 13:13:57 +0100 Subject: [PATCH] lua cache.* fixes - docs: fix cache.current_* since long ago d5272b4 - don't allow "cache.foo = 'bar'" for abitrary foo - restore cache['nic.cz'] after b31bad2ccf while not breaking completion - #cache won't work on lua 5.1, so remove it --- daemon/README.rst | 24 +++++++++++++++++++----- daemon/lua/sandbox.lua | 26 +++++++++++--------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/daemon/README.rst b/daemon/README.rst index c6365f1ba..8d62ab648 100644 --- a/daemon/README.rst +++ b/daemon/README.rst @@ -711,30 +711,44 @@ The daemon provides an interface for dynamic loading of :ref:`daemon modules cache.count()` -- `cache[x] -> cache.get(x)` -- `cache.{size|storage} = value` setmetatable(cache, { - __len = function (t) - return t.count() - end, __index = function (t, k) - if type(k) == 'number' then - return rawget(t, k) or (rawget(t, 'current_size') and t.get(k)) - end + local res = rawget(t, k) + if res and not rawget(t, 'current_size') then return res end + -- Beware: t.get returns empty table on failure to find. + -- That would be confusing here (breaking kresc), so return nil instead. + res = t.get(k) + if res and next(res) ~= nil then return res else return nil end end, __newindex = function (t,k,v) -- Defaults - if type(k) == number then - local storage = rawget(t, 'current_storage') - if not storage then storage = 'lmdb://' end - local size = rawget(t, 'current_size') - if not size then size = 10*MB end - end + local storage = rawget(t, 'current_storage') + if not storage then storage = 'lmdb://' end + local size = rawget(t, 'current_size') + if not size then size = 10*MB end -- Declarative interface for cache if k == 'size' then t.open(v, storage) - elseif k == 'storage' then t.open(size, v) - else rawset(t, k, v) end + elseif k == 'storage' then t.open(size, v) end end }) -- 2.47.3