From 08370b6f302f93cae01b0521f29a62c20e97bdab Mon Sep 17 00:00:00 2001 From: unwox Date: Thu, 17 Oct 2024 14:31:22 +0600 Subject: implement cache clearing by namespaces --- bin/fetch.fnl | 2 +- lib/cache.fnl | 7 +++++-- 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} -- cgit v1.2.3