blob: 454a4c5db03c5dac38b0e2e08342c4c9316082ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
module Text.Hakyll.Internal.Cache
( storeInCache
, getFromCache
) where
import Control.Monad.Reader (liftIO)
import Text.Hakyll.Hakyll (Hakyll)
import Text.Hakyll.File
storeInCache :: (Show a) => a -> FilePath -> Hakyll ()
storeInCache value path = do
cachePath <- toCache path
makeDirectories cachePath
liftIO $ writeFile cachePath (show value)
getFromCache :: (Read a) => FilePath -> Hakyll (Maybe a)
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)
|