memcache-0.5.1.0: Database/Memcache/Types/Cluster.hs
{-|
Module : Database.Memcache.Types.Cluster
Description : The Cluster type
Copyright : (c) David Terei, 2016
License : BSD
Maintainer : code@davidterei.com
Stability : stable
Portability : GHC
The 'Cluster' type, with all its fields. "Database.Memcache.Cluster" exports
it abstractly; "Database.Memcache.ElastiCacheClient" also sets
'cStopRefresh', which @quit@ in "Database.Memcache.Client" runs. Not exposed.
-}
module Database.Memcache.Types.Cluster (
Cluster(..)
) where
import qualified Database.Memcache.Ketama as Ketama
import Database.Memcache.Types (Key)
import Database.Memcache.Types.Server (Server)
import Control.Concurrent.MVar (MVar)
import Data.IORef (IORef)
import Data.Time.Clock (NominalDiffTime)
import qualified Data.Vector as V
-- | Memcached cluster.
data Cluster = Cluster {
-- | Either servers that discovery replaces, or a fixed set of servers
-- and their ketama ring, built on first use.
cServers :: Either (MVar (V.Vector Server)) (V.Vector Server, Ketama.Ring),
-- | For servers in an 'MVar': the ketama ring last built and the
-- servers it was built for.
cRingCache :: IORef (V.Vector Server, Ketama.Ring),
-- See @Options@ for description of these values.
cRetries :: {-# UNPACK #-} !Int,
cFailDelay :: {-# UNPACK #-} !Int, -- ^ microseconds
cDeadDelay :: !NominalDiffTime,
cTimeout :: {-# UNPACK #-} !Int, -- ^ microseconds
cGetServerForKey :: Cluster -> Key -> IO (Maybe Server),
-- | Stop the thread that replaces the servers in 'cServers', as
-- ElastiCache discovery's refresh thread does, so that it can't
-- replace them once @quit@ has closed their connections: @quit@ runs
-- this first. It returns at once and doesn't throw. @pure ()@ for
-- every other cluster, including one made by @setServers@ from an
-- ElastiCache client, as no thread replaces the servers it is given.
cStopRefresh :: IO ()
}