registry-0.3.0.7: data structure for assembling components
Safe HaskellNone
LanguageHaskell2010

Data.Registry.Internal.Cache

Description

Cache for individual IO values when we wish to memoize actions for database connection pools for example

This is inspired by https://hackage.haskell.org/package/io-memoize

Synopsis

Documentation

newtype Cache a Source #

A thread-safe write-once cache. If you need more functionality, (e.g. multiple write, cache clearing) use an MVar instead.

Constructors

Cache (MVar (Map Key a)) 

Instances

Instances details
Eq (Cache a) Source # 
Instance details

Defined in Data.Registry.Internal.Cache

Methods

(==) :: Cache a -> Cache a -> Bool #

(/=) :: Cache a -> Cache a -> Bool #

type Key = Maybe [SpecializationPath] Source #

We need to cache different values to account for the fact that different values might be specialized for the same type

fetch :: forall a m. (MonadIO m, Typeable a) => Cache a -> Key -> m a -> m a Source #

Fetch the value stored in the cache, or call the supplied fallback and store the result, if the cache is empty.

newCache :: IO (Cache a) Source #

Create an empty cache.