on ee682ab help sign in
30 lines 1.2 kB history raw
1module Text.Hakyll.Internal.Cache
2 ( storeInCache
3 , getFromCache
4 , isCacheMoreRecent
5 ) where
7import Control.Monad ((<=<))
8import Control.Monad.Reader (liftIO)
9import Text.Hakyll.Hakyll (Hakyll)
10import Text.Hakyll.File
11import Data.Binary
13-- | We can store all datatypes instantiating @Binary@ to the cache. The cache
14-- directory is specified by the @HakyllConfiguration@, usually @_cache@.
15storeInCache :: (Binary a) => a -> FilePath -> Hakyll ()
16storeInCache value path = do
17 cachePath <- toCache path
18 makeDirectories cachePath
19 liftIO $ encodeFile cachePath value
21-- | Get a value from the cache. The filepath given should not be located in the
22-- cache. This function performs a timestamp check on the filepath and the
23-- filepath in the cache, and only returns the cached value when it is still
24-- up-to-date.
25getFromCache :: (Binary a) => FilePath -> Hakyll a
26getFromCache = liftIO . decodeFile <=< toCache
28-- | Check if a file in the cache is more recent than a number of other files.
29isCacheMoreRecent :: FilePath -> [FilePath] -> Hakyll Bool
30isCacheMoreRecent file depends = toCache file >>= flip isMoreRecent depends