summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Internal/Cache.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Hakyll/Internal/Cache.hs')
-rw-r--r--src/Text/Hakyll/Internal/Cache.hs16
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)