Skip to content

Commit 72efb66

Browse files
committed
clear disk-cache between invocations
1 parent b49b4f8 commit 72efb66

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/clj/xt_play/lambda.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
(:require [muuntaja.core :as m]
66
[clojure.java.io :as io]
77
[clojure.string :as str]
8+
[clojure.tools.logging :as log]
89
[xtdb.api :as xt]
910
[xtdb.node :as xtn]
1011
[xt-play.config :as config]
1112
[xt-play.base64 :as b64]
1213
[xt-play.handler :as h]))
1314

15+
(defn- clear-directory
16+
"Recursively delete all contents of a directory"
17+
[^java.io.File dir]
18+
(when (.exists dir)
19+
(doseq [file (.listFiles dir)]
20+
(if (.isDirectory file)
21+
(do
22+
(clear-directory file)
23+
(.delete file))
24+
(.delete file)))
25+
(log/info "Cleared disk cache directory:" (.getPath dir))))
26+
1427
(defn -init []
28+
; Clear disk cache from previous Lambda container executions
29+
(clear-directory (io/file "/tmp/xtdb-cache"))
30+
1531
; NOTE: This ensure xtdb is warmed up before starting the server
1632
; Otherwise, the first few requests will time out
1733
(with-open [node (xtn/start-node config/node-config)]

0 commit comments

Comments
 (0)