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
Returns
true
if the cache contains the given key- get
Returns the value associated with the given key.
- getOrAdd
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
Obj[] keys()
Returns a list of all the mapped keys.
- make
new make(|This? f := null)
- makeWithMap
Make a
ConcurrentCache
using the given immutable map @since 1.4.6- map
A read-only copy of the cache map.
- set
@
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
andval
must be immutable.- vals
Obj[] vals()
Returns a list of all the mapped values.