SqlMessageCatalogueService

works.iterative.sqldb.SqlMessageCatalogueService
See theSqlMessageCatalogueService companion object
class SqlMessageCatalogueService(repository: MessageCatalogueRepository, cacheRef: Ref[Map[Language, Map[String, String]]], defaultLanguage: Language) extends MessageCatalogueService

MessageCatalogueService implementation with database-backed pre-loaded cache.

This service manages the lifecycle of SQL-backed message catalogues:

  • Pre-loads all messages from database at startup (fail-fast via .orDie)
  • Stores messages in in-memory cache (ZIO Ref) for fast synchronous access
  • Supports hot reload of messages from database without application restart

Lifecycle:

  1. Startup: Pre-load all configured languages from database (parallel loading) 2. Runtime: Serve messages from in-memory cache (no database queries) 3. On demand: Reload messages from database via reload() method

Key characteristics:

  • Fail-fast startup: Application won't start if messages cannot be loaded
  • Zero database queries during message retrieval (all queries at startup/reload)
  • Thread-safe concurrent access via ZIO Ref atomic updates
  • Hot reload support: Update database, call reload(), no restart needed
  • Atomic cache updates: Reload errors leave existing cache unchanged

Performance:

  • Startup: ~100-200ms for 10K messages across multiple languages
  • Reload: ~50-200ms depending on message count and language count
  • Lookup: O(1) map access (identical to JSON implementation)

Value parameters

cacheRef

Reference to the in-memory cache of messages by language

defaultLanguage

The default language to use when messages() is called

repository

The repository for loading messages from database

Attributes

See also

works.iterative.core.service.impl.InMemoryMessageCatalogue for the message catalogue implementation

MessageCatalogueRepository for database access

docs/message-catalogue-reload.md for reload mechanism documentation

Companion
object
Graph
Supertypes
trait MessageCatalogueService
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def forLanguage(language: Language): UIO[MessageCatalogue]

Attributes

Definition Classes
MessageCatalogueService
override def messages: UIO[MessageCatalogue]

Attributes

Definition Classes
MessageCatalogueService
def reload(language: Option[Language]): Task[Unit]

Reloads messages from the database for specified language(s). This method is on the concrete class (not MessageCatalogueService trait) because the JSON implementation cannot reload messages from files.

Reloads messages from the database for specified language(s). This method is on the concrete class (not MessageCatalogueService trait) because the JSON implementation cannot reload messages from files.

Value parameters

language

None to reload all configured languages, Some(lang) to reload specific language

Attributes

Returns

Task that completes when reload is finished