From f0593bd746bb6bec62c5ad72ab699e4ec5ff102b Mon Sep 17 00:00:00 2001 From: Mikhail Kuzmin Date: Wed, 6 Nov 2024 17:57:03 +0400 Subject: [PATCH] deref cache --- src/darkleaf/di/core.clj | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/darkleaf/di/core.clj b/src/darkleaf/di/core.clj index 5cbf922..4f9b5d8 100644 --- a/src/darkleaf/di/core.clj +++ b/src/darkleaf/di/core.clj @@ -905,28 +905,25 @@ " [cache] - (fn [downstream-registry] - (let [cached-registry (:registry @cache) - registry (fn [key] - ;; тут бы тест написать на порядок - ;; в gmonit хороший пример с reitit и update-key conj routes - (?? (cached-registry key) - (downstream-registry key)))] - (fn [key] - - ;; throw on empty cache? - - (let [cache @cache - factory (registry key) - {cached-deps :dependencies - cached-obj :object} (cache key)] - (reify p/Factory - (dependencies [_] - (p/dependencies factory)) - (build [_ deps] - (if (identical-deps? cached-deps deps) - cached-obj - (p/build factory deps))) - (demolish [_ obj] - (when (not (identical? cached-obj obj)) - (p/demolish factory obj))))))))) + (let [cache @cache] + (fn [downstream-registry] + (let [cached-registry (:registry cache) + registry (fn [key] + ;; тут бы тест написать на порядок + ;; в gmonit хороший пример с reitit и update-key conj routes + (?? (cached-registry key) + (downstream-registry key)))] + (fn [key] + (let [factory (registry key) + {cached-deps :dependencies + cached-obj :object} (cache key)] + (reify p/Factory + (dependencies [_] + (p/dependencies factory)) + (build [_ deps] + (if (identical-deps? cached-deps deps) + cached-obj + (p/build factory deps))) + (demolish [_ obj] + (when (not (identical? cached-obj obj)) + (p/demolish factory obj))))))))))