fcache-0.1.0.0: Cache a function (a -> b)

Safe HaskellSafe
LanguageHaskell2010

Cache.Internal

Documentation

data Cache k v Source

Constructors

Cache 

Fields

_limit :: Maybe Int
 
_size :: Int
 
_cache :: HashMap k v
 
_queue :: Seq k
 

Instances

(Hashable k, Eq k) => IsCache Cache k Source 
(Eq k, Eq v) => Eq (Cache k v) Source 
(Show k, Show v) => Show (Cache k v) Source 

class IsCache m k where Source

Minimal complete definition

newCache, lookup, insert, dumpOldest, size, limit, setLimit

Methods

newCache :: Maybe Int -> m k v Source

newCache size. Set a max number of elements the cache will hold.

If the newly inserted element exceeds the size limit, the oldest element is removed from the cache.

newUnlimitedCache :: m k v Source

Alias for newCache Nothing

lookup :: k -> m k v -> Maybe v Source

Lookup an element from the cache

insert :: k -> v -> m k v -> m k v Source

Insert an element to the cache.

If the newly inserted element exceeds the size limit, the oldest element is removed from the cache.

dumpOldest :: m k v -> m k v Source

Remove the oldest key from the cache.

size :: m k v -> Int Source

Return the current number of elements.

limit :: m k v -> Maybe Int Source

Return the max number of elements the cache can hold.

setLimit :: Maybe Int -> m k v -> m k v Source

Change the size limit.

dump :: Int -> m k v -> m k v Source

dump n cache removes n oldest elements from the cache.

Instances