Storage¶
Persistent data storage objects. These objects will act like normal built-in data types, except all data will be saved to disk for later access when flushed.
-
class
codequick.storage.
PersistentDict
(name, ttl=None)[source]¶ Persistent storage with a
dictionary
like interface.Parameters: Note
name
can be a filename, or the full path to a file. The add-on profile directory will be the default location for files, unless a full path is given.Note
If the
ttl
parameter is given, “any” expired data will be removed on initialization.Note
This class is also designed as a “Context Manager”.
Note
Data will only be synced to disk when connection to file is “closed” or when “flush” method is explicitly called.
Example: >>> with PersistentDict("dictfile.pickle") as db: >>> db["testdata"] = "testvalue" >>> db.flush()
-
flush
()¶ Synchronize data back to disk.
Data will only be written to disk if content has changed.
-
close
()¶ Flush content to disk & close file object.
-
-
class
codequick.storage.
PersistentList
(name, ttl=None)[source]¶ Persistent storage with a
list
like interface.Parameters: Note
name
can be a filename, or the full path to a file. The add-on profile directory will be the default location for files, unless a full path is given.Note
If the
ttl
parameter is given, “any” expired data will be removed on initialization.Note
This class is also designed as a “Context Manager”.
Note
Data will only be synced to disk when connection to file is “closed” or when “flush” method is explicitly called.
Example: >>> with PersistentList("listfile.pickle") as db: >>> db.append("testvalue") >>> db.extend(["test1", "test2"]) >>> db.flush()
-
flush
()¶ Synchronize data back to disk.
Data will only be written to disk if content has changed.
-
close
()¶ Flush content to disk & close file object.
-