lrucache-1.2.0.1: a simple, pure LRU cache

Safe HaskellSafe
LanguageHaskell98

Data.Cache.LRU.IO.Internal

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.

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.

Synopsis

Documentation

newtype AtomicLRU key val Source #

The opaque wrapper type

Constructors

C (MVar (LRU key val)) 

newAtomicLRU Source #

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 Source #

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)] Source #

Retrieve 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 (Maybe val) Source #

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)) Source #

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 Source #

Returns the number of elements the AtomicLRU currently contains.

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

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 () Source #

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.

modifyMVar_' :: MVar a -> (a -> IO a) -> IO () Source #

A version of modifyMVar_ that forces the result of the function application to WHNF.

modifyMVar' :: MVar a -> (a -> IO (a, b)) -> IO b Source #

A version of modifyMVar that forces the result of the function application to WHNF.