This is used in FHFS... just thought I'd post it here since it can be extremely useful.
These functions just create simple files that store database-like values and can be retrieved at any time, on any page, with easy to use functions. It functions somewhat like user-notes, except these values are global, not just for one user, and are stored in a separate file.
Put these under [request] in hfs.events:
{.set|loaddb|{:{.for each|value|{.replace|;|{.no pipe||.}|{.load|$1.db.}.}|{:{.if|{.^value.}|{:{.set table|$1|{.^value.}.}:}.}:}.}:}.}
{.set|writedb|{:{.^loaddb|$1.}{.save|$1.db|{.replace|$2={.from table|$1|$2.};||{.load|$1.db.}.}.}{.append|$1.db|$2=$3; .}{.^loaddb|$1.}:}.}
{.set|delkey|{:{.^loaddb|$1.}{.save|$1.db|{.replace|$2={.from table|$1|$2.};||{.load|$1.db.}.}.}{.^loaddb|$1.}:}.}
You use {.^loaddb|A.} to initialize a database for use, once per page, {.^writedb|A|B|C.} to write a new key or overwrite and old one, {.^delkey|A|B.} to delete a key and its value, and {.from table|A|B.} to expand to a value.
So if you want to write a value, you'd put in
{.^writedb|databasename|keyname|value.}
At the beginning of each page, before you can use {.from table.} to get a value, you must first load the database into memory, either using {.^loaddb|databasename.} or else {.^writedb.} which automatically loads the database, writes to it, and then reloads the new values.
So to call a value from a DB file, you might use something like:
{.^loaddb|databasename.}
{.from table|databasename|keyname|value.}
And then to delete a key, you would use
{.^delkey|databasename|keyname.}
For me, reading a db with 1000 keys took around 0.37 seconds consistently. So it works pretty quickly.
-- Raybob