-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memoize #17
Conversation
f1e8c12
to
71983f5
Compare
4d3099f
to
f5ebb03
Compare
@@ -0,0 +1,53 @@ | |||
(ns darkleaf.di.tutorial.z-memoize-test ;;todo: name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот тест нужно переработать, чтобы это была как документация
test/darkleaf/di/cache_test.clj
Outdated
(di/use-cache cache)) | ||
_ (di/start [::y `a] | ||
{::y :y} | ||
(di/log (callbacks :third)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут порядок важен
{::y :y}
по идее должен быть после use-cache.
log должен быть самым последним.
НО если лог последний, то мы увидим, что компоненты из main по 3 раза останавливаются.
f73a37f
to
073471c
Compare
297c0f9
to
cfcc33c
Compare
(set! *warn-on-reflection* true) | ||
|
||
(t/deftest cache-stop-test | ||
(let [cache (atom {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(let [cache (->cache)] ...
???
src/darkleaf/di/core.clj
Outdated
(downstream-registry key)))] | ||
(fn [key] | ||
|
||
;; throw on empty cache? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!
src/darkleaf/di/core.clj
Outdated
(let [cached-registry (:registry @cache) | ||
registry (fn [key] | ||
;; тут бы тест написать на порядок | ||
;; в gmonit хороший пример с reitit и update-key conj routes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!
src/darkleaf/di/core.clj
Outdated
" | ||
[cache] | ||
(fn [downstream-registry] | ||
(let [cached-registry (:registry @cache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
может быть выше делать один глобальный deref?
@@ -870,3 +872,66 @@ | |||
middlewares | |||
(inspect-middleware))] | |||
@components)) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(def cache (di/cache))
(di/start (:collect cache))
(di/start (:use cache))
(def cache (di/cache)) ;; or (def cache (atom {}))
(di/start (di/collect-cache cache))
(di/start (di/use-cache cache))
di/cache
-> di/->cache
??
(fn [registry] | ||
(swap! cache assoc :registry (fn [key] | ||
(case key | ||
::implicit-root nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::implicit-root
в системах, использующих кэш, свой, со своими зависимостями.
Его нельзя кэшировать.
Есть еще вариант в start
положить реестр с рутом самым последним, но тогда отваливается add-side-depencency
.
middlewares (concat [with-env
- with-ns
- root-registry]
- middlewares)
+ with-ns]
+ middlewares
+ [root-registry])
registry (apply-middleware nil-registry middlewares)
https://github.com/darkleaf/di/pull/35/files
Хз что лучше.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
от add-side-dependency одни проблемы. Может быть переделать ее на
(add-side-dependency key dep)
и по умолчанию (add-side-dependency ::implicit-root dep)
?
или сделать add-side-dependency2
, а первую задепрекейтить?
No description provided.