history: Application history support¶
This module provides support for caching information across application invocations. In particular, it is useful for command and file history.
History files are kept in an application user’s cache directory, so there is the assumption that they can be removed and the application will still work.
-
class
FIFOHistory
(capacity, session, tag, unversioned=True, auto_save=True)¶ Bases:
object
A fixed capacity FIFO queue with backing store.
Parameters: capacity : int, a limit on the number of items in the history
session :
Session
instancetag : str, a unique tag to identify the history
unversioned : bool, optional, defaults to True
auto_save : bool, optional, defaults to True
If unversioned is true, then the history is for all versions of application. If auto_save is true, then the history is flushed to disk everyime it is updated.
Notes
Iterating returns oldest first.
-
clear
()¶ Remove all items
-
dequeue
(_skip_save=False)¶ Remove and return oldest item
-
enqueue
(value)¶ Add newest item
-
extend
(iterable)¶ Add newest items
-
replace
(iterable)¶ Replace current items
-
save
()¶ Save to history file.
-
-
class
LRUSetHistory
(capacity, session, tag, unversioned=True, auto_save=True)¶ Bases:
chimera.core.orderedset.OrderedSet
A fixed capacity LRU set with backing store.
Saves and restores a set of data from a history file. Use the
add()
method to put items into the set and to update it. The last member of the set is the most recent. ALl of the normalset
methods are supported as well.Parameters: capacity : int, a limit on the number of items in the history
session :
Session
instancetag : str, a unique tag to identify the history
unversioned : bool, optional, defaults to True
auto_save : bool, optional, defaults to True
If unversioned is true, then the history is for all versions of application. If auto_save is true, then the history is flushed to disk everyime it is updated.
-
add
(item)¶ Add item to set and make it the most recent.
Parameters: item : simple type suitable for Python’s JSON
module.
-
save
()¶ Save set to history file.
-
-
class
ObjectCache
(session, tag, unversioned=True)¶ Bases:
object
Maintain an object in application’s cache on disk.
Parameters: session :
Session
instancetag : str, a unique tag to identify the cache
unversioned : bool, optional, defaults to False
Notes
Uses JSON to serialize and deserialize history object.
-
load
()¶ Return deserialized object from history file.
-
save
(obj)¶ Serialize object into history file.
Parameters: obj : object
The object to save.
-