CurrencyConversionCache.ktAn in-memory cache for currency pairs and their conversion rates. Extends AbstractCache, implementing the ProjectForge caching pattern with lazy refresh. Also acts as a BaseDOModifiedListener for CurrencyPairDO to invalidate the cache on inserts/updates. Provides bidirectional rate lookup with automatic inverse-rate computation.
checkRefresh()/refresh()/setExpired()| Field | Type | Purpose |
|---|---|---|
currencyPairMap | Map<Long, CurrencyPairDO> | Primary lookup by database primary key |
currencyPairLookupMap | Map<Pair<String,String>, Long> | Quick lookup by (source, target) → pair id |
The refresh() method runs inside a read-only transaction via persistenceService.runIsolatedReadOnly(). It loads all non-deleted CurrencyPairDO entries and all their non-deleted rates (sorted by validFrom DESC). Rates are grouped by currency pair id and assigned to the pair's transient rates list.
findCurrencyPairForConversion(source, target) first tries a direct lookup (e.g. EUR→USD). If not found, it tries the inverse direction (USD→EUR) and returns a CurrencyPairLookup with useInverseRate=true, signaling the caller to use 1/rate.
findActiveRate() with useFallbackToOldestRate=true will log a warning and return the oldest available rate when no rate is valid for the requested date. This is explicitly documented as potentially non-compliant for financial accounting.
| Property | Type | Description |
|---|---|---|
pair | CurrencyPairDO | The matching currency pair |
useInverseRate | Boolean | If true, the caller should apply 1/conversionRate |
| Method | Description |
|---|---|
getCurrencyPair(id) | Retrieve a currency pair by its primary key |
findCurrencyPair(src, tgt) | Direct lookup by source and target currency codes |
findCurrencyPairForConversion(src, tgt) | Bidirectional lookup with inverse rate support |
getConversionRate(pairId, date) | Finds the active rate for a pair at a given date (optionally inverse) |
getActiveRateDate(pairId, date) | Returns the validFrom of the active rate |
getRates(pairId) | Returns all rates for a currency pair |
@PostConstruct: registers itself with currencyPairDao as a listener and stores the singleton in the companion object.checkRefresh() triggers refresh().CurrencyPairDO is modified, afterInsertOrModify() calls setExpired().CurrencyConversionServiceSupport) also call cache.setExpired() directly.868d6abb7 2025 -> 2026 f4a839e3a CurrencyConversion: Show date of active rates in list view. 472fbc977 WIP: currency conversion with Claude Code. 8c2bf04f0 WIP: currency conversion with Claude Code. abdac2e1b WIP: currency conversion with Claude Code. e1323795d WIP: currency conversion with Claude Code. 357ebee61 WIP: currency conversion with Claude Code.