Skip to content

Commit

Permalink
deref cache
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Nov 6, 2024
1 parent 7e42ac0 commit f0593bd
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))))))

0 comments on commit f0593bd

Please sign in to comment.