Script Development / Simple Storage DFF.STORE
DFF.STORE is used to persist small-scale KV data, structured as scope + key -> value. Writes are automatically JSON-serialized; reads are automatically deserialized and preserve JSON types.
When you need to save data to the file system, you can use Script Development / File System Storage DFF.STORE_FS. The data in the two storage types are independent of each other.
Complex queries or large amounts of data should use a database Connector. Short-lived, high-frequency data that can accept stringification should use DFF.CACHE.
Common Parameters
| Parameter | Required / Default | Description |
|---|---|---|
key |
Required | Key name, up to 256 characters |
value |
Required | JSON-serializable object |
expires |
None |
Expiration seconds; None means never expires |
scope |
Current Script ID | Namespace, up to 256 characters |
pattern |
"*" |
Key name pattern; * matches any length, ? matches a single character |
sort_keys |
None |
Added in version 8.1.21; 'asc' for ascending, 'desc' for descending, case-insensitive; None preserves the original order |
API
| Method | Return value / Description |
|---|---|
set(key, value, expires=None, not_exists=False, scope=None) |
Writes a single value; returns None |
mset(key_values, expires=None, not_exists=False, scope=None) |
Writes multiple values; returns None |
get(key, scope=None) / DFF.STORE(key, scope=None) |
Returns the value; returns None if it does not exist or has expired |
mget(keys, scope=None, sort_keys=None) |
Returns {key: value} |
getall(scope=None, sort_keys=None) |
Returns all data under the Scope |
keys(pattern='*', scope=None, sort_keys=None) |
Returns a list of matching Keys |
get_pattern(pattern='*', scope=None, sort_keys=None) |
Returns matching data {key: value} |
delete(key, scope=None) |
Deletes the specified Key |
delete_pattern(pattern='*', scope=None) |
Deletes matching Keys |
ref(key, scope=None, default=None) |
Creates a dynamic reference for DFF.API parameters that support dynamic values |
| Example | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
mget(...) includes each requested Key; missing or expired values are None; get_pattern(...) only includes records that match and are still valid.
sort_keys applies to keys(...), mget(...), getall(...), and get_pattern(...); it orders key names according to the database character collation, and the iteration order of the returned dictionary matches it. By default no sorting is specified, and mget(...) preserves the order of the input Keys; passing a value other than those listed in the table raises ValueError.
Since 8.1.18, when using not_exists=True, writes are allowed for Keys that do not exist or have expired, even if expired records have not been physically cleaned up; existing valid records remain unchanged. Both set(...) and mset(...) return None; to confirm creation results, read after writing. Batch writes are performed item by item and are not an all-or-nothing transaction.
A missing or falsy expires means no expiration; subsequent writes without an expiration time clear the previous expiration time. Old code may use the expire parameter; new code should use expires consistently.
Since 8.1.18, the pattern matching of keys(...), get_pattern(...), and delete_pattern(...) matches full key names: abc only matches abc, *abc* matches keys containing abc, and abc? matches exactly one character after abc. Except for * and ?, all other characters match literally. Calls that rely on the old version's substring matching should explicitly add *; confirm the results with keys(...) before deletion.
Dynamic References
DFF.STORE.ref(...) returns a dynamic reference that can be used for the delayed_cron_job, timeout, expires, and queue parameters of DFF.API. When scope is omitted, the reference uses a dedicated REF Scope instead of the current Script Scope; you should usually explicitly pass a Scope consistent with the writer.
When a record is missing, expired, or its value is JSON null, the reference uses default; 0, False, and empty strings are preserved and passed to the target parameter for validation, and are not replaced with the default value.
Pattern deletion matches the entire Scope by default
The default pattern of delete_pattern() is "*". Unless you specifically need to delete the entire Scope, you must explicitly pass pattern and first use keys(...) to inspect the matching Keys.
Do not use DFF.STORE for long-term storage of large files or large lists.