Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Cache k v = Cache {
- cacheGet :: k -> IO (Maybe v)
- cachePut :: k -> v -> IO ()
- cacheDelete :: k -> IO ()
- cacheVacuum :: IO Int
- cacheFetch :: (k -> IO v) -> Cache k v -> k -> IO v
- cached :: Cache k v -> (k -> IO v) -> k -> IO v
- nullCache :: Cache k v
- appendCache :: Cache k v -> Cache k v -> Cache k v
- transformCache :: (k -> j) -> (j -> Maybe k) -> (v -> IO (Maybe u)) -> (u -> IO (Maybe v)) -> Cache j u -> Cache k v
Documentation
Common interface for cache backends.
In Cache k v
, k
is the key type and v
the value type.
cacheFetch :: (k -> IO v) -> Cache k v -> k -> IO v Source #
cacheFetch load cache key
fetches a value at the key
from the cache
,
failing over to the load
action when the key is not present in the cache,
and adding it to the cache.
transformCache :: (k -> j) -> (j -> Maybe k) -> (v -> IO (Maybe u)) -> (u -> IO (Maybe v)) -> Cache j u -> Cache k v Source #
Wrap a cache such that the new cache uses different types for the keys and values, using the provided transformation functions. A typical application for this is to serialize data structures into a more palatable format for caching while exposing a more useful kind of data structure