summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-17 14:31:22 +0600
committerunwox <me@unwox.com>2024-10-17 14:31:22 +0600
commit08370b6f302f93cae01b0521f29a62c20e97bdab (patch)
treed4862634ea0668ac83c0fc06fff2a4e471c49e95
parentff8c6c9dde3a877b51e2fabafa579e2c05dc856e (diff)
implement cache clearing by namespaces
-rw-r--r--bin/fetch.fnl2
-rw-r--r--lib/cache.fnl7
2 files changed, 6 insertions, 3 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl
index da5383d..4558c50 100644
--- a/bin/fetch.fnl
+++ b/bin/fetch.fnl
@@ -144,7 +144,7 @@
ipuer.products
ozchai.products])]
(store-products tx (products)))
-(cache.clear-tx tx)
+(cache.clear-tx tx "page:")
(must (luna.db.commit tx))
(populate-search-table)
diff --git a/lib/cache.fnl b/lib/cache.fnl
index b21a05e..8cf7323 100644
--- a/lib/cache.fnl
+++ b/lib/cache.fnl
@@ -15,7 +15,10 @@
[key value]))
value)
-(fn clear-tx [tx]
- (must (luna.db.exec-tx tx "DELETE FROM cache" [])))
+(fn clear-tx [tx prefix]
+ (if (= "string" (type prefix))
+ (must (luna.db.exec-tx tx "DELETE FROM cache WHERE key LIKE ?"
+ [(.. prefix "%")]))
+ (must (luna.db.exec-tx tx "DELETE FROM cache" []))))
{: get :set _set : clear-tx}