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:
- 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 MessageCatalogueServiceclass Objecttrait Matchableclass Any
Members list
In this article