HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelrucache-1.2.0.1Haskell98

Data.Cache.LRU

Implements an LRU cache.

This module provides a pure LRU cache based on a doubly-linked list through a Data.Map structure. This gives O(log n) operations on insert, lookup, delete, and pop, and O(n * log n) for toList.

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

  • 1 type
  • 12 values
  • Packagelrucache-1.2.0.1
  • Exports13
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceLRU.hs
datadata LRU key val
#

Stores the information that makes up an LRU cache

Instances6Functor, Foldable, Traversable, Eq, Data, Show
  • Functor (LRU key)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
  • Ord key => Foldable (LRU key)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
  • Ord key => Traversable (LRU key)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
  • (Eq key, Eq val) => Eq (LRU key val)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
  • (Data key, Data val, Ord key) => Data (LRU key val)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
  • (Ord key, Show key, Show val) => Show (LRU key val)Defined in lrucache-1.2.0.1 · Data.Cache.LRU.Internal
valuenewLRU
  1. :: Ord key
  2. => Maybe Integer

    the optional maximum size of the LRU

  3. -> LRU key val
#

Make an LRU. If a size limit is specified, the LRU is guaranteed to not grow above the specified number of entries.

valuefromList
  1. :: Ord key
  2. => Maybe Integer

    the optional maximum size of the LRU

  3. -> [(key, val)]
  4. -> LRU key val
#

Build a new LRU from the given maximum size and list of contents, in order from most recently accessed to least recently accessed.

valuetoList :: Ord key => LRU key val -> [(key, val)]
#

Retrieve a list view of an LRU. The items are returned in order from most recently accessed to least recently accessed.

valuepairs
  1. :: (Ord key, Applicative f, Contravariant f)
  2. => (key, val) -> f (key, val)
  3. -> LRU key val
  4. -> f (LRU key val)
#

Traverse the (key, value) pairs of the LRU, in a read-only way. This is a Fold in the sense used by the lens package. It must be read-only because alterations could break the underlying Map structure.

valuekeys
  1. :: (Ord key, Applicative f, Contravariant f)
  2. => key -> f key
  3. -> LRU key val
  4. -> f (LRU key val)
#

Traverse the keys of the LRU, in a read-only way. This is a Fold in the sense used by the lens package. It must be read-only because alterations could break the underlying Map structure.

valueinsert :: Ord key => key -> val -> LRU key val -> LRU key val
#

Add an item to an LRU. If the key was already present in the LRU, the value is changed to the new value passed in. The item added is marked as the most recently accessed item in the LRU returned.

If this would cause the LRU to exceed its maximum size, the least recently used item is dropped from the cache.

valuelookup :: Ord key => key -> LRU key val -> (LRU key val, Maybe val)
#

Look up an item in an LRU. If it was present, it is marked as the most recently accesed in the returned LRU.

valuedelete :: Ord key => key -> LRU key val -> (LRU key val, Maybe val)
#

Remove an item from an LRU. Returns the new LRU, and the value removed if the key was present.

valuepop :: Ord key => LRU key val -> (LRU key val, Maybe (key, val))
#

Removes the least-recently accessed element from the LRU. Returns the new LRU, and the key and value from the least-recently used element, if there was one.

valuesize :: LRU key val -> Int
#

Returns the number of elements the LRU currently contains.