diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-20 17:10:08 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-20 17:10:08 +0100 |
commit | 892cae9da263d9f2fad4d93dd6d6c50fb12add16 (patch) | |
tree | a3ec2acd763ade28d6377959471b1e015e3e3868 /src/Text/Hakyll/Internal | |
parent | 8602f23f7bcdcc3bec65ec98c70ee3f295482856 (diff) | |
download | hakyll-892cae9da263d9f2fad4d93dd6d6c50fb12add16.tar.gz |
Added caching again. But now the more sexy, stable and fast version.
Diffstat (limited to 'src/Text/Hakyll/Internal')
-rw-r--r-- | src/Text/Hakyll/Internal/Cache.hs | 16 |
1 files changed, 14 insertions, 2 deletions
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) |