const classafIoc::ConcurrentCache

sys::Obj
  afIoc::ConcurrentCache

A helper class that wraps a Map providing fast reads and synchronised writes betweeen threads. 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.

Note that all objects held in the map have to be immutable.

@since 1.4.2

clear

Source

This clear()

Remove all key/value pairs from the map. Return this.

containsKey

Source

Bool containsKey(Obj key)

Returns true if the cache contains the given key

get

Source

@Operator
Obj? get(Obj key, Obj? def := null)

Returns the value associated with the given key. If key is not mapped, then return the value of the def parameter. If def is omitted it defaults to null.

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

isEmpty

Source

Bool isEmpty()

Return true if size() == 0

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. Use when you need a case insensitive map. @since 1.4.6

map

Source

Obj:Obj? map { private set }

A read-only copy of the cache map.

remove

Source

Obj? remove(Obj key)

Remove the key/value pair identified by the specified key from the map and return the value. If the key was not mapped then return null.

replace

Source

Obj:Obj? replace(Obj:Obj? newMap)

Replaces the entire content of the cache with the given map. The existing map is returned.

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.

size

Source

Int size()

Get the number of key/value pairs in the map.

vals

Source

Obj[] vals()

Returns a list of all the mapped values.