PersistentValue
PersistentValue["name"]
represents the persistent value associated with the key "name".
PersistentValue["name",loc]
represents the persistent value associated with name stored in persistence location loc.
PersistentValue["name",{loc1,…}]
represents the persistent value associated with name at the first of the locations loci at which it occurs.
Details and Options
- PersistentValue["name",…] evaluates to give the corresponding persistent value.
- PersistentValue["name",…]=value or PersistentValue["name",…]:=value can be used to set persistent values.
- PersistentValue allows the following options:
-
MergingFunction Automatic the function applied to the list of values found ValuePreprocessingFunction Identity the function applied to new values to be assigned ExpirationDate None when the value should expire PersistenceTime None how long the value should persist - A persistence location is given as PersistenceLocation["type"] or "type".
- PersistentValue["name"] is equivalent to PersistentValue["name",$PersistencePath].
- PersistentValue["name"]=value is equivalent to PersistentValue["name",$PersistenceBase]=value.
- PersistentValue["name",loc] is essentially PersistentObject["name",loc]["Value"].
- When a single persistence location is specified, as in PersistentValue["name",loc,…], the setting for MergingFunction is not used.
- Otherwise, with the setting MergingFunction->f, the final value returned is the result of applying the function f to the list of values found at all persistence locations.
- Unless specified otherwise by "MergingFunction" metadata in the PersistentObject, MergingFunction->Automatic is equivalent to MergingFunction->First.
- Before a new value is assigned in PersistentValue[sym]=value, any specified value preprocessing function is applied to value before the value is assigned.
- If the preprocessing function returns $Failed, the assignment is not performed.
- If no explicit setting for ValuePreprocessingFunction is given, the setting to use is looked up on $PersistencePath.
- An expired persistent value is treated as nonexistent, and the underlying persistent object may be removed.
- Persistent values can be removed with Remove. Remove[PersistentValue["name"]] is equivalent to Remove[PersistentValue["name",$PersistenceBase]].
Examples
open allclose allBasic Examples (3)
Retrieve a previously saved value:
Remember a value with front end session scope:
| In[1]:= |
Use the saved value, even in a newly restarted kernel within the same front end session:
| In[2]:= |
Store values for the same name at different persistence locations:
| In[1]:= |
Retrieve the first value found:
Retrieve the list of all values on $PersistencePath:
Options (8)
Applications (1)
Properties & Relations (5)
Possible Issues (1)
See Also
PersistentObject PersistenceLocation $PersistencePath $PersistenceBase PersistentObjects InitializationValue