|
58 | 58 | memoized version of the function keeps a cache of the mapping from arguments |
59 | 59 | to results and, when calls with the same arguments are repeated often, has |
60 | 60 | higher performance at the expense of higher memory use. FIFO with 100 entries. |
61 | | - If the cached if filled, there will be a WARNING logged at least once -> root cause |
62 | | - is most propably that the route is using anonymous coercer, which doesn't hit |
63 | | - the cache. It will produce slower performance, but works otherwise as expected." |
64 | | - [name] |
65 | | - (let [cache (atom {:mem (linked/map), :overflow false}) |
| 61 | + Cache will be filled if anonymous coercers are used (does not match the cache)" |
| 62 | + [] |
| 63 | + (let [cache (atom (linked/map)) |
66 | 64 | cache-size 100] |
67 | 65 | (fn [& args] |
68 | | - (or (-> @cache :mem (get args)) |
| 66 | + (or (@cache args) |
69 | 67 | (let [coercer (apply sc/coercer args)] |
70 | | - (swap! cache (fn [cache] |
71 | | - (let [mem (assoc (:mem cache) args coercer)] |
| 68 | + (swap! cache (fn [mem] |
| 69 | + (let [mem (assoc mem args coercer)] |
72 | 70 | (if (>= (count mem) cache-size) |
73 | | - (do |
74 | | - (when-not (:overflow cache) |
75 | | - ;; side-effecting within a swap! might cause multiple writes. |
76 | | - ;; it's ok'ish as we are just reporting something that should be |
77 | | - ;; fixes at development time |
78 | | - (logging/log! :warning (str "Coercion memoization cache for " name |
79 | | - " maxing at " cache-size ". " |
80 | | - "You might recreate the coercer " |
81 | | - "matcher on each request, causing " |
82 | | - "coercer re-compilation per request, " |
83 | | - "effecting coercion performance."))) |
84 | | - {:mem (dissoc mem (-> mem first first)) |
85 | | - :overflow true}) |
86 | | - (assoc cache :mem mem))))) |
| 71 | + (dissoc mem (-> mem first first)) |
| 72 | + mem)))) |
87 | 73 | coercer))))) |
88 | 74 |
|
89 | 75 | (defn strict [schema] |
|
152 | 138 | ;; |
153 | 139 |
|
154 | 140 | (defmulti restructure-param |
155 | | - "Restructures a key value pair in smart routes. By default the key |
156 | | - is consumed form the :parameters map in acc. k = given key, v = value." |
157 | | - (fn [k v acc] k)) |
| 141 | + "Restructures a key value pair in smart routes. By default the key |
| 142 | + is consumed form the :parameters map in acc. k = given key, v = value." |
| 143 | + (fn [k v acc] k)) |
158 | 144 |
|
159 | 145 | ;; |
160 | 146 | ;; Pass-through swagger metadata |
|
358 | 344 | (defn restructure [method [path arg & args] & [{:keys [body-wrap]}]] |
359 | 345 | (let [body-wrap (or body-wrap 'do) |
360 | 346 | method-symbol (symbol (str (-> method meta :ns) "/" (-> method meta :name))) |
361 | | - coercer-name (str (keyword (.toLowerCase (name method-symbol))) " " path) |
362 | 347 | [parameters body] (extract-parameters args) |
363 | 348 | [lets letks responses middlewares] [[] [] nil nil] |
364 | 349 | [lets arg-with-request arg] (destructure-compojure-api-request lets arg) |
|
375 | 360 | (map-of lets letks responses middlewares parameters body) |
376 | 361 | parameters) |
377 | 362 |
|
378 | | - pre-lets [+compojure-api-coercer+ `(memoized-coercer ~coercer-name)] |
| 363 | + pre-lets [+compojure-api-coercer+ `(memoized-coercer)] |
379 | 364 |
|
380 | 365 | body `(~body-wrap ~@body) |
381 | 366 | body (if (seq letks) `(letk ~letks ~body) body) |
|
0 commit comments