const classafIoc::ThreadStash
sys::Obj afIoc::ThreadStash
A wrapper around Actor.locals ensuring a unique namespace per instance. this means you don't have to worry about name clashes.
Example usage:
stash1 := ThreadStash("prefix")
stash1["wot"] = "ever"
stash2 := ThreadStash("prefix")
stash2["wot"] = "banana"
Obj.echo(stash1["wot"]) // --> ever
Though typically you would create calculated field wrappers:
const class Example
private const ThreadStash stash := LocalStash(typeof.name)
MyService wotever {
get { stash["wotever"] }
set { stash["wotever"] = it }
}
}
@since 1.3.0 (a replacement for LocalStash)
- clear
Void clear()Removes all key/value pairs from this stash
- contains
Returns
trueif this stash contains the given name@since 1.3.2
- get
@Operator
Obj? get(Str name, |->Obj? defFunc := null)Get the value for the specified name.
- keys
Str[] keys()Returns all (fully qualified) keys associated / used with this stash. Note the returns
- make
new make(Str prefix)A thread-local count is added to the given prefix to make it truly unique.
- prefix
const Str prefixThe prefix used to identify all keys used with this stash
- remove
Remove the name/value pair from the stash and returns the value that was. If the name was not mapped then return null.
- set
@Operator
Void set(Str name, Obj? value)Set the value for the specified name. If the name was already mapped, this overwrites the old value.