cardano-rpc
Safe HaskellNone
LanguageHaskell2010

Cardano.Rpc.Server.Internal.TimedCache

Description

A cache for a single value. The value is dropped once nothing has read it for a while. Use it for data that is expensive to build but too big or too rarely needed to keep around forever.

Synopsis

Documentation

data TimedCache a Source #

Holds at most one value. The value is dropped once no read has happened for expiryTimeout.

Create with newTimedCache, read with readThroughCache.

newTimedCache Source #

Arguments

:: MonadIO m 
=> DiffTime

How long the cached value is kept after the last read

-> m (TimedCache a) 

Create an empty cache.

This starts no thread. The watcher thread only exists while the cache holds a value, so an unused cache holds no data and runs nothing.

readThroughCache Source #

Arguments

:: MonadUnliftIO m 
=> TimedCache a

The cache to read

-> m a

How to load the value on a cache miss

-> m a 

Read the cached value. If the cache is empty, run the load action and cache its result. Every read restarts the expiry timer.

If the load throws, the exception goes to the caller and the cache stays empty. The next read simply tries again.