@@ -1,5 +1,6 @@
11-- | A store for stroing and retreiving items
22--
3+{-# LANGUAGE ExistentialQuantification #-}
34module Hakyll.Core.Store
45 ( Store
56 , makeStore
@@ -14,20 +15,22 @@ import Data.Map (Map)
1415import qualified Data.Map as M
1516
1617import Data.Binary (Binary, encodeFile, decodeFile)
17−import Data.Typeable (Typeable)
18+import Data.Typeable (Typeable, cast)
1819
19−import Hakyll.Core.CompiledItem
20−import Hakyll.Core.Writable
2120import Hakyll.Core.Identifier
2221import Hakyll.Core.Util.File
2322
23+-- | Items we can store
24+--
25+data Storable = forall a. (Binary a, Typeable a) => Storable a
26+
2427-- | Data structure used for the store
2528--
2629data Store = Store
2730 { -- | All items are stored on the filesystem
2831 storeDirectory :: FilePath
2932 , -- | And some items are also kept in-memory
30− storeMap :: MVar (Map FilePath CompiledItem)
33+ storeMap :: MVar (Map FilePath Storable)
3134 }
3235
3336-- | Initialize the store
@@ -42,10 +45,9 @@ makeStore directory = do
4245
4346-- | Auxiliary: add an item to the map
4447--
45−addToMap :: (Binary a, Typeable a, Writable a)
46− => Store -> FilePath -> a -> IO ()
48+addToMap :: (Binary a, Typeable a) => Store -> FilePath -> a -> IO ()
4749addToMap store path value =
48− modifyMVar_ (storeMap store) $ return . M.insert path (compiledItem value)
50+ modifyMVar_ (storeMap store) $ return . M.insert path (Storable value)
4951
5052-- | Create a path
5153--
@@ -55,7 +57,7 @@ makePath store name identifier =
5557
5658-- | Store an item
5759--
58−storeSet :: (Binary a, Typeable a, Writable a)
60+storeSet :: (Binary a, Typeable a)
5961 => Store -> String -> Identifier -> a -> IO ()
6062storeSet store name identifier value = do
6163 makeDirectories path
@@ -66,14 +68,14 @@ storeSet store name identifier value = do
6668
6769-- | Load an item
6870--
69−storeGet :: (Binary a, Typeable a, Writable a)
71+storeGet :: (Binary a, Typeable a)
7072 => Store -> String -> Identifier -> IO (Maybe a)
7173storeGet store name identifier = do
7274 -- First check the in-memory map
7375 map' <- readMVar $ storeMap store
7476 case M.lookup path map' of
7577 -- Found in the in-memory map
76− Just c -> return $ Just $ unCompiledItem c
78+ Just (Storable s) -> return $ cast s
7779 -- Not found in the map, try the filesystem
7880 Nothing -> do
7981 exists <- doesFileExist path