|
13 | 13 | java.util.zip.GZIPInputStream |
14 | 14 | java.util.jar.JarFile)) |
15 | 15 |
|
| 16 | +(def artifacts-file ".artifacts-cache") |
| 17 | + |
| 18 | +(defn get-last-modified-from-file |
| 19 | + "Returns last modified time in milliseconds or nil if file does not exist." |
| 20 | + [file] |
| 21 | + (let [lm (.lastModified (io/file file))] |
| 22 | + (if (zero? lm) nil lm))) |
| 23 | + |
16 | 24 | ;; structure here is {"prismatic/schem" ["0.1.1" "0.2.0" ...]} |
17 | | -(defonce artifacts (atom {} :meta {:last-modified nil})) |
| 25 | +(defonce artifacts (atom (slurp artifacts-file) |
| 26 | + :meta {:last-modified |
| 27 | + (get-last-modified-from-file artifacts-file)})) |
18 | 28 | (def millis-per-day (* 24 60 60 1000)) |
19 | 29 |
|
20 | 30 | (defn- get-proxy-opts |
|
28 | 38 | (defn- stale-cache? |
29 | 39 | [] |
30 | 40 | (or (empty? @artifacts) |
31 | | - (if-let [last-modified (some-> artifacts meta :last-modified .getTime)] |
| 41 | + (if-let [last-modified (some-> artifacts meta :last-modified)] |
32 | 42 | (neg? (- millis-per-day (- (.getTime (java.util.Date.)) last-modified))) |
33 | 43 | true))) |
34 | 44 |
|
|
99 | 109 | (let [clojars-artifacts (future (get-artifacts-from-clojars!)) |
100 | 110 | maven-artifacts (future (get-artifacts-from-mvn-central!))] |
101 | 111 | (reset! artifacts (into @clojars-artifacts @maven-artifacts)) |
102 | | - (alter-meta! artifacts update-in [:last-modified] (constantly (java.util.Date.))))) |
| 112 | + (spit artifacts-file @artifacts) |
| 113 | + (alter-meta! artifacts update-in [:last-modified] |
| 114 | + (constantly (get-last-modified-from-file artifacts-file))))) |
103 | 115 |
|
104 | 116 | (defn artifact-list |
105 | 117 | [{:keys [force]}] |
106 | 118 | (when (or (= force "true") (stale-cache?)) |
107 | 119 | (update-artifact-cache!) |
108 | | - (spit ".artifacts-cache" @artifacts)) |
| 120 | + (spit artifacts-file @artifacts)) |
109 | 121 | (->> @artifacts keys list*)) |
110 | 122 |
|
111 | 123 | (defn artifact-versions |
|
0 commit comments