implement support for the new :skip-file-modification-check option
This commit is contained in:
parent
aaced50b76
commit
826fdb3832
|
@ -60,6 +60,12 @@
|
||||||
true
|
true
|
||||||
(> file-last-modified other-timestamp))))
|
(> file-last-modified other-timestamp))))
|
||||||
|
|
||||||
|
; this function really only exists so i can easily change the exception type / message in the future
|
||||||
|
; since this file-exists check is needed in a few places
|
||||||
|
(defn- err-if-no-file! [^File file]
|
||||||
|
(if-not (.exists file)
|
||||||
|
(throw (new FileNotFoundException (str "Template file \"" file "\" not found.")))))
|
||||||
|
|
||||||
(defn- cache-compiled-template! [^File file create-fn]
|
(defn- cache-compiled-template! [^File file create-fn]
|
||||||
(let [filepath (.getPath file)
|
(let [filepath (.getPath file)
|
||||||
cache-and-return! (fn []
|
cache-and-return! (fn []
|
||||||
|
@ -72,19 +78,29 @@
|
||||||
:template new-compiled-template})
|
:template new-compiled-template})
|
||||||
new-compiled-template))
|
new-compiled-template))
|
||||||
cached (get @compiled-templates filepath)]
|
cached (get @compiled-templates filepath)]
|
||||||
(if (and cached
|
(cond
|
||||||
(or (:skip-file-modification-check @options)
|
(not cached)
|
||||||
(not (newer? file (:last-modified cached)))))
|
(do
|
||||||
|
(err-if-no-file! file)
|
||||||
|
(cache-and-return!))
|
||||||
|
|
||||||
|
(:skip-file-modification-check @options)
|
||||||
(:template cached)
|
(:template cached)
|
||||||
(cache-and-return!))))
|
|
||||||
|
:else
|
||||||
|
(do
|
||||||
|
(err-if-no-file! file)
|
||||||
|
(if (newer? file (:last-modified cached))
|
||||||
|
(cache-and-return!)
|
||||||
|
(:template cached))))))
|
||||||
|
|
||||||
(defn- compile-template! [^File file]
|
(defn- compile-template! [^File file]
|
||||||
(if-not (.exists file)
|
(let [compile-template-fn (fn [file]
|
||||||
(throw (new FileNotFoundException (str "Template file \"" file "\" not found.")))
|
(compile-template-file file))]
|
||||||
(let [compile-template-fn (fn [file]
|
(if (:cache-compiled-templates @options)
|
||||||
(compile-template-file file))]
|
(cache-compiled-template! file compile-template-fn)
|
||||||
(if (:cache-compiled-templates @options)
|
(do
|
||||||
(cache-compiled-template! file compile-template-fn)
|
(err-if-no-file! file)
|
||||||
(compile-template-fn file)))))
|
(compile-template-fn file)))))
|
||||||
|
|
||||||
(defn flush-template-cache!
|
(defn flush-template-cache!
|
||||||
|
|
Reference in a new issue