lrucache-0.1: a simple pure LRU cache



This module contains a mutable wrapping of an LRU in the IO monad, providing atomic access in a concurrent environment. All calls preserve the same semantics as those in Data.Cache.LRU, but perform updates in place.

(This implementation uses an MVar for coarse locking. It's unclear if anything else would give better performance, given that many calls alter the head of the access list.)



data AtomicLRU key val Source

The opaque wrapper type



:: Ord key 
=> Int

the maximum size

-> IO (AtomicLRU key val) 

Make a new AtomicLRU with the given maximum size.



:: Ord key 
=> Int

the maximum size

-> [(key, val)] 
-> IO (AtomicLRU key val) 

Build a new LRU from the given maximum size and list of contents. See fromList for the semantics.

toList :: Ord key => AtomicLRU key val -> IO [(key, val)]Source

Retreive a list view of an AtomicLRU. See toList for the semantics.

insert :: Ord key => key -> val -> AtomicLRU key val -> IO ()Source

Insert a key/value pair into an AtomicLRU. See insert for the semantics.

lookup :: Ord key => key -> AtomicLRU key val -> IO (Maybe val)Source

Look up a key in an AtomicLRU. See lookup for the semantics.

delete :: Ord key => key -> AtomicLRU key val -> IO BoolSource

Remove an item from an AtomicLRU. Returns whether the item was present to be removed.

size :: AtomicLRU key val -> IO IntSource

Returns the number of elements the AtomicLRU currently contains.