Permalink
Browse files

Modified FifoCache to respect threshold. Modified README to conform t…

…o contrib format
  • Loading branch information...
1 parent dd9439d commit 8c22ef153b7825b33e73cea41607d106fd3d0268 @fogus fogus committed Aug 6, 2012
Showing with 63 additions and 60 deletions.
  1. +56 −56 README.md
  2. +7 −4 src/main/clojure/clojure/core/cache.clj
View
112 README.md
@@ -1,17 +1,19 @@
-# clojure.core.cache - A Clojure Caching Library
+clojure.core.cache
+========================================
core.cache is a new Clojure contrib library providing the following features:
* An underlying `CacheProtocol` used as the base abstraction for implementing new synchronous caches
* A `defcache` macro for hooking your `CacheProtocol` implementations into the Clojure associative data capabilities.
-* Immutable implementations of some basic caching strategies
+* Implementations of some basic caching strategies
- First-in-first-out (FIFOCache)
- Least-recently-used (LRUCache)
- Least-used (LUCache)
- Time-to-live (TTLCache)
- Naive cache (BasicCache)
+ - Naive cache backed with soft references (SoftCache)
* Implementation of an efficient buffer replacement policy based on the *low inter-reference recency set* algorithm (LIRSCache) described in the [LIRS](http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.116.2184) paper
@@ -20,83 +22,81 @@ core.cache is a new Clojure contrib library providing the following features:
core.cache is based on a library named Clache, found at http://github.com/fogus/clache that is planned for deprecation.
-Using
------
+Releases and Dependency Information
+========================================
-You can use core.cache in your [Leiningen](https://github.com/technomancy/leiningen) and [Cake](https://github.com/flatland/cake) projects with the following `:dependencies` directive in your `project.clj` file:
+Latest stable release: 0.6.2
- [org.clojure/core.cache "0.5.0"]
+* [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22core.cache%22)
-For Maven-driven projects, use the following slice of XML in your `pom.xml`'s `<dependencies>` section:
+* [Development Snapshot Versions](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure.cache~~~)
- <dependency>
- <groupId>org.clojure</groupId>
- <artifactId>core.cache</artifactId>
- <version>0.5.0</version>
- </dependency>
-
-Enjoy!
-
-
-Places
-------
+[Leiningen](https://github.com/technomancy/leiningen) dependency information:
-* [Source code](https://github.com/clojure/core.cache)
-* [Ticket system](http://dev.clojure.org/jira/browse/CCACHE)
-* [Announcement](http://groups.google.com/group/clojure/browse_frm/thread/69d08572ab265dc7)
-* [Examples and documentation](http://github.com/clojure/core.cache/wiki)
+ [org.clojure/data.json "0.1.2"]
+[Maven](http://maven.apache.org/) dependency information:
-Changes from Clache
--------------------
-
-The v0.5.0 version of core.cache is based almost wholly on the final version of Clache, with the following changes:
-
-* An addition of an `evict` function on the `CacheProtocol` used to explicitly remove a value from a cache based on a key. All of the existing cache types implement this function *except* for `LIRSCache`.
+ <dependency>
+ <groupId>org.clojure</groupId>
+ <artifactId>core.cache</artifactId>
+ <version>0.6.2</version>
+ </dependency>
-* The addition of cache factory functions for all of the existing cache types
-* The associative structure behaviors are defined solely in terms of the underlying `CacheProtocol`
-* The `SoftCache` implementation was buggy and removed for now
+Example Usage
+========================================
+ (require [clojure.core.cache :as cache])
+
+ (def C (cache/fifo-cache-factory {:a 1, :b 2})
@jochenberger
jochenberger added a line comment Aug 7, 2014

I think there's a closing paren missing

@fogus
Clojure member
fogus added a line comment Aug 7, 2014

Added. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ (if (cache/has? C :c)
+ (cache/hit C :c)
+ (cache/miss C :c 42))
+
+ ;=> {:a 1, :b 2, :c 42}
+
+ (cache/evict C :b)
+
+ ;=> {:a 1}
-Plans
------
+Refer to docstrings in the `clojure.core.cache` namespace, or the [autogenerated API documentation](http://clojure.github.com/core.cache/) for additional documentation
-The following capabilities are under design, development, or consideration for future versions of core.cache:
-* Asynchronous caching protocol
-* `LIRSCache evict`
-* Removal of the `seed` function from the `CacheProtocol`
-* Reimplementation of a cache based on soft references
-* test.generative usage
-* Deprecation of Clache
-* Documentation and examples
-More planning is needed around capabilities not listed nor thought of.
+Developer Information
+========================================
+* [GitHub project](https://github.com/clojure/core.cache)
-Contributors
-------------
+* [Bug Tracker](http://dev.clojure.org/jira/browse/CCACHE)
-core.cache would not exist if not for the inspiration and contributions of the following people:
+* [Continuous Integration](http://build.clojure.org/job/core.cache/)
-* [Meikel Brandmeyer](http://kotka.de)
-* [Fogus](http://fogus.me/fun)
-* [Sebastián Galkin](http://github.com/paraseba)
-* [Jan Oberhagemann](http://github.com/deduktion)
+* [Compatibility Test Matrix](http://build.clojure.org/job/core.cache-test-matrix/)
-References
-----------
-TODO
+Change Log
+====================
+* Release 0.6.2 on 2012.08.07 [more information](http://blog.fogus.me/?p=4527)
+ * Removed reflection warnings
+ * Fixed eviction of items from LU, TTL and LRU caches with thresholds less than two
+ * Fixed eviction of items from FIFO cache prior to threshold
+* Release 0.6.1 on 2012.07.13 [more information](http://blog.fogus.me/2012/07/13/announcing-core-cache-version-0-6-1/)
+ * Added SoftCache
+ * Fixed eviction of items from LU and LRU caches prior to threshold
+ * Adjusted default thresholds in factory functions
+* Release 0.5.0 on 2011.12.13 [more information](http://blog.fogus.me/2011/12/13/announcing-core-cache-v0-5-0/)
+ * Added `evict`
+ * Added cache factory functions
+ * Added associatve operation support
-License
--------
-Copyright © 2011 Rich Hickey
+Copyright and License
+========================================
-Licensed under the EPL. (See the file epl.html.)
+Copyright (c) Rich Hickey, Michael Fogus and contributors, 2012. All rights reserved. The use and distribution terms for this software are covered by the Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound bythe terms of this license. You must not remove this notice, or any other, from this software.
View
11 src/main/clojure/clojure/core/cache.clj
@@ -155,9 +155,12 @@
(hit [this item]
this)
(miss [_ item result]
- (let [k (peek q)]
- (FIFOCache. (-> cache (dissoc k) (assoc item result))
- (-> q pop (conj item))
+ (let [[cache q] (if (>= (count cache) limit)
+ (let [k (peek q)]
+ [(dissoc cache k) (pop q)])
+ [cache q])]
+ (FIFOCache. (assoc cache item result)
+ (conj q item)
limit)))
(evict [this key]
(let [v (get cache key ::miss)]
@@ -566,7 +569,7 @@
[base & {threshold :threshold :or {threshold 32}}]
{:pre [(number? threshold) (< 0 threshold)
(map? base)]
- :post [(== threshold (count %))]}
+ :post [(== threshold (count (.q ^FIFOCache %)))]}
(clojure.core.cache/seed (FIFOCache. {} clojure.lang.PersistentQueue/EMPTY threshold) base))
(defn lru-cache-factory

0 comments on commit 8c22ef1

Please sign in to comment.