From a3021bc703d8a60a2e6467afce6691ee039f3612 Mon Sep 17 00:00:00 2001 From: noxx Date: Sat, 4 May 2013 12:51:58 +0300 Subject: Added isMember functions for Store --- src/Hakyll/Core/Store.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs index 1208c84..eb2d742 100644 --- a/src/Hakyll/Core/Store.hs +++ b/src/Hakyll/Core/Store.hs @@ -9,6 +9,7 @@ module Hakyll.Core.Store , new , set , get + , isMember , delete , hash ) where @@ -100,6 +101,16 @@ cacheLookup (Store _ (Just lru)) key = do Nothing -> WrongType (typeOf (undefined :: a)) (typeOf x) +-------------------------------------------------------------------------------- +cacheIsMember :: Store -> String -> Bool +cacheIsMember (Store _ Nothing) _ = False +cacheIsMember (Store _ (Just lru)) key = + let res = Lru.lookup key lru in + case Just res of + Nothing -> False + _ -> True + + -------------------------------------------------------------------------------- -- | Auxiliary: delete an item from the in-memory cache cacheDelete :: Store -> String -> IO () @@ -151,6 +162,17 @@ get store identifier = do return $ decode lbs +-------------------------------------------------------------------------------- +-- | Strict function +isMember :: Store -> [String] -> IO Bool +isMember store identifier + | cacheIsMember store key = return True + | otherwise = doesFileExist path + + where + key = hash identifier + path = storeDirectory store key + -------------------------------------------------------------------------------- -- | Delete an item delete :: Store -> [String] -> IO () -- cgit v1.2.3