summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Internal/Cache.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-24 11:31:36 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-24 11:31:36 +0100
commit4295de01bc524b5dccb17dfe2e50f2121feeea07 (patch)
tree1faffd2eeae3b907bfd130bb765368d8eb181b42 /src/Text/Hakyll/Internal/Cache.hs
parent59e3c7f277a64f09ef65c4ca42d7c2398f04acd4 (diff)
downloadhakyll-4295de01bc524b5dccb17dfe2e50f2121feeea07.tar.gz
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.
Diffstat (limited to 'src/Text/Hakyll/Internal/Cache.hs')
-rw-r--r--src/Text/Hakyll/Internal/Cache.hs14
1 files changed, 8 insertions, 6 deletions
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