on master help sign in
Added isMember functions for Store
a3021bcnoxx
src/Hakyll/Core/Store.hs+22
@@ -9,6 +9,7 @@ module Hakyll.Core.Store
9 , new
9 , new
10 , set
10 , set
11 , get
11 , get
12+ , isMember
12 , delete
13 , delete
13 , hash
14 , hash
14 ) where
15 ) where
@@ -100,6 +101,16 @@ cacheLookup (Store _ (Just lru)) key = do
100 Nothing -> WrongType (typeOf (undefined :: a)) (typeOf x)
101 Nothing -> WrongType (typeOf (undefined :: a)) (typeOf x)
101
102
102
103
104+--------------------------------------------------------------------------------
105+cacheIsMember :: Store -> String -> Bool
106+cacheIsMember (Store _ Nothing) _ = False
107+cacheIsMember (Store _ (Just lru)) key =
108+ let res = Lru.lookup key lru in
109+ case Just res of
110+ Nothing -> False
111+ _ -> True
112+
113+
103--------------------------------------------------------------------------------
114--------------------------------------------------------------------------------
104-- | Auxiliary: delete an item from the in-memory cache
115-- | Auxiliary: delete an item from the in-memory cache
105cacheDelete :: Store -> String -> IO ()
116cacheDelete :: Store -> String -> IO ()
@@ -151,6 +162,17 @@ get store identifier = do
151 return $ decode lbs
162 return $ decode lbs
152
163
153
164
165+--------------------------------------------------------------------------------
166+-- | Strict function
167+isMember :: Store -> [String] -> IO Bool
168+isMember store identifier
169+ | cacheIsMember store key = return True
170+ | otherwise = doesFileExist path
171+
172+ where
173+ key = hash identifier
174+ path = storeDirectory store </> key
175+
154--------------------------------------------------------------------------------
176--------------------------------------------------------------------------------
155-- | Delete an item
177-- | Delete an item
156delete :: Store -> [String] -> IO ()
178delete :: Store -> [String] -> IO ()