EN · DE · RU · FR · ES

#825: AddressImageCache.kt

projectforge-business/src/main/kotlin/org/projectforge/business/address/AddressImageCache.kt @Component — Application-level cache, projectforge-business/src/main/kotlin/org/projectforge/business/address/AddressImageCache.kt 102 lines · 54 code · 38 comments · 10 blank
In-memory cache mapping address IDs to AddressImageDO metadata (excluding binary image data). Provides fast lookup of whether an address has an image and what its type is.

Architecture

AddressImageCache extends AbstractCache, ProjectForge's base class for refreshable caches. The framework calls refresh() periodically or on-demand, synchronized to prevent concurrent modifications.

Data Model

The cache stores a Map<Long, AddressImageDO> where each value is a lightweight AddressImageDO containing only:

Binary data is excluded — neither preview nor image byte arrays are loaded. This keeps the cache memory-efficient while still answering "does address X have an image?" queries instantly.

Refresh Strategy

refresh() runs inside a read-only isolated persistence context (for clean transaction boundaries). It uses a JPQL query selecting addressId, lastUpdate, and imageType as a Tuple projection, rebuilding the entire map atomically to avoid concurrent read issues.

Usage

getImage(addressId) is the sole public API. It calls checkRefresh() (inherited from AbstractCache) to ensure freshness before looking up the map. A null return means no image exists for that address.

Singleton Access

The companion object holds a lateinit var instance set in @PostConstruct, allowing static access from code that cannot use Spring injection.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
943947aaa Addresses: support of gif and jpeg
0ceceb28f All cache refreshs are now running in isolated transactions
5989b32fd BaseDao: mechanism of onChangeLister refactored.
1b50060c3 BaseDao: renamed: get -> find, save -> insert, getList -> select, load -> select