module Text.Hakyll.Internal.Cache
( storeInCache
, getFromCache
, isCacheMoreRecent
) where
import Control.Monad ((<=<))
import Control.Monad.Reader (liftIO)
import Text.Hakyll.Hakyll (Hakyll)
import Text.Hakyll.File
import Data.Binary
storeInCache :: (Binary a) => a -> FilePath -> Hakyll ()
storeInCache value path = do
cachePath <- toCache path
makeDirectories cachePath
liftIO $ encodeFile cachePath value
getFromCache :: (Binary a) => FilePath -> Hakyll a
getFromCache = liftIO . decodeFile <=< toCache
isCacheMoreRecent :: FilePath -> [FilePath] -> Hakyll Bool
isCacheMoreRecent file depends = toCache file >>= flip isFileMoreRecent depends