lrucache-1.2.0.0: a simple, pure LRU cache

Safe Haskell | Safe
Language | Haskell98

Data.Cache.LRU.IO

Description

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. All functions use a single atomic update of the backing structure.

The interface this module provides is opaque. If further control is desired, the Data.Cache.LRU.IO.Internal module can be used in combination with Data.Cache.LRU.Internal.

(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.)

Synopsis

- data AtomicLRU key val
- newAtomicLRU :: Ord key => Maybe Integer -> IO (AtomicLRU key val)
- fromList :: Ord key => Maybe Integer -> [(key, val)] -> IO (AtomicLRU key val)
- toList :: Ord key => AtomicLRU key val -> IO [(key, val)]
- maxSize :: AtomicLRU key val -> IO (Maybe Integer)
- insert :: Ord key => key -> val -> AtomicLRU key val -> IO ()
- lookup :: Ord key => key -> AtomicLRU key val -> IO (Maybe val)
- delete :: Ord key => key -> AtomicLRU key val -> IO (Maybe val)
- pop :: Ord key => AtomicLRU key val -> IO (Maybe (key, val))
- size :: AtomicLRU key val -> IO Int
- modifyAtomicLRU :: (LRU key val -> LRU key val) -> AtomicLRU key val -> IO ()
- modifyAtomicLRU' :: (LRU key val -> IO (LRU key val)) -> AtomicLRU key val -> IO ()

# Documentation

data AtomicLRU key val #

The opaque wrapper type

newAtomicLRU #

Arguments

:: Ord key |
=> Maybe Integer | the optional maximum size
-> IO (AtomicLRU key val) |

Make a new AtomicLRU that will not grow beyond the optional maximum size, if specified.

fromList #

Arguments

:: Ord key |
=> Maybe Integer | the optional maximum size
-> [(key, val)] |
-> IO (AtomicLRU key val) |

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

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

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

maxSize :: AtomicLRU key val -> IO (Maybe Integer) #

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

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

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

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

delete :: Ord key => key -> AtomicLRU key val -> IO (Maybe val) #

Remove an item from an AtomicLRU. Returns the value for the removed key, if it was present

pop :: Ord key => AtomicLRU key val -> IO (Maybe (key, val)) #

Remove the least-recently accessed item from an AtomicLRU. Returns the (key, val) pair removed, if one was present.

size :: AtomicLRU key val -> IO Int #

Returns the number of elements the AtomicLRU currently contains.

modifyAtomicLRU :: (LRU key val -> LRU key val) -> AtomicLRU key val -> IO () #

Given a function that takes an `LRU` and returns one of the same type, use it to modify the contents of this AtomicLRU.

modifyAtomicLRU' :: (LRU key val -> IO (LRU key val)) -> AtomicLRU key val -> IO () #

Given a function that takes an `LRU` and returns an IO action producting one of the same type, use it to modify the contents of this AtomicLRU.