IntlLangMemoizer

Per-language memoizer that caches instances by type.

Thread-safe via copy-on-write AtomicRef maps. Concurrent readers never block; writers contend via CAS, with the loser rebuilding from the winner's snapshot. The factory passed to withTryGet / getOrCreateFormatter may run more than once under heavy contention (a benign form of wasted work — the cache only ever holds one canonical instance per key, and factories are expected to be pure).

Safe to share across threads: the owning dev.kbroom.fluent.bundle.FluentBundle is immutable by construction, and this cache only grows via copy-on-write.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun clear()

Clear all cached values for this language.

Link copied to clipboard
fun <T : Any> getFormatterOrNull(name: String, options: Any?): T?

Get a cached formatter if it exists.

Link copied to clipboard
fun <T : Any> getOrCreateFormatter(name: String, options: Any?, factory: () -> T): T

Get or create a formatter with the given name and options. The options should be a data class with consistent equals/hashCode.

Link copied to clipboard
fun <T : Any> getOrNull(clazz: KClass<T>): T?

Get a cached value if it exists.

Link copied to clipboard
fun size(): Int

Get the number of cached items.

Link copied to clipboard
fun <T : Any, R> withTryGet(clazz: KClass<T>, factory: () -> T, block: (T) -> R): R

Try to get a cached instance of type T, or create one if not cached.