API for clojure.core.cache - A caching library implementing various cache strategies 0.6.4 (in development)

by Fogus

Full namespace name: clojure.core.cache

Overview

A caching library for Clojure.

Protocols



CacheProtocol

Protocol
This is the protocol describing the basic cache capability.
Known implementations: BasicCache, FIFOCache, FnCache, LIRSCache, LRUCache, LUCache, SoftCache, TTLCache

evict

function
Usage: (evict cache e)
Removes an entry from the cache

has?

function
Usage: (has? cache e)
Checks if the cache contains a value associated with `e`

hit

function
Usage: (hit cache e)
Is meant to be called if the cache is determined to contain a value
associated with `e`

lookup

function
Usage: (lookup cache e)
       (lookup cache e not-found)
Retrieve the value associated with `e` if it exists, else `nil` in
the 2-arg case.  Retrieve the value associated with `e` if it exists,
else `not-found` in the 3-arg case.

miss

function
Usage: (miss cache e ret)
Is meant to be called if the cache is determined to **not** contain a
value associated with `e`

seed

function
Usage: (seed cache base)
Is used to signal that the cache should be created with a seed.
The contract is that said cache should return an instance of its
own type.
Source

Types



BasicCache

type

    Fields: [cache]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


FIFOCache

type

    Fields: [cache q limit]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


FnCache

type

    Fields: [cache f]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


LIRSCache

type

    Fields: [cache lruS lruQ tick limitS limitQ]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


LRUCache

type

    Fields: [cache lru tick limit]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


LUCache

type

    Fields: [cache lu limit]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


SoftCache

type

    Fields: [cache rcache rq]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable


TTLCache

type

    Fields: [cache ttl ttl-ms]
Protocols: CacheProtocol
Interfaces: clojure.lang.Associative, clojure.lang.Counted, clojure.lang.ILookup, clojure.lang.IPersistentCollection, clojure.lang.IPersistentMap, clojure.lang.Seqable

Public Variables and Functions



->BasicCache

function
Usage: (->BasicCache cache)
Positional factory function for class clojure.core.cache.BasicCache.
Source


->FIFOCache

function
Usage: (->FIFOCache cache q limit)
Positional factory function for class clojure.core.cache.FIFOCache.
Source


->FnCache

function
Usage: (->FnCache cache f)
Positional factory function for class clojure.core.cache.FnCache.
Source


->LIRSCache

function
Usage: (->LIRSCache cache lruS lruQ tick limitS limitQ)
Positional factory function for class clojure.core.cache.LIRSCache.
Source


->LRUCache

function
Usage: (->LRUCache cache lru tick limit)
Positional factory function for class clojure.core.cache.LRUCache.
Source


->LUCache

function
Usage: (->LUCache cache lu limit)
Positional factory function for class clojure.core.cache.LUCache.
Source


->SoftCache

function
Usage: (->SoftCache cache rcache rq)
Positional factory function for class clojure.core.cache.SoftCache.
Source


->TTLCache

function
Usage: (->TTLCache cache ttl ttl-ms)
Positional factory function for class clojure.core.cache.TTLCache.
Source


basic-cache-factory

function
Usage: (basic-cache-factory base)
Returns a pluggable basic cache initialied to `base`
Source


fifo-cache-factory

function
Usage: (fifo-cache-factory base & {threshold :threshold, :or {threshold 32}})
Returns a FIFO cache with the cache and FIFO queue initialized to `base` --
the queue is filled as the values are pulled out of `base`.  If the associative
structure can guarantee ordering, then the said ordering will define the
eventual eviction order.  Otherwise, there are no guarantees for the eventual
eviction ordering.

This function takes an optional `:threshold` argument that defines the maximum number
of elements in the cache before the FIFO semantics apply (default is 32).

If the number of elements in `base` is greater than the limit then some items
in `base` will be dropped from the resulting cache.  If the associative
structure used as `base` can guarantee sorting, then the last `limit` elements
will be used as the cache seed values.  Otherwise, there are no guarantees about
the elements in the resulting cache.
Source


lirs-cache-factory

function
Usage: (lirs-cache-factory base & {:keys [s-history-limit q-history-limit], :or {s-history-limit 32, q-history-limit 32}})
Returns an LIRS cache with the S & R LRU lists set to the indicated
limits.
Source


lru-cache-factory

function
Usage: (lru-cache-factory base & {threshold :threshold, :or {threshold 32}})
Returns an LRU cache with the cache and usage-table initialied to `base` --
each entry is initialized with the same usage value.

This function takes an optional `:threshold` argument that defines the maximum number
of elements in the cache before the LRU semantics apply (default is 32).
Source


lu-cache-factory

function
Usage: (lu-cache-factory base & {threshold :threshold, :or {threshold 32}})
Returns an LU cache with the cache and usage-table initialied to `base`.

This function takes an optional `:threshold` argument that defines the maximum number
of elements in the cache before the LU semantics apply (default is 32).
Source


soft-cache-factory

function
Usage: (soft-cache-factory base)
Returns a SoftReference cache.  Cached values will be referred to with
SoftReferences, allowing the values to be garbage collected when there is
memory pressure on the JVM.

SoftCache is a mutable cache, since it is always based on a
ConcurrentHashMap.
Source


through

function
Usage: (through cache item)
       (through value-fn cache item)
       (through wrap-fn value-fn cache item)
The basic hit/miss logic for the cache system.  Expects a wrap function and
value function.  The wrap function takes the value function and the item in question
and is expected to run the value function with the item whenever a cache
miss occurs.  The intent is to hide any cache-specific cells from leaking
into the cache logic itelf.
Source


ttl-cache-factory

function
Usage: (ttl-cache-factory base & {ttl :ttl, :or {ttl 2000}})
Returns a TTL cache with the cache and expiration-table initialied to `base` --
each with the same time-to-live.

This function also allows an optional `:ttl` argument that defines the default
time in milliseconds that entries are allowed to reside in the cache.
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.