Permalink
Browse files

CCHACHE-17: Added protocol for fn backed cache

  • Loading branch information...
1 parent dca15eb commit 8602477433ce7d876794a7d518fb3609442de645 @fogus fogus committed Feb 10, 2012
Showing with 29 additions and 1 deletion.
  1. +8 −0 pom.xml
  2. +21 −1 src/main/clojure/clojure/core/cache.clj
View
@@ -54,4 +54,12 @@
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/test/clojure</directory>
+ </resource>
+ </resources>
+ </build>
</project>
@@ -82,7 +82,6 @@
java.lang.Iterable
(iterator [this#] (.iterator ~base-field)))))
-
(defcache BasicCache [cache]
CacheProtocol
(lookup [_ item]
@@ -101,6 +100,27 @@
Object
(toString [_] (str cache)))
+(defcache FnCache [cache f]
+ CacheProtocol
+ (lookup [_ item]
+ (f (get cache item)))
+ (lookup [_ item not-found]
+ (let [ret (get cache item not-found)]
+ (if (= ret not-found)
+ not-found
+ (f ret))))
+ (has? [_ item]
+ (contains? cache item))
+ (hit [this item] this)
+ (miss [_ item result]
+ (BasicCache. (assoc cache item result)))
+ (evict [_ key]
+ (BasicCache. (dissoc cache key)))
+ (seed [_ base]
+ (BasicCache. base))
+ Object
+ (toString [_] (str cache)))
+
;; # FIFO
(defn- describe-layout [mappy limit]

0 comments on commit 8602477

Please sign in to comment.