CachedFactoryBase

mill.util.CachedFactoryBase
See theCachedFactoryBase companion object
abstract class CachedFactoryBase[Key, InternalKey, InitData, Value] extends AutoCloseable

A unified cache implementation that combines properties of reference counting and LRU caching.

Values that are actively being used are tracked in a list. When released, values move to an LRU cache for potential reuse. Values are evicted from the LRU cache when it exceeds maxCacheSize.

Type parameters

InitData

transient initialization data passed to setup

InternalKey

the internal key used for caching (can be the same as Key)

Key

the public cache key

Value

the cached value type

Attributes

Companion
object
Source
CachedFactoryBase.scala
Graph
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
Known subtypes
class CachedFactoryWithInitData[K, InitData, V]
class CachedFactory[K, V]
class RefCountedCache[Key, InternalKey, InitData, Value]
Show all

Members list

Type members

Types

type Entry = Entry[Key, InternalKey, Value]

Attributes

Source
CachedFactoryBase.scala

Value members

Abstract methods

def keyToInternalKey(key: Key): InternalKey

Convert the public key to an internal key used for caching.

Convert the public key to an internal key used for caching.

Attributes

Source
CachedFactoryBase.scala
def maxCacheSize: Int

Maximum number of unused values to keep in the LRU cache. Set to 0 to disable caching of unused values (values are closed immediately when released).

Maximum number of unused values to keep in the LRU cache. Set to 0 to disable caching of unused values (values are closed immediately when released).

Attributes

Source
CachedFactoryBase.scala
def setup(key: Key, internalKey: InternalKey, initData: InitData): Value

Create a new value for the given key.

Create a new value for the given key.

Attributes

Source
CachedFactoryBase.scala
def shareValues: Boolean

If true, a value can be used concurrently by multiple consumers (reference counted). If false, a value can only be used by one consumer at a time.

If true, a value can be used concurrently by multiple consumers (reference counted). If false, a value can only be used by one consumer at a time.

Attributes

Source
CachedFactoryBase.scala
def teardown(key: Key, internalKey: InternalKey, value: Value): Unit

Clean up a value when it is evicted from the cache.

Clean up a value when it is evicted from the cache.

Attributes

Source
CachedFactoryBase.scala

Concrete methods

def cacheEntryStillValid(key: Key, internalKey: InternalKey, initData: => InitData, value: Value): Boolean

Returns true if the cache entry associated with the given key is still valid. If false, the entry will be removed from the cache and setup will be invoked.

Returns true if the cache entry associated with the given key is still valid. If false, the entry will be removed from the cache and setup will be invoked.

Attributes

Source
CachedFactoryBase.scala
override def close(): Unit

Attributes

Definition Classes
AutoCloseable
Source
CachedFactoryBase.scala
def getOrCreate(key: Key, initData: => InitData): Value

Get a value for the given key, creating one if necessary. The caller must call release when done with the value.

Get a value for the given key, creating one if necessary. The caller must call release when done with the value.

Attributes

Source
CachedFactoryBase.scala
def release(key: Key): Option[Entry]

Release a reference to the value associated with the given key. If this was the last reference, the value moves to the unused cache.

Release a reference to the value associated with the given key. If this was the last reference, the value moves to the unused cache.

Attributes

Returns

Some(entry) if there are still active references (only possible in shared mode), None otherwise

Source
CachedFactoryBase.scala
def releaseKeyValue(key: Key, value: Value): Option[Entry]

Release a reference to a specific value, matching by value identity. This should be used when shareValues = false and multiple entries may have the same key.

Release a reference to a specific value, matching by value identity. This should be used when shareValues = false and multiple entries may have the same key.

Attributes

Source
CachedFactoryBase.scala
def withValue[R](key: Key, initData: => InitData)(block: Value => R): R

Get a value, use it in the provided block, then release it.

Get a value, use it in the provided block, then release it.

Attributes

Source
CachedFactoryBase.scala