store/[org.clojure/clojure "1.8.0"] clj::clojure.core/memoize

Official Documentation

Add notes
Arities
==================================================
   [f]

Docstring
==================================================
  Returns a memoized version of a referentially transparent function. The
  memoized version of the function keeps a cache of the mapping from arguments
  to results and, when calls with the same arguments are repeated often, has
  higher performance at the expense of higher memory use.

Source

(defn memoize
  "Returns a memoized version of a referentially transparent function. The
  memoized version of the function keeps a cache of the mapping from arguments
  to results and, when calls with the same arguments are repeated often, has
  higher performance at the expense of higher memory use."
  {:added "1.0"
   :static true}
  [f]
  (let [mem (atom {})]
    (fn [& args]
      (if-let [e (find @mem args)]
        (val e)
        (let [ret (apply f args)]
          (swap! mem assoc args ret)
          ret)))))

Example 1

Edit
;; First we define a function that presumably have some expensive computation.
(defn myfunc [a] (println "doing some work") (+ a 10))
;; => #'user/myfunc

;; Next we create a memoized version of the function.
(def myfunc-memo (memoize myfunc))
;; => #'user/myfunc-memo


;; The first time we call the function with a particular argument the
;; original function is invoked and the value is returned.  The next
;; time the function is called with the same argument the cached result
;; is returned and the original function is NOT called.
(myfunc-memo 1)
;; > doing some work
;; => 11

(myfunc-memo 1)
;; => 11

(myfunc-memo 20)
;; > doing some work
;; => 30

(myfunc-memo 20)
;; => 30

Uses on crossclj