Skip to content

Instantly share code, notes, and snippets.

@strongh
Created September 24, 2014 19:02
Show Gist options
  • Save strongh/2055df89ff041915f855 to your computer and use it in GitHub Desktop.
Save strongh/2055df89ff041915f855 to your computer and use it in GitHub Desktop.
trying to reproduce replacement of memoized fn with crache version
(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