@@ -3,6 +3,7 @@
3{-# LANGUAGE ExistentialQuantification #-}
3{-# LANGUAGE ExistentialQuantification #-}
4module Hakyll.Core.Store
4module Hakyll.Core.Store
6 , makeStore
7 , makeStore
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
26data Storable = forall a. (Binary a, Typeable a) => Storable a
27data Storable = forall a. (Binary a, Typeable a) => Storable a
29+-- | Result when an item from the store
31+data StoreGet a = Found a
34+ deriving (Show, Eq, Ord)
28-- | Data structure used for the store
36-- | Data structure used for the store
30data Store = Store
38data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
72-- | Load an item
80-- | Load an item
74storeGet :: (Binary a, Typeable a)
82storeGet :: (Binary a, Typeable a)
75− => Store -> String -> Identifier -> IO (Maybe a)
83+ => Store -> String -> Identifier -> IO (StoreGet a)
76storeGet store name identifier = do
84storeGet store name identifier = do
77 -- First check the in-memory map
85 -- First check the in-memory map
78 map' <- readMVar $ storeMap store
86 map' <- readMVar $ storeMap store
79 case M.lookup path map' of
87 case M.lookup path map' of
80 -- Found in the in-memory map
88 -- Found in the in-memory map
81− Just (Storable s) -> return $ cast s
89+ Just (Storable s) -> return $ case cast s of
82 -- Not found in the map, try the filesystem
92 -- Not found in the map, try the filesystem
83 Nothing -> do
93 Nothing -> do
84 exists <- doesFileExist path
94 exists <- doesFileExist path
85 if not exists
95 if not exists
86 -- Not found in the filesystem either
96 -- Not found in the filesystem either
87− then return Nothing
97+ then return NotFound
88 -- Found in the filesystem
98 -- Found in the filesystem
89 else do v <- decodeFile path
99 else do v <- decodeFile path
90 addToMap store path v
100 addToMap store path v
91− return $ Just v
101+ return $ Found v
93 path = makePath store name identifier
103 path = makePath store name identifier