on 892cae9 help sign in
24 lines 742 B history raw
1module Text.Hakyll.Internal.Cache
2 ( storeInCache
3 , getFromCache
4 ) where
6import Control.Monad.Reader (liftIO)
7import Text.Hakyll.Hakyll (Hakyll)
8import Text.Hakyll.File
10storeInCache :: (Show a) => a -> FilePath -> Hakyll ()
11storeInCache value path = do
12 cachePath <- toCache path
13 makeDirectories cachePath
14 liftIO $ writeFile cachePath (show value)
16getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a)
17getFromCache path = do
18 cachePath <- toCache path
19 valid <- isMoreRecent cachePath [path]
20 if valid then liftIO (getFromCache' cachePath) >>= return . Just
21 else return Nothing
22 where
23 getFromCache' cachePath = do c <- readFile cachePath
24 return (read c)