filecache-0.2.9: A Linux-only cache system associating values to files.

Safe HaskellNone
LanguageHaskell98

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

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.

query Source

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)) Source

Gets a copy of the cache.

lazyQuery Source

Arguments

:: 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

-> IO (Either r a) 

Just like query, but with the standard Either type. Note that it is just there for easy interoperability with the more comme Either type, as the result is still forced.