filecache 0.2.6 → 0.2.7
raw patch · 2 files changed
+9/−9 lines, 2 files
Files
- Data/FileCache.hs +8/−8
- filecache.cabal +1/−1
Data/FileCache.hs view
@@ -14,11 +14,11 @@ import System.INotify import Control.Concurrent.STM import qualified Data.Either.Strict as S-import Control.Exception import Control.Monad.Catch import Control.Exception.Lens import Control.Applicative import Control.Monad (join)+import Data.String -- | The main FileCache type, for queries returning 'Either r a'. The r -- type must be an instance of 'Error'.@@ -29,7 +29,7 @@ -- | Generates a new file cache. The opaque type is for use with other -- functions.-newFileCache :: Exception e => IO (FileCacheR r a)+newFileCache :: IO (FileCacheR r a) newFileCache = FileCache <$> newTVarIO HM.empty <*> initINotify -- | Destroys the thread running the FileCache. Pretty dangerous stuff.@@ -37,7 +37,7 @@ killFileCache (FileCache _ ino) = killINotify ino -- | Manually invalidates an entry.-invalidate :: Exception e => FilePath -> FileCacheR e a -> IO ()+invalidate :: FilePath -> FileCacheR e a -> IO () invalidate fp (FileCache q _) = join $ atomically $ do mp <- readTVar q case HM.lookup fp mp of@@ -52,7 +52,7 @@ -- Queries that fail with an 'IOExeception' will not create a cache entry. -- Also please note that there is a race condition between the potential -- execution of the computation and the establishment of the watch.-query :: Exception e+query :: IsString e => FileCacheR e a -> FilePath -- ^ Path of the file entry -> IO (S.Either e a) -- ^ The computation that will be used to populate the cache@@ -71,11 +71,11 @@ change = atomically . modifyTVar q nochange = return () catches (action >>= withWatch)- [ handler _IOException (\io -> return (S.Left (strMsg $ show io)))- , handler id (\e -> withWatch (S.Left (strMsg $ show e)))+ [ handler _IOException (return . S.Left . fromString . show)+ , handler id (withWatch . S.Left . fromString . show) ] -- | Just like `query`, but with the standard "Either" type.-lazyQuery :: Exception e r+lazyQuery :: IsString r => FileCacheR r a -> FilePath -- ^ Path of the file entry -> IO (Either r a) -- ^ The computation that will be used to populate the cache@@ -88,6 +88,6 @@ unstrict (S.Right x) = Right x -- | Gets a copy of the cache.-getCache :: Exception e => FileCacheR e a -> IO (HM.HashMap FilePath (S.Either e a, WatchDescriptor))+getCache :: FileCacheR e a -> IO (HM.HashMap FilePath (S.Either e a, WatchDescriptor)) getCache (FileCache q _) = atomically (readTVar q)
filecache.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: filecache-version: 0.2.6+version: 0.2.7 synopsis: A Linux-only cache system associating values to files. description: A Linux-only cache system, that works by associating computation results with file names. When the files are modified, the cache entries are discarded. homepage: http://lpuppet.banquise.net/