module Data.LazyHash.Cache.Int (
cached, cached'
, fundamental, (<#>), liftPH2
) where
import Data.LazyHash.Cache hiding (cached, cached')
import Data.LazyHash.Class
import Data.LazyHash.Numerical ()
import qualified Data.Hashable as SH
import Data.Binary
import System.FilePath
import System.Directory
import Data.Typeable
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as BS (toStrict)
import Numeric (showHex)
import Data.Word (Word64)
import Data.Default.Class
import Lens.Micro
cached :: (Binary a, Typeable a) => Prehashed Int a -> IO a
cached = cached' def
cached' :: (Binary a, Typeable a)
=> CacheAccessConf
-> Prehashed Int a
-> IO a
cached' conf (Prehashed h v) = case conf^.cachingLocation of
Nothing -> do
tmpRoot <- getTemporaryDirectory
cached' (conf & cachingLocation .~ Just (tmpRoot</>"hs-lazy-hashed")) (Prehashed h v)
Just path -> do
let fname = path </> showHex (fromIntegral (h # typeRep [v]) :: Word64) [] <.> ".lhbs"
cachedValueInFile conf fname v