Skip to content

Commit

Permalink
wip4
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Oct 15, 2024
1 parent a57733f commit 8bcce98
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@
(demolish [_ _])))
(registry key)))))

;; может быть сделать 2 арности в одной функции вместо этих 2х функций?

(defn collect-cache []
(let [cache (volatile! {})]
(fn [registry]
Expand All @@ -773,39 +775,26 @@
(build [_ deps]
(let [obj (p/build factory deps)]
(vswap! cache assoc
[:key+deps key deps] obj
#_#_
[:key+obj key obj] true)
[:key->deps key] deps
[:key->obj key] obj)
obj))
(demolish [_ obj]
(p/demolish factory obj)))))))))

;; может быть сделать 2 арности вместо этих 2х функций?

(defn use-cache [cache]
(fn [registry]
(fn [key]
(let [factory (registry key)]
(let [factory (registry key)
cached-deps (cache [:key->deps key])
cached-obj (cache [:key->obj key])]
(reify p/Factory
(dependencies [_]
(p/dependencies factory))
(build [_ deps]
(?? (get cache [:key+deps key deps])
(p/build factory deps)))
(if (= cached-deps deps)
cached-obj
(p/build factory deps)))
(demolish [_ obj]
;; todo
;; складывать кешированные в какую-то мапу, что проверяет на identical?
;; или просто делать
;; (swap! cache assoc [key deps] obj
;; [key obj] :cached
;; и тут проверять, что он :cached
;; или, но только за одно обновление
;; (swap! cache update :direct assoc [key deps] obj)
;; (swap! cache update :indirect conj [key obj]) ;; #{set}

;; или можно каждой фабрике сделать локальный (volatile! cached?)
;; и спрашивать у него
;; но это логику di ломает


#_"we must stop only not cached obj"))))))
(if (identical? cached-obj obj)
nil
(p/demolish factory obj))))))))

0 comments on commit 8bcce98

Please sign in to comment.