mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
e17e47ef8c
There are two implementations of a Cache, namely a bounded and an unbounded variant. This can be elegantly captured in a type class. In addition to reducing the amount of error-prone code in the definition of the cache, this version reduces the amount of error-prone code in usage sites of the cache, as it makes the cache into an abstract object, so that a calling site cannot distinguish between cache types. Any decision about what should be cached should be made through the interface of a cache, rather than at the callsite, and this is captured by this variant.
19 lines
519 B
Haskell
19 lines
519 B
Haskell
module Hasura.Cache
|
|
( module Hasura.Cache.Types
|
|
, B.CacheSize(..)
|
|
, B.parseCacheSize
|
|
, initialise
|
|
) where
|
|
|
|
import Hasura.Prelude hiding (lookup)
|
|
|
|
import Hasura.Cache.Types
|
|
import qualified Hasura.Cache.Bounded as B
|
|
import qualified Hasura.Cache.Unbounded as U
|
|
|
|
initialise :: (Hashable k, Ord k) => Maybe B.CacheSize -> IO (Cache k v)
|
|
initialise cacheSizeM =
|
|
case cacheSizeM of
|
|
Nothing -> Cache <$> U.initialise
|
|
Just cacheSize -> Cache <$> B.initialise cacheSize
|