Safe Haskell | None |
---|
Provides a general caching interface along with a simple in-memory (process only) and file based cache implementations.
- class Cache c where
- put :: MonadIO m => c -> String -> ByteString -> m ByteString
- fetch :: MonadIO m => c -> String -> m (Maybe ByteString)
- invalidate :: MonadIO m => c -> String -> m ()
- fetchOr :: (Cache c, MonadIO m) => c -> String -> m ByteString -> m ByteString
- data FileSystemCache
- newFileSystemCache :: FilePath -> FileSystemCache
- data InMemCache
- newInMemCache :: MonadIO m => m InMemCache
Cache Interface
A class that captures a simple key-value caching interface. The keys are simply 'String'\'s and values are simply 'ByteString'\'s.
put :: MonadIO m => c -> String -> ByteString -> m ByteStringSource
Store a value in the cache. The returned value should be the value that was just stored.
fetch :: MonadIO m => c -> String -> m (Maybe ByteString)Source
Retrieve a value from the cache.
invalidate :: MonadIO m => c -> String -> m ()Source
Invalidate a potentially existing value in the cache. Depending on the implementation this may or may not free the space used by the key-value pair.
fetchOr :: (Cache c, MonadIO m) => c -> String -> m ByteString -> m ByteStringSource
Cache Implementations
data FileSystemCache Source
A file based cache implementation. Files are stored in subdirectories of
fsCacheBase
.
newFileSystemCache :: FilePath -> FileSystemCacheSource
Create a new FileSystemCache
.
data InMemCache Source
An in-memory cache implementation. The current processes heap space is simply used as the cache.
newInMemCache :: MonadIO m => m InMemCacheSource
Create a new InMemCache
.