Script Development / File System Storage DFF.STORE_FS
Added in version 8.1.18
DFF.STORE_FS is used to persist small-scale JSON data in the file system, reading and writing by scope + key. It is consistent with the calling method of DFF.STORE, but the data is independent of each other; identical Scope and Key do not share values.
1. Reading and Writing Data
Key and Scope are strings with a maximum length of 256 characters. When scope is omitted, the current Script ID is used; when accessing across scripts, the same Scope should be explicitly specified.
| Saving and Reading Settings | |
|---|---|
1 2 3 4 5 6 7 8 | |
| Method | Return value / Description |
|---|---|
set(key, value, expires=None, not_exists=False, scope=None) |
Write a single value, returns None |
mset(key_values, expires=None, not_exists=False, scope=None) |
Batch write, returns None |
get(key, scope=None) / DFF.STORE_FS(key, scope=None) |
Return the value; return None if it does not exist or has expired |
mget(keys, scope=None, sort_keys=None) |
Returns {key: value}, with missing or expired values as None |
getall(scope=None, sort_keys=None) |
Returns all valid data under the Scope |
keys(pattern='*', scope=None, sort_keys=None) |
Returns a list of matching and valid Keys |
get_pattern(pattern='*', scope=None, sort_keys=None) |
Returns matching and valid data {key: value} |
delete(key, scope=None) |
Delete the specified Key |
delete_pattern(pattern='*', scope=None) |
Delete matching Keys |
ref(key, scope=None, default=None) |
Create DFF.API dynamic reference |
expires is the expiration time in seconds; omitting it or passing a falsy value means no expiration, and subsequent writes without an expiration time will clear the original expiration time. not_exists=True allows writing records that are missing or expired, while keeping existing records that are still valid. The write methods return None; if confirmation is needed, read back the data. Batch writes are executed item by item and are not all-or-nothing transactions.
Since 8.1.21, keys(...), mget(...), getall(...), and get_pattern(...) support sort_keys: 'asc' for ascending order and 'desc' for descending order; parameter values are case-insensitive. The default None preserves the original order, and mget(...) retains the input Key order. Key names are sorted in case-sensitive string lexicographic order, and the returned dictionary preserves that order; other parameter values raise ValueError. This sorting rule differs from the database character collation used by DFF.STORE.
Patterns match complete key names; * matches any length, ? matches a single character, and other characters are matched literally. Pattern operations scan the selected Scope and are suitable for small-scale data.
Pattern deletion matches the entire Scope by default
delete_pattern() uses '*' by default. When deleting partial data, explicitly pass a pattern and first use keys(...) to verify the matched results.
2. Dynamic References
DFF.STORE_FS.ref(...) can be used for the delayed_cron_job, timeout, expires, and queue parameters of DFF.API. When scope is omitted, REF is used, which differs from the default Scope for normal reads and writes; the Scope consistent with the writing side should be explicitly passed.
When a record is missing, expired, or the value is JSON null, default is used; 0, False, and empty strings are preserved and passed to the target parameter for validation. See Script Development / Exported Function DFF.API / Dynamic References for details.
3. Storage and Deployment
Data is stored in the store-fs subdirectory of the resource directory. When RESOURCE_ROOT_PATH is configured in the configuration file config.yaml, that resource directory is used. All Server and Worker instances that use these values must access the same resource directory, including the Server that resolves dynamic references.
The underlying file system must support file locking and atomic replacement; backups should cover the resource directory. The resource directory permissions determine data access permissions. Do not include the storage directory in the public File Service root directory, and do not directly edit managed files.
Reads filter out expired records, and background cleanup handles physical reclamation. For large files, large lists, and complex queries, use other storage or database Connectors; for temporary caching, use Script Development / Simple Cache DFF.CACHE.