Skip to content
Browse files

fixed bug in macro

  • Loading branch information...
1 parent e3ad865 commit 0df952207cef1ed10b5d81c58edc94873a11fdeb @davidhmartin committed Feb 28, 2012
Showing with 9 additions and 9 deletions.
  1. +6 −6 src/mcache/core.clj
  2. +3 −3 test/mcache/test/cache.clj
View
12 src/mcache/core.clj
@@ -71,22 +71,22 @@
(clear [mc] "clear the cache"))
(defmacro with-cache
- "key is a string, value-fn is a function. Returns keyed value from cache;
- if not found, uses value-fn to obtain the value and adds it to cache
+ "key is a string, value is an sexpr. Returns keyed value from cache;
+ if not found, uses value to obtain the value and adds it to cache
before returning."
- ([cache key value-fn]
+ ([cache key value]
`(if-let [cached-val# (fetch ~cache ~key)]
cached-val#
- (let [val# (~value-fn ~key)]
+ (let [val# ~value]
(if (nil? val#)
nil
(if (.get (put-if-absent ~cache ~key val#))
val#
(fetch ~cache ~key))))))
- ([cache key value-fn exp]
+ ([cache key value exp]
`(if-let [cached-val# (fetch ~cache ~key)]
cached-val#
- (let [val# (~value-fn ~key)]
+ (let [val# ~value]
(if (nil? val#)
nil
(if (.get (put-if-absent ~cache ~key val# ~exp))
View
6 test/mcache/test/cache.clj
@@ -131,10 +131,10 @@
(if (< (Integer/parseInt id) 100)
(str "foo" id)
nil))]
- (is (nil? (with-cache mc "200" qfcn)))
- (is (= "foo50" (with-cache mc "50" qfcn)))
+ (is (nil? (with-cache mc "200" (qfcn "200"))))
+ (is (= "foo50" (with-cache mc "50" (qfcn "50"))))
(is (= "foo50" (fetch mc "50")))
- (is (= "foo50" (with-cache mc "50" qfcn)))))
+ (is (= "foo50" (with-cache mc "50" (qfcn 50))))))
(defn do-test-cache-backed-lookup [mc]

0 comments on commit 0df9522

Please sign in to comment.
Something went wrong with that request. Please try again.