Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Example usage:
-- Downloads a large payload from an external data store. downloadData :: IO ByteString cachedDownloadData :: IO (Cached IO ByteString) cachedDownloadData = cachedIO (secondsToNominalDiffTime 600) downloadData
The first time cachedDownloadData
is called, it calls downloadData
,
stores the result, and returns it. If it is called again:
- before 10 minutes have passed, it returns the stored value.
- after 10 minutes have passed, it calls
downloadData
and stores the result again.
Synopsis
- newtype Cached m a = Cached {
- runCached :: m a
- cachedIO :: (MonadIO m, MonadIO t, MonadCatch t) => NominalDiffTime -> t a -> m (Cached t a)
- cachedIOWith :: (MonadIO m, MonadIO t, MonadCatch t) => (UTCTime -> UTCTime -> Bool) -> t a -> m (Cached t a)
- cachedIO' :: (MonadIO m, MonadIO t, MonadCatch t) => NominalDiffTime -> (Maybe (UTCTime, a) -> t a) -> m (Cached t a)
- cachedIOWith' :: (MonadIO m, MonadIO t, MonadCatch t) => (UTCTime -> UTCTime -> Bool) -> (Maybe (UTCTime, a) -> t a) -> m (Cached t a)
Documentation
:: (MonadIO m, MonadIO t, MonadCatch t) | |
=> NominalDiffTime | Number of seconds before refreshing cache |
-> t a | IO action to cache |
-> m (Cached t a) |
Cache an IO action, producing a version of this IO action that is cached
for interval
seconds. The cache begins uninitialized.
The outer IO is responsible for setting up the cache. Use the inner one to
either get the cached value or refresh, if the cache is older than interval
seconds.
:: (MonadIO m, MonadIO t, MonadCatch t) | |
=> (UTCTime -> UTCTime -> Bool) | Test function:
If |
-> t a | action to cache. |
-> m (Cached t a) |
Cache an IO action, The cache begins uninitialized.
The outer IO is responsible for setting up the cache. Use the inner one to either get the cached value or refresh
:: (MonadIO m, MonadIO t, MonadCatch t) | |
=> NominalDiffTime | Number of seconds before refreshing cache |
-> (Maybe (UTCTime, a) -> t a) | action to cache. The stale value and its refresh date are passed so that the action can perform external staleness checks |
-> m (Cached t a) |
Cache an IO action, producing a version of this IO action that is cached
for interval
seconds. The cache begins uninitialized.
The outer IO is responsible for setting up the cache. Use the inner one to
either get the cached value or refresh, if the cache is older than interval
seconds.
:: (MonadIO m, MonadIO t, MonadCatch t) | |
=> (UTCTime -> UTCTime -> Bool) | Test function:
If |
-> (Maybe (UTCTime, a) -> t a) | action to cache. The stale value and its refresh date are passed so that the action can perform external staleness checks |
-> m (Cached t a) |
Cache an IO action, The cache begins uninitialized.
The outer IO is responsible for setting up the cache. Use the inner one to either get the cached value or refresh