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 module contains the internal implementation details. It's
possible to put an AtomicLRU
into a bad state with this module.
It is highly recommended that the external interface,
Data.Cache.LRU.IO, be used instead.
- newtype AtomicLRU key val = C (MVar (LRU key val))
- newAtomicLRU :: Ord key => Int -> IO (AtomicLRU key val)
- fromList :: Ord key => Int -> [(key, val)] -> IO (AtomicLRU key val)
- toList :: Ord key => AtomicLRU key val -> IO [(key, val)]
- maxSize :: AtomicLRU key val -> IO Int
- 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 Bool
- size :: AtomicLRU key val -> IO Int
- modifyMVar_' :: MVar a -> (a -> IO a) -> IO ()
- modifyMVar' :: MVar a -> (a -> IO (a, b)) -> IO b
Documentation
Make a new AtomicLRU with the given maximum size.
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.
modifyMVar_' :: MVar a -> (a -> IO a) -> IO ()Source
A version of modifyMVar_
that applies the modification
function strictly.
modifyMVar' :: MVar a -> (a -> IO (a, b)) -> IO bSource
A version of modifyMVar
that applies the modification
function strictly. The returned value is not evaluated strictly.