From 892cae9da263d9f2fad4d93dd6d6c50fb12add16 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 20 Jan 2010 17:10:08 +0100 Subject: Added caching again. But now the more sexy, stable and fast version. --- src/Text/Hakyll/Internal/Cache.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/Text/Hakyll/Internal') diff --git a/src/Text/Hakyll/Internal/Cache.hs b/src/Text/Hakyll/Internal/Cache.hs index 8e52bb4..454a4c5 100644 --- a/src/Text/Hakyll/Internal/Cache.hs +++ b/src/Text/Hakyll/Internal/Cache.hs @@ -3,10 +3,22 @@ module Text.Hakyll.Internal.Cache , getFromCache ) where +import Control.Monad.Reader (liftIO) import Text.Hakyll.Hakyll (Hakyll) +import Text.Hakyll.File storeInCache :: (Show a) => a -> FilePath -> Hakyll () -storeInCache = undefined +storeInCache value path = do + cachePath <- toCache path + makeDirectories cachePath + liftIO $ writeFile cachePath (show value) getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a) -getFromCache = undefined +getFromCache path = do + cachePath <- toCache path + valid <- isMoreRecent cachePath [path] + if valid then liftIO (getFromCache' cachePath) >>= return . Just + else return Nothing + where + getFromCache' cachePath = do c <- readFile cachePath + return (read c) -- cgit v1.2.3