-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Cache combinators. -- -- Cache combinators. @package caching @version 0 module Data.Cache.Trace data CacheEvent k t v CacheEvict :: !k -> !t -> v -> CacheEvent k t v [_ceKey] :: CacheEvent k t v -> !k [_ceTracking] :: CacheEvent k t v -> !t [_ceValue] :: CacheEvent k t v -> v CacheAdd :: !k -> !t -> v -> CacheEvent k t v [_ceKey] :: CacheEvent k t v -> !k [_ceTracking] :: CacheEvent k t v -> !t [_ceValue] :: CacheEvent k t v -> v type CacheTrace k t v = DList (CacheEvent k t v) class MonadTrace (trc :: Bool) trace :: (MonadTrace trc, Applicative m) => w -> Tracable trc w m () class MonadAtomicRef m => MonadAtomicRefTraced trc w m -- | Atomically mutate the contents of a reference with trace data output atomicModifyRefTraced :: MonadAtomicRefTraced trc w m => Ref m a -> (a -> (a, w, b)) -> Tracable trc w m b -- | Strict version of atomicModifyRefTraced. This forces both the value -- stored in the reference as well as the value returned but not the -- trace. atomicModifyRefTraced' :: MonadAtomicRefTraced trc w m => Ref m a -> (a -> (a, w, b)) -> Tracable trc w m b -- | Strict Monadic update function so that tracing is closer to zero cost -- when unused. atomicModifyRefTracedM' :: MonadAtomicRefTraced trc w m => Ref m a -> (forall m'. Monad m' => a -> Tracable trc w m' (a, b)) -> Tracable trc w m b atomicModifyRefTracedM'_ :: (MonadAtomicRefTraced trc w m, forall mg. Monad mg => Functor (Tracable trc w mg)) => Ref m a -> (forall m'. (Monad m', Functor (Tracable trc w m')) => a -> Tracable trc w m' a) -> Tracable trc w m () data family Tracable (trc :: Bool) :: * -> (* -> *) -> * -> * instance (GHC.Classes.Ord k, GHC.Classes.Ord t, GHC.Classes.Ord v) => GHC.Classes.Ord (Data.Cache.Trace.CacheEvent k t v) instance (GHC.Classes.Eq k, GHC.Classes.Eq t, GHC.Classes.Eq v) => GHC.Classes.Eq (Data.Cache.Trace.CacheEvent k t v) instance (GHC.Show.Show k, GHC.Show.Show t, GHC.Show.Show v) => GHC.Show.Show (Data.Cache.Trace.CacheEvent k t v) instance (GHC.Read.Read k, GHC.Read.Read t, GHC.Read.Read v) => GHC.Read.Read (Data.Cache.Trace.CacheEvent k t v) instance (Control.Monad.Ref.MonadAtomicRef m, GHC.Base.Monoid w) => Data.Cache.Trace.MonadAtomicRefTraced 'GHC.Types.True w m instance (Control.Monad.Ref.MonadAtomicRef m, GHC.Base.Monoid w) => Data.Cache.Trace.MonadAtomicRefTraced 'GHC.Types.False w m instance Data.Cache.Trace.MonadTrace 'GHC.Types.True instance Data.Cache.Trace.MonadTrace 'GHC.Types.False instance GHC.Base.Functor m => GHC.Base.Functor (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance GHC.Base.Functor m => GHC.Base.Functor (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => GHC.Base.Applicative (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance GHC.Base.Monad m => GHC.Base.Applicative (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, GHC.Base.MonadPlus m) => GHC.Base.Alternative (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance (GHC.Base.Monoid w, GHC.Base.MonadPlus m) => GHC.Base.Alternative (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => GHC.Base.Monad (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance GHC.Base.Monad m => GHC.Base.Monad (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, Control.Monad.Fail.MonadFail m) => Control.Monad.Fail.MonadFail (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, GHC.Base.MonadPlus m) => GHC.Base.MonadPlus (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance (GHC.Base.Monoid w, GHC.Base.MonadPlus m) => GHC.Base.MonadPlus (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance (GHC.Base.Monoid w, Control.Monad.Fix.MonadFix m) => Control.Monad.Fix.MonadFix (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Data.Cache.Trace.Tracable 'GHC.Types.False w m) instance GHC.Base.Monoid w => Control.Monad.Trans.Class.MonadTrans (Data.Cache.Trace.Tracable 'GHC.Types.True w) instance GHC.Base.Monoid w => Control.Monad.Trans.Class.MonadTrans (Data.Cache.Trace.Tracable 'GHC.Types.False w) instance (GHC.Base.Monoid w, Control.Monad.IO.Class.MonadIO m) => Control.Monad.IO.Class.MonadIO (Data.Cache.Trace.Tracable 'GHC.Types.True w m) instance (GHC.Base.Monoid w, Control.Monad.IO.Class.MonadIO m) => Control.Monad.IO.Class.MonadIO (Data.Cache.Trace.Tracable 'GHC.Types.False w m) -- | By tracing operations we can transform one type of cache into another. module Data.Cache.Type data Cache m k t v Cache :: c -> Cache m k t v insert :: (Monad m, Caching c m k () v) => c -> k -> v -> m () lookup :: (MonadFail m, Caching c m k t v) => c -> k -> m v lookupMaybe :: (Monad m, Caching c m k t v) => c -> k -> m (Maybe v) lookupCreating :: (Monad m, Caching c m k () v) => c -> k -> m v -> m v cached :: (Monad m, Caching c m k t v) => c -> k -> m Bool evict :: (Monad m, Caching c m k t v) => c -> k -> m () data CacheEvent k t v CacheEvict :: !k -> !t -> v -> CacheEvent k t v [_ceKey] :: CacheEvent k t v -> !k [_ceTracking] :: CacheEvent k t v -> !t [_ceValue] :: CacheEvent k t v -> v CacheAdd :: !k -> !t -> v -> CacheEvent k t v [_ceKey] :: CacheEvent k t v -> !k [_ceTracking] :: CacheEvent k t v -> !t [_ceValue] :: CacheEvent k t v -> v type CacheTrace k t v = DList (CacheEvent k t v) -- | c - The cache type. m - The Monad. k - The key. t - The tracking data. -- This allows caches to store metadata for 3rd parties. v - The value. class Caching c (m :: * -> *) k t v | c -> m, c -> k, c -> t, c -> v insetTraced :: forall (trc :: Bool). Caching c m k t v => c -> k -> t -> v -> Tracable trc (CacheTrace k t v) m () lookupTraced :: forall (trc :: Bool). Caching c m k t v => c -> k -> Tracable trc (CacheTrace k t v) m (Maybe v) evictTraced :: forall (trc :: Bool). Caching c m k t v => c -> k -> Tracable trc (CacheTrace k t v) m () updateTracking :: forall (trc :: Bool). Caching c m k t v => c -> k -> (t -> t) -> Tracable trc (CacheTrace k t v) m () -- | A reified Caching dictionary so that we can assemble them on demand. data DictCache (m :: * -> *) k t v DictCache :: (forall (trc :: Bool). k -> t -> v -> Tracable trc (CacheTrace k t v) m ()) -> (forall (trc :: Bool). k -> Tracable trc (CacheTrace k t v) m (Maybe v)) -> (forall (trc :: Bool). k -> Tracable trc (CacheTrace k t v) m ()) -> (forall (trc :: Bool). k -> (t -> t) -> Tracable trc (CacheTrace k t v) m ()) -> DictCache k t v [dcIns] :: DictCache k t v -> forall (trc :: Bool). k -> t -> v -> Tracable trc (CacheTrace k t v) m () [dcLook] :: DictCache k t v -> forall (trc :: Bool). k -> Tracable trc (CacheTrace k t v) m (Maybe v) [dcEvict] :: DictCache k t v -> forall (trc :: Bool). k -> Tracable trc (CacheTrace k t v) m () [dcUp] :: DictCache k t v -> forall (trc :: Bool). k -> (t -> t) -> Tracable trc (CacheTrace k t v) m () instance Data.Cache.Type.Caching (Data.Cache.Type.DictCache m k t v) m k t v module Data.Cache.LRU data LRUCache m (s :: Strategy) p k t v data Strategy -- | Priority is set on entry and not changed. | LIFO -- ^ A generally bad -- policy where the most recent thing is evicted. FIFO :: Strategy -- | Every lookup generates a new priority. LRU :: Strategy -- | Priority is number of times looked up (tie breaker of order -- inserted?). LFU :: Strategy instance (GHC.Show.Show p, GHC.Show.Show k, GHC.Show.Show t, GHC.Show.Show v) => GHC.Show.Show (Data.Cache.LRU.LRUCache' s p k t v) instance (GHC.Classes.Eq t, GHC.Classes.Eq v, Data.Hashable.Class.Hashable k, GHC.Classes.Ord k, GHC.Classes.Ord p) => GHC.Classes.Eq (Data.Cache.LRU.LRUCache' s p k t v) module Data.Cache -- | We can translate the tracking data. When the first cache evicts data, -- try to insert it into the second. Left bias, faster cache should come -- first. exclusive :: (Cache c1 m k t1 v, Cache c2 k t2 v) => c1 -- -> c2 -> (t1 -> t2) -> Cache m k t1 v -- -- Insert any data into both caches, retrieve it from either. Left bias, -- faster cache should come first. inclusive :: (Cache c1 m k t v, Cache -- c2 k t v) => c1 -> c2 -> Cache m k t v -- -- Inserts to both, evicts if evicts from either. Example usage is to -- augment a cache with a dataset size limit intersection :: (Cache c1 m -- k t1 v, Cache c2 k t2 v) => c1 -> c2 -> Cache m k (t1, t2) v -- -- Maps the key to one of a given number of caches and inserts and -- retrieves from there. stripped :: (Cache c m k t v) => [c] -> -- Cache m k t v filtering :: (Monad m, forall (trc :: Bool). Monad m => Applicative (Tracable trc (CacheTrace k t v) m), Caching c m k t v) => (k -> t -> Bool) -> c -> DictCache m k t v