-
-
Save strongh/2055df89ff041915f855 to your computer and use it in GitHub Desktop.
trying to reproduce replacement of memoized fn with crache version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'crache.memo) | |
(defn f [_] | |
(rand-int 100)) | |
(def f-memo (memoize f)) | |
(defn my-app [] | |
(println (map f-memo (range 10)))) | |
;; output stays the same: | |
;; user=> (my-app) | |
;; (57 74 8 27 14 47 44 23 52 46) | |
;; user=> (my-app) | |
;; (57 74 8 27 14 47 44 23 52 46) | |
;; until... | |
(alter-var-root (var f-memo) (fn [_] (memo-redis f))) | |
;; this re-memoizes, and causes redis requests | |
;; user=> (my-app) | |
;; (1 29 29 64 20 56 11 91 56 6) | |
;; user=> (my-app) | |
;; (1 29 29 64 20 56 11 91 56 6) | |
;; I can see redis traffic reading values with each execution of my-app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment