summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cache.fnl9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/cache.fnl b/lib/cache.fnl
index 8cf7323..76ede13 100644
--- a/lib/cache.fnl
+++ b/lib/cache.fnl
@@ -21,4 +21,11 @@
[(.. prefix "%")]))
(must (luna.db.exec-tx tx "DELETE FROM cache" []))))
-{: get :set _set : clear-tx}
+(fn wrap [db key f]
+ (local cached (get db key))
+ (if cached
+ cached
+ (let [res (f)]
+ (if res (_set db key res) nil))))
+
+{: get :set _set : clear-tx : wrap}