CachedFactoryWithInitData

mill.util.CachedFactoryWithInitData
abstract class CachedFactoryWithInitData[K, InitData, V] extends AutoCloseable

Manage the setup, teardown, and caching of objects of type V safely in a multithreaded environment.

The user provides the setup and teardown logic along with a maxCacheSize, and CachedFactory provides instances of V as requested using the withValue method. These instances are automatically constructed on-demand from the give key, cached with an LRU strategy, and destroyed when they are assertEventually evicted

Intended for relatively small caches approximately O(num-threads) in size that will typically get used in a build system, not intended for caching large amounts of entries

Type parameters

InitData

the transient initialization data that will be passed to setup.

K

the cache key. setup will be invoked if the key is not found in the cache.

V

the cached value

Attributes

Source
CachedFactory.scala
Graph
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def maxCacheSize: Int

Attributes

Source
CachedFactory.scala
def setup(key: K, initData: InitData): V

Attributes

Source
CachedFactory.scala
def teardown(key: K, value: V): Unit

Attributes

Source
CachedFactory.scala

Concrete methods

def cacheEntryStillValid(key: K, initData: => InitData, value: V): Boolean

Returns true if the cache entry associated with the given key is still valid, false otherwise.

Returns true if the cache entry associated with the given key is still valid, false otherwise.

If false, the entry will be removed from the cache and setup will be invoked.

Attributes

Source
CachedFactory.scala
def close(): Unit

Attributes

Source
CachedFactory.scala
def withValue[R](key: K, initData: => InitData)(block: V => R): R

Attributes

Source
CachedFactory.scala