graphql-engine/server/src-lib/Hasura/Cache.hs
Auke Booij e17e47ef8c
server: avoid code duplication using type classes (#4624)
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.
2020-05-13 11:17:32 +02:00

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