haxl-0.5.1.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 #

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

See the definition of ResultVar for more details.

Constructors

DataCache (HashMap 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

(Hashable (req a), Eq (req a), Typeable (req a)) => SubCache (req a -> String) (a -> String) !(HashMap (req a) (res a)) 

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 
-> DataCache res 

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 
-> DataCache res 

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 
-> DataCache res 

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 
-> Maybe (res a) 

Looks up the cached result of a request.

showCache :: DataCache ResultVar -> 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.