haxl-2.4.0.0: A Haskell library for efficient, concurrent, and concise data access.
Safe HaskellNone
LanguageHaskell2010

Haxl.Core.DataCache

Description

A cache mapping data requests to their results. This module is provided for access to Haxl internals only; most users should not need to import it.

Synopsis

Documentation

newtype DataCache res Source #

A DataCache res maps things of type req a to res a, for any req and a provided req a is an instance of Typeable. In practice req a will be a request type parameterised by its result.

Constructors

DataCache (HashTable TypeRep (SubCache res)) 

data SubCache res Source #

The implementation is a two-level map: the outer level maps the types of requests to SubCache, which maps actual requests to their results. So each SubCache contains requests of the same type. This works well because we only have to store the dictionaries for Hashable and Eq once per request type.

Constructors

forall req a.(Hashable (req a), Eq (req a)) => SubCache (req a -> String) (a -> String) !(HashTable (req a) (res a)) 

filter :: forall res. (forall a. res a -> IO Bool) -> DataCache res -> IO (DataCache res) Source #

insert Source #

Arguments

:: (Hashable (req a), Typeable (req a), Eq (req a), Show (req a), Show a) 
=> req a

Request

-> res a

Result

-> DataCache res 
-> IO () 

Inserts a request-result pair into the DataCache.

insertNotShowable Source #

Arguments

:: (Hashable (req a), Typeable (req a), Eq (req a)) 
=> req a

Request

-> res a

Result

-> DataCache res 
-> IO () 

Inserts a request-result pair into the DataCache, without requiring Show instances of the request or the result. The cache cannot be subsequently used with showCache.

insertWithShow Source #

Arguments

:: (Hashable (req a), Typeable (req a), Eq (req a)) 
=> (req a -> String)

Show function for request

-> (a -> String)

Show function for result

-> req a

Request

-> res a

Result

-> DataCache res 
-> IO () 

Inserts a request-result pair into the DataCache, with the given functions used to show the request and result.

lookup Source #

Arguments

:: Typeable (req a) 
=> req a

Request

-> DataCache res 
-> IO (Maybe (res a)) 

Looks up the cached result of a request.

showCache :: forall res. DataCache res -> (forall a. res a -> IO (Maybe (Either SomeException a))) -> IO [(TypeRep, [(String, Either SomeException String)])] Source #

Dumps the contents of the cache, with requests and responses converted to Strings using the supplied show functions. The entries are grouped by TypeRep. Note that this will fail if insertNotShowable has been used to insert any entries.

readCache :: forall res ret. DataCache res -> (forall a. res a -> IO ret) -> IO [(TypeRep, [Either SomeException ret])] Source #

Dumps the contents of the cache responses to list