Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.FileCache
Description
This module let you create caches where keys are file names, and values are automatically expired when the file is modified for any reason.
This is usually done in the following fashion :
cache <- newFileCache o <- query cache "/path/to/file" computation
The computation will be used to populate the cache if this call results in a miss. The result is forced to WHNM.
- type FileCache = FileCacheR String
- data FileCacheR r a
- newFileCache :: IO (FileCacheR r a)
- killFileCache :: FileCacheR r a -> IO ()
- invalidate :: FilePath -> FileCacheR e a -> IO ()
- query :: IsString e => FileCacheR e a -> FilePath -> IO (Either e a) -> IO (Either e a)
- getCache :: FileCacheR e a -> IO (HashMap FilePath (Either e a, WatchDescriptor))
- lazyQuery :: IsString r => FileCacheR r a -> FilePath -> IO (Either r a) -> IO (Either r a)
Documentation
type FileCache = FileCacheR String #
A default type synonym, for String errors.
data FileCacheR r a #
The main FileCache type, for queries returning 'Either r a'. The r
type must be an instance of Error
.
newFileCache :: IO (FileCacheR r a) #
Generates a new file cache. The opaque type is for use with other functions.
killFileCache :: FileCacheR r a -> IO () #
Destroys the thread running the FileCache. Pretty dangerous stuff.
invalidate :: FilePath -> FileCacheR e a -> IO () #
Manually invalidates an entry.
Arguments
:: IsString e | |
=> FileCacheR e a | |
-> FilePath | Path of the file entry |
-> IO (Either e a) | The computation that will be used to populate the cache |
-> IO (Either e a) |
Queries the cache, populating it if necessary, returning a strict
Either
(from Data.Either.Strict).
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.
getCache :: FileCacheR e a -> IO (HashMap FilePath (Either e a, WatchDescriptor)) #
Gets a copy of the cache.