@@ -22,6 +22,7 @@ import Data.Typeable (Typeable, TypeRep, cast, typeOf)
23import Hakyll.Core.Identifier
23import Hakyll.Core.Identifier
24import Hakyll.Core.Util.File
24import Hakyll.Core.Util.File
25+import qualified Data.Cache.LRU.IO as LRU
26-- | Items we can store
27-- | Items we can store
@@ -40,40 +41,44 @@ data Store = Store
40 { -- | All items are stored on the filesystem
41 { -- | All items are stored on the filesystem
41 storeDirectory :: FilePath
42 storeDirectory :: FilePath
42 , -- | And some items are also kept in-memory
43 , -- | And some items are also kept in-memory
43− storeMap :: Maybe (MVar (Map FilePath Storable))
44+ storeLRU :: Maybe (LRU.AtomicLRU FilePath Storable)
47+-- | The size of the in-memory cache to use in items.
48+storeLRUSize :: Maybe Integer
49+storeLRUSize = Just 500
46-- | Initialize the store
51-- | Initialize the store
48makeStore :: Bool -- ^ Use in-memory caching
53makeStore :: Bool -- ^ Use in-memory caching
49 -> FilePath -- ^ Directory to use for hard disk storage
54 -> FilePath -- ^ Directory to use for hard disk storage
50 -> IO Store -- ^ Store
55 -> IO Store -- ^ Store
51makeStore inMemory directory = do
56makeStore inMemory directory = do
52− mvar <- if inMemory then Just <$> newMVar M.empty else return Nothing
57+ lru <- if inMemory then Just <$> LRU.newAtomicLRU storeLRUSize else return Nothing
53 return Store
58 return Store
54 { storeDirectory = directory
59 { storeDirectory = directory
55− , storeMap = mvar
60+ , storeLRU = lru
58-- | Auxiliary: add an item to the map
63-- | Auxiliary: add an item to the map
60cacheInsert :: (Binary a, Typeable a) => Store -> FilePath -> a -> IO ()
65cacheInsert :: (Binary a, Typeable a) => Store -> FilePath -> a -> IO ()
61cacheInsert (Store _ Nothing) _ _ = return ()
66cacheInsert (Store _ Nothing) _ _ = return ()
62−cacheInsert (Store _ (Just mv)) path value =
67+cacheInsert (Store _ (Just lru)) path value =
63− modifyMVar_ mv $ return . M.insert path (Storable value)
68+ LRU.insert path (Storable value) lru
65-- | Auxiliary: get an item from the cache
70-- | Auxiliary: get an item from the cache
67cacheLookup :: forall a. (Binary a, Typeable a)
72cacheLookup :: forall a. (Binary a, Typeable a)
68 => Store -> FilePath -> IO (StoreGet a)
73 => Store -> FilePath -> IO (StoreGet a)
69cacheLookup (Store _ Nothing) _ = return NotFound
74cacheLookup (Store _ Nothing) _ = return NotFound
70−cacheLookup (Store _ (Just mv)) path = do
75+cacheLookup (Store _ (Just lru)) path = do
72− case M.lookup path map' of
76+ res <- LRU.lookup path lru
73− Nothing -> return NotFound
78+ Nothing -> return NotFound
74− Just (Storable s) -> return $ case cast s of
79+ Just (Storable s) -> return $ case cast s of
75− Nothing -> WrongType (typeOf s) $ typeOf (undefined :: a)
80+ Nothing -> WrongType (typeOf s) $ typeOf (undefined :: a)
76− Just s' -> Found s'
81+ Just s' -> Found s'
78-- | Create a path
83-- | Create a path