Repository navigation
Feat/currency placeholder and local caching - #23
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It adds concurrency-sensitive caching with cross-node Redis invalidation on the money/balance path, with no tests in the affected modules, so final human review is warranted.
Review effort: Balanced
Findings: None
What changed in this PR
This PR adds locally-cached, non-suspending balance reads for the client runtime and exposes them through PlaceholderAPI on Paper. A new BalanceCache keeps per-default-account balances in a Caffeine cache that is never recomputed locally; instead, whenever a transaction touches an account the balance is re-queried from the microservice. Cross-node consistency is achieved by publishing a BalanceChangedEvent over Redis so other servers refresh their cached entries, while the originating server refreshes locally and skips its own event. Three PAPI placeholders (current-balance, current-balance-short, currency-display) surface this data in-game.
Changes:
- Introduce
BalanceCache(background-loaded, versioned, event-invalidated) and wireTransactionServiceImplto invalidate it on every balance-changing operation (begin/commit/rollback/deposit/withdraw/transfer). - Add
BalanceChangedEvent+BalanceEventsListenerand register the listener inRedisService; dispose the cache scope on client shutdown. - Add PAPI placeholders and expansion, registered from
PaperMain; bump Gradle wrapper to 9.8.0 and project version to 4.1.8.
| File | Description |
|---|---|
.../balance/BalanceCache.kt |
New non-suspending balance cache with background loading, versioned refresh, and Redis-based invalidation. |
.../transaction/TransactionServiceImpl.kt |
Invalidates BalanceCache on all balance-changing results via per-result-type transactions extensions. |
.../redis/events/balance/BalanceChangedEvent.kt |
New serializable Redis event carrying affected account IDs and currency name. |
.../balance/BalanceEventsListener.kt |
Refreshes cached balances on remote BalanceChangedEvent, skipping self-originated events. |
.../redis/RedisService.kt |
Subscribes the new BalanceEventsListener. |
.../client/ClientTransactionalInstance.kt |
Disposes the BalanceCache scope on client disable. |
.../papi/placeholder/CurrentBalancePlaceholder.kt |
PAPI placeholder returning the full-precision cached balance. |
.../papi/placeholder/CurrentBalanceShortPlaceholder.kt |
PAPI placeholder returning the cached balance rounded to 2 decimals. |
.../papi/placeholder/CurrencyDisplayPlaceholder.kt |
PAPI placeholder returning a currency symbol. |
.../papi/PapiExpansion.kt |
Aggregates the placeholders into a PAPI expansion. |
.../paper/PaperMain.kt |
Registers the PAPI expansion on enable. |
gradle/wrapper/gradle-wrapper.properties, gradle.properties |
Gradle wrapper 9.8.0 and project version 4.1.8 bumps. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…in add and remove commands
…pecific balance handling
…alance by currency
No description provided.