const classafIoc::ConcurrentCache

sys::Obj
  afIoc::ConcurrentCache

A map that shares its state across threads providing fast reads and synchronised writes. It's an application of ConcurrentState for use when reads far out number the writes.

The cache wraps a map stored in an AtomicRef through which all reads are made. All writes are made via ConcurrentState ensuring synchronised access. Writing makes a rw copy of the map and is thus a more expensive operation.

@since 1.4.2

containsKey

Source

Bool containsKey(Obj key)

Returns true if the cache contains the given key

get

Source

@Operator
Obj? get(Obj key)

Returns the value associated with the given key.

getOrAdd

Source

Obj getOrAdd(Obj key, |->Obj valFunc)

Returns the value associated with the given key. If it doesn't exist then it is added from the value function.

This method is NOT thread safe. If two actors call this method at the same time, the value function could be called twice for the same key. @since 1.4.6

keys

Source

Obj[] keys()

Returns a list of all the mapped keys.

make

Source

new make(|This? f := null)

makeWithMap

Source

new makeWithMap(Obj:Obj? map)

Make a ConcurrentCache using the given immutable map @since 1.4.6

map

Source

Obj:Obj? map { private set }

A read-only copy of the cache map.

set

Source

@Operator
Void set(Obj key, Obj val)

Sets the key / value pair, ensuring no data is lost during multi-threaded race conditions. Though the same key may be overridden. Both the key and val must be immutable.

vals

Source

Obj[] vals()

Returns a list of all the mapped values.