From 4295de01bc524b5dccb17dfe2e50f2121feeea07 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 24 Jan 2010 11:31:36 +0100 Subject: Added tagMap caching. Because the readTagMap function was currently one of the bottlenexks, this has caused a speedup of 900% for some test cases, so yay for that. --- src/Text/Hakyll/Internal/Cache.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/Text/Hakyll/Internal/Cache.hs') diff --git a/src/Text/Hakyll/Internal/Cache.hs b/src/Text/Hakyll/Internal/Cache.hs index d28f849..0deb5f4 100644 --- a/src/Text/Hakyll/Internal/Cache.hs +++ b/src/Text/Hakyll/Internal/Cache.hs @@ -1,8 +1,10 @@ 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 @@ -20,9 +22,9 @@ storeInCache value path = do -- cache. This function performs a timestamp check on the filepath and the -- filepath in the cache, and only returns the cached value when it is still -- up-to-date. -getFromCache :: (Binary a) => FilePath -> Hakyll (Maybe a) -getFromCache path = do - cachePath <- toCache path - valid <- isMoreRecent cachePath [path] - if valid then liftIO (decodeFile cachePath) >>= return . Just - else return Nothing +getFromCache :: (Binary a) => FilePath -> Hakyll a +getFromCache = liftIO . decodeFile <=< toCache + +-- | Check if a file in the cache is more recent than a number of other files. +isCacheMoreRecent :: FilePath -> [FilePath] -> Hakyll Bool +isCacheMoreRecent file depends = toCache file >>= flip isMoreRecent depends -- cgit v1.2.3