DistributedCacheService

core.services.cache.DistributedCacheService
class DistributedCacheService[F[_]](system: ActorSystem, selfUniqueAddress: SelfUniqueAddress)(implicit evidence$1: Async[F], ec: ExecutionContext, distributedTtl: Timeout, localTtlWithUnit: (Int, TimeUnit)) extends CacheServiceTrait[F]

A distributed cache service for managing mechanisms and reactions using Akka Distributed Data.

This service provides caching with consistency guarantees across multiple nodes in a cluster. It uses LWWMap (Last-Write-Wins Map) for conflict resolution and performs distributed read and write operations with configurable timeouts. Additionally, it leverages a local cache for optimised read-heavy workloads, reducing latency for frequently accessed data.

Type parameters

F

The effect type (e.g., IO, Future, etc.) used to encapsulate asynchronous computations in a functional manner.

Value parameters

distributedTtl

The timeout for distributed operations such as Get and Update in Akka Distributed Data. This defines how long the system will wait for responses in a distributed environment.

ec

The ExecutionContext used for handling asynchronous operations within the service. Ensures non-blocking execution of distributed reads and writes.

localTtlWithUnit

A tuple specifying the expiration duration for entries in the local cache. The tuple consists of an integer value representing the duration and a TimeUnit specifying the unit (e.g., minutes, seconds).

selfUniqueAddress

The unique address of the current node interacting with the cache. This address is used to identify updates and ensure correct state replication in the LWWMap.

system

The ActorSystem used for Akka operations, required to initialise the Distributed Data replicator. It enables communication and coordination across nodes in the cluster.

Attributes

Source
DistributedCacheService.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def cleanExpiredEntries: F[Unit]

Cleans expired entries from the cache.

Cleans expired entries from the cache.

Attributes

Returns

An effect indicating completion.

Definition Classes
Source
DistributedCacheService.scala
override def createMechanism(id: MechanismId, mechanism: Mechanism): F[Either[String, Mechanism]]

Creates a mechanism in the cache if it doesn't already exist.

Creates a mechanism in the cache if it doesn't already exist.

Value parameters

id

The ID of the mechanism.

mechanism

The Mechanism instance to create.

Attributes

Returns

An effect wrapping either an error message if the mechanism exists, or the created mechanism.

Definition Classes
Source
DistributedCacheService.scala
override def createReaction(id: ReactionId, reaction: Reaction): F[Either[String, Reaction]]

Creates a reaction in the cache if it doesn't already exist.

Creates a reaction in the cache if it doesn't already exist.

Value parameters

id

The ID of the reaction.

reaction

The Reaction instance to create.

Attributes

Returns

An effect wrapping either an error message if the reaction exists, or the created reaction.

Definition Classes
Source
DistributedCacheService.scala
override def getMechanism(id: MechanismId): F[Option[Mechanism]]

Retrieves a mechanism from the cache.

Retrieves a mechanism from the cache.

Value parameters

id

The ID of the mechanism.

Attributes

Returns

An effect wrapping an optional Mechanism.

Definition Classes
Source
DistributedCacheService.scala
override def getMechanismDetails(id: MechanismId): F[Option[MechanismDetails]]

Retrieves a mechanism's details from the cache.

Retrieves a mechanism's details from the cache.

Value parameters

id

The ID of the mechanism.

Attributes

Returns

An effect wrapping an optional MechanismDetails.

Definition Classes
Source
DistributedCacheService.scala
override def getReaction(id: ReactionId): F[Option[Reaction]]

Retrieves a reaction from the cache.

Retrieves a reaction from the cache.

Value parameters

id

The ID of the reaction.

Attributes

Returns

An effect wrapping an optional Reaction.

Definition Classes
Source
DistributedCacheService.scala
override def getReactionDetails(id: ReactionId): F[Option[ReactionDetails]]

Retrieves a reaction's details from the cache.

Retrieves a reaction's details from the cache.

Value parameters

id

The ID of the reaction.

Attributes

Returns

An effect wrapping an optional ReactionDetails.

Definition Classes
Source
DistributedCacheService.scala
override def putMechanism(id: MechanismId, mechanism: Mechanism): F[Unit]

Caches a mechanism by its ID.

Caches a mechanism by its ID.

Value parameters

id

The ID of the mechanism.

mechanism

The Mechanism instance to cache.

Attributes

Returns

An effect indicating completion.

Definition Classes
Source
DistributedCacheService.scala
override def putMechanismDetails(id: MechanismId, mechanismDetails: MechanismDetails): F[Unit]

Caches a mechanism's details by its ID.

Caches a mechanism's details by its ID.

Value parameters

id

The ID of the mechanism.

mechanismDetails

The MechanismDetails instance to cache.

Attributes

Returns

An effect indicating completion.

Definition Classes
Source
DistributedCacheService.scala
override def putReaction(id: ReactionId, reaction: Reaction): F[Unit]

Caches a reaction by its ID.

Caches a reaction by its ID.

Value parameters

id

The ID of the reaction.

reaction

The Reaction instance to cache.

Attributes

Returns

An effect indicating completion.

Definition Classes
Source
DistributedCacheService.scala
override def putReactionDetails(id: ReactionId, reactionDetails: ReactionDetails): F[Unit]

Caches a reaction's details by its ID.

Caches a reaction's details by its ID.

Value parameters

id

The ID of the reaction.

reactionDetails

The ReactionDetails instance to cache.

Attributes

Returns

An effect indicating completion.

Definition Classes
Source
DistributedCacheService.scala