Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Caching implementation internals.
This module is not part of the Data.Cache public API and should not be directly relied upon by users. Anything meant for external use defined here will be re-exported by a public module.
Synopsis
- class (MonadCatch m, MonadIO m) => MonadCache m where
- data DelayMode a
- = DelayForMicroseconds Int
- | DelayDynamically (Either SomeException a -> Int)
- | DelayDynamicallyWithBounds (Int, Int) (Either SomeException a -> Int)
- data FailureMode
- data CacheOptions a = CacheOptions {
- delayMode :: DelayMode a
- failureMode :: FailureMode
- delayFuzzing :: Maybe Int
Documentation
class (MonadCatch m, MonadIO m) => MonadCache m where Source #
The top-level Monad
in which caching operations are performed.
This exists primarily for testing purposes. Production uses should drop in IO
and forget that this exists.
currentTime :: m UTCTime Source #
The current system time.
randomize :: (Int, Int) -> m Int Source #
Generate a random number between two bounds (inclusive).
Delay execution of the current thread for a number of microseconds.
newThread :: m () -> m ThreadId Source #
Spawn a new thread of execution to run an action.
repeatedly :: m () -> m () Source #
Run an action forever.
killCache :: ThreadId -> m () Source #
Stop a thread of execution. The thread can be assumed to have been started using newThread
.
The supported delay modes for a PollingCache
instance.
The delay associated with a cache instance define the amount of time that will pass between cache refreshes.
DelayForMicroseconds Int | Delay for static number of microseconds between each refresh. |
DelayDynamically (Either SomeException a -> Int) | Delay for a dynamic number of microseconds between each refresh. This is useful if different delays should be used for successes or failures, or if the result being retrieved contains information that could affect the delay period. |
DelayDynamicallyWithBounds (Int, Int) (Either SomeException a -> Int) | Delay for a dynamic number of microseconds between each refresh within a set of bounds. This is similarly useful to |
data FailureMode Source #
The supported failure handling modes for a PollingCache
instance.
In the context of the cache action, "failure" means an Exception thrown from the user-supplied action that generates values to populate the cache.
Because these operations are performed in a background thread, the user must decide how failures are to be handled upon cache creation.
Ignore | Failures should be ignored entirely; the most relaxed failure handling strategy. This means that |
EvictImmediately | If a failure occurs, any previously cached value is immediately evicted from the cache; the strictest failure handling strategy. |
EvictAfterTime NominalDiffTime | Failures will be ignored unless they persist beyond the supplied time span. This is a middle-ground failure handling strategy that probably makes sense to use in most scenarios. The nature of asynchronous polling implies that somewhat stale values are not an issue to the consumer; therefore, allowing some level of transient failure can often improve reliability without sacrificing correctness. |
Instances
Eq FailureMode Source # | |
Defined in Data.Cache.Internal (==) :: FailureMode -> FailureMode -> Bool # (/=) :: FailureMode -> FailureMode -> Bool # | |
Show FailureMode Source # | |
Defined in Data.Cache.Internal showsPrec :: Int -> FailureMode -> ShowS # show :: FailureMode -> String # showList :: [FailureMode] -> ShowS # |
data CacheOptions a Source #
Options that dictate the behavior of a PollingCache
instance.
CacheOptions | |
|