@@ -1,9 +1,7 @@
11{-# LANGUAGE RecordWildCards, CPP #-}
22
33module Network.Wai.Handler.Warp.FileInfoCache (
4− -- * Types
54 FileInfo(..)
6− -- * Functions
75 , withFileInfoCache
86 , getInfo -- test purpose only
97 ) where
@@ -24,6 +22,7 @@ import Network.Wai.Handler.Warp.Date (uToH)
2422
2523----------------------------------------------------------------
2624
25+-- | File information.
2726data FileInfo = FileInfo {
2827 fileInfoName :: !FilePath
2928 , fileInfoSize :: !Integer
@@ -37,6 +36,7 @@ type FileInfoCache = Reaper Cache (FilePath,Entry)
3736
3837----------------------------------------------------------------
3938
39+-- | Getting the file information corresponding to the file.
4040getInfo :: FilePath -> IO FileInfo
4141getInfo path = do
4242 fs <- getFileStatus path -- file access
@@ -79,6 +79,9 @@ negative Reaper{..} path = do
7979
8080----------------------------------------------------------------
8181
82+-- | Creating a file information cache
83+-- and executing the action in the second argument.
84+-- The first argument is a cache duration in second.
8285withFileInfoCache :: Int -> ((FilePath -> IO FileInfo) -> IO a) -> IO a
8386withFileInfoCache 0 action = action getInfo
8487withFileInfoCache duration action = E.bracket (initialize duration)