lazy-hash-cache-0.1.0.0: Storing computed values for re-use when the same program runs again.

Copyright(c) Justus Sagemüller 2017
LicenseGPL v3
Maintainer(@) jsagemue $ uni-koeln.de
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.LazyHash.Cache

Contents

Description

 

Synopsis

The caching actions

cached :: (Hash h, Binary a, Typeable a, Binary h) => Prehashed h a -> IO a Source #

Look up a value in the project-global cache store. If it has already been computed during an earlier program run, simply re-use that result, else calculate it and store for future runs to use.

This is a shortcut for cached' def, which corresponds to the options

This function is polymorphic in the type of hash it uses, but this can require boilerplate signature and you'll probably want to choose one such type and stick to it for your entire project. We offer specialised versions for this purpose; see Data.LazyHash.Cache.Int.

cached' Source #

Arguments

:: (Hash h, Binary a, Typeable a, Binary h) 
=> CacheAccessConf 
-> Prehashed h a

Value to cache

-> IO a 

Write, re-use or modify the cache, depending on the configuration.

Prehashing tools

fundamental :: QuasiQuoter #

Transform an ordinary value into a pre-hashed one. This hashes the source code contained in the quasi quote, making the assumption that the behaviour of anything invoked therein will never change.

Applying this to anything but named, fixed-predefined values (standard library functions etc.) is probably a bad idea.

(<#>) :: Hash h => Prehashed h (a -> b) -> Prehashed h a -> Prehashed h b infixl 4 #

Analogous to <$>: apply a hash-supported function to a hash-supported value.

liftPH2 :: Hash h => Prehashed h (a -> b -> c) -> Prehashed h a -> Prehashed h b -> Prehashed h c #

Configuration

cachingLocation :: Lens' CacheAccessConf (Maybe FilePath) Source #

Where the cache-files should be stored. If Nothing, the system temporary folder will be used.

usePrecalculated :: Lens' CacheAccessConf Bool Source #

Whether to actually make use of a cached value, in case one is found. Usually, doing that is the entire point of this library, but sometimes you may want to disable it (e.g. after debbuging some function that was assumed fundamental).

calculateIfNecessary :: Lens' CacheAccessConf Bool Source #

Whether you want the processor to bite the bullet and compute the value itself, in case it can't be found in the cache. Again, you will need to have this on at some point (the cached values have to come from somewhere, after all).

writeUsedVersion :: Lens' CacheAccessConf Bool Source #

Whether to store the computed value in cache. This too should usually be enabled.

burnAfterReading :: Lens' CacheAccessConf Bool Source #

Enable this to have the cached value deleted after use. May be useful to save disk space.

(For the record: this does not perform any kind of special secure-memore-erasing, it only removes the cache file.)

Internals

cachedValueInFile Source #

Arguments

:: Binary a 
=> CacheAccessConf 
-> FilePath

File to store this value in.

-> a

Value to cache

-> IO a