const classafConcurrent::SynchronizedFileMap
sys::Obj afConcurrent::SynchronizedFileMap
A SynchronisedMap, keyed on File, that updates its contents if the file is updated. Use as a cache based on the content of the file, see getOrAddOrUpdate().
Note that all objects held in the map have to be immutable.
- clear
This clear()Remove all key/value pairs from the map. Return this.
- containsKey
Returns
trueif the map contains the given file- def
const Obj? def := nullThe default value to use for get when a key isn't mapped.
- get
@Operator
Obj? get(Obj key, Obj? def := this.def)Returns the value associated with the given key. If key is not mapped, then return the value of the
defparameter. Ifdefis omitted it defaults tonull.- getOrAdd
Obj? getOrAdd(File key, |File->Obj? valFunc)Returns the value associated with the given key. If it doesn't exist then it is added from the value function.
- getOrAddOrUpdate
Obj? getOrAddOrUpdate(File key, |File->Obj? valFunc)Returns the value associated with the given file. If it doesn't exist, or the file has been updated since the last get, then it is added from the given value function.
Set
timeoutin the ctor to avoid hitting the file system on every call to this method.- isEmpty
Bool isEmpty()Return
trueif size() == 0- isModified
Returns
trueif a subsequent call togetOrAddOrUpdate()would result in thevalFuncbeing executed. This method does not modify any state and returnstrueif the file has not been added to the map.- keys
Obj[] keys()Returns a list of all the mapped keys.
- make
new make(ActorPool actorPool, Duration? timeout := 30sec, |This? f := null)Creates a
SynchronizedMapwith the givenActorPool.timeoutis how long to wait between individual file checks. Use to avoid excessive reads of the file system. Set tonullto check the file every time.- map
Gets or sets a read-only copy of the backing map.
- remove
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.- rw
Get a read-write, mutable Map instance with the same contents.
- set
@Operator
Void set(File key, Obj? val)Sets the key / value pair, ensuring no data is lost during multi-threaded race conditions.
- size
Int size()Get the number of key/value pairs in the map.
- valType
const Type valType := sys::Obj?#Used to parameterize the backing map.
- vals
Obj?[] vals()Returns a list of all the mapped values.