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

Examples

open allclose all

Basic Examples  (3)

Assign a persistent value:

Retrieve a previously saved value:

Remember a value with front end session scope:

Use the saved value, even in a newly restarted kernel within the same front end session:

Store values for the same name at different persistence locations:

Retrieve the first value found:

Retrieve the list of all values on $PersistencePath:

Options  (8)

MergingFunction  (3)

Create a complement of persistent values with key "lval" at various locations:

List all existing values for the key "lval" on $PersistencePath:

By default, only the first value is returned:

Join and flatten all sublists:

Join all sublists:

Create a complement of persistent associations with name "aval" at various locations:

List all existing values on $PersistencePath:

Merge the values of identical keys in the associations:

Define a default value for "mylist" with a custom merging function:

Define additional values at different persistence locations:

For looking up values, the custom merging function is now used:

PersistenceTime  (2)

Define a persistent value that expires in 5 seconds:

After 5 seconds, it is no longer used:

Define a persistent object that expires in 5 days:

Verify the expiration date of the underlying persistent object:

ExpirationDate  (2)

Define a persistent value that expires at the beginning of the year 2020:

Verify the expiration date of the underlying persistent object:

Define a persistent value that expires at the beginning of next year:

Verify the expiration date of the underlying persistent object:

ValuePreprocessingFunction  (1)

Define a value preprocessing function for a particular persistent value that accepts only integers:

Assign an integer at any persistence location:

Assigning anything else generates an error and the assignment is not performed:

Applications  (1)

List all existing persistent objects for the key "lval":

Delete them:

Properties & Relations  (5)

Persistent values are stored in persistent objects:

The default location of a new persistent object is given by $PersistenceBase:

Create a complement of persistent values with key "v" at various locations:

Persistent values are by default searched on all locations given in $PersistencePath:

The first value found is returned:

With MergingFunction->Identity, all values found are returned in a list:

Specify an explicit list of locations to search for values:

Expiration times specified with PersistenceTime are converted to absolute expiration dates:

Persistent values can be removed with Remove:

Possible Issues  (1)

Create two persistent values for "name" in different locations:

Remove by default removes only the value in the location given by $PersistenceBase:

Remove all values that might exist anywhere in the locations given by $PersistencePath:

Introduced in 2017
 (11.1)
 |
Updated in 2017
 (11.2)
2019
 (12.0)