Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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.
Synopsis
- 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 :: forall e a. IsString e => FileCacheR e a -> FilePath -> IO (Either e a) -> IO (Either e a)
- type OnModified = IO ()
- queryWith :: forall e a. IsString e => FileCacheR e a -> FilePath -> OnModified -> IO (Either e a) -> IO (Either e a)
- getCache :: FileCacheR e a -> IO (Map FilePath (Either e a))
- lazyQuery :: IsString r => FileCacheR r a -> FilePath -> IO (Either r a) -> IO (Either r a)
Documentation
type FileCache = FileCacheR String Source #
A default type synonym, for String errors.
data FileCacheR r a Source #
The main FileCache type, for queries returning 'Either r a'. The r
type must be an instance of Error
.
newFileCache :: IO (FileCacheR r a) Source #
Generates a new file cache. The opaque type is for use with other functions.
killFileCache :: FileCacheR r a -> IO () Source #
Destroys the thread running the FileCache. Pretty dangerous stuff.
invalidate :: FilePath -> FileCacheR e a -> IO () Source #
Manually invalidates an entry.
Arguments
:: forall e a. 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.
type OnModified = IO () Source #
Hook to invoke after an entry is removed from the cache (because the corresponding file has been modified)
Arguments
:: forall e a. IsString e | |
=> FileCacheR e a | |
-> FilePath | Path of the file entry |
-> OnModified | |
-> IO (Either e a) | The computation that will be used to populate the cache |
-> IO (Either e a) |
Generalization of query
that allows to specify an OnModified
hook