From cf789c7ac677b9c13ae6f26d7dda950584a373c8 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 20 Jan 2010 22:08:15 +0100 Subject: Speedup of factor 4 by switching to the Data.Binary library for serialization. --- src/Text/Hakyll/Internal/Cache.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/Text/Hakyll/Internal/Cache.hs') diff --git a/src/Text/Hakyll/Internal/Cache.hs b/src/Text/Hakyll/Internal/Cache.hs index 454a4c5..9b9fab1 100644 --- a/src/Text/Hakyll/Internal/Cache.hs +++ b/src/Text/Hakyll/Internal/Cache.hs @@ -6,19 +6,17 @@ module Text.Hakyll.Internal.Cache import Control.Monad.Reader (liftIO) import Text.Hakyll.Hakyll (Hakyll) import Text.Hakyll.File +import Data.Binary -storeInCache :: (Show a) => a -> FilePath -> Hakyll () +storeInCache :: (Binary a) => a -> FilePath -> Hakyll () storeInCache value path = do cachePath <- toCache path makeDirectories cachePath - liftIO $ writeFile cachePath (show value) + liftIO $ encodeFile cachePath value -getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a) +getFromCache :: (Binary a) => FilePath -> Hakyll (Maybe a) getFromCache path = do cachePath <- toCache path valid <- isMoreRecent cachePath [path] - if valid then liftIO (getFromCache' cachePath) >>= return . Just + if valid then liftIO (decodeFile cachePath) >>= return . Just else return Nothing - where - getFromCache' cachePath = do c <- readFile cachePath - return (read c) -- cgit v1.2.3