Class s.p.PersistentDict(PersistentDictBase):

Part of sasync.pdict View In Hierarchy

I am a database-persistent dictionary-like object with memory caching of items and lazy writing.

Getting, setting, or deleting my items returns Deferred objects of the Twisted asynchronous framework that fire when the underlying database accesses are completed. Returning a deferred value avoids forcing the client code to block while the real value is being read from the database.
Instance VariablesdataThe in-memory dictionary that each instance of me uses to cache values for a given ID.
Method __getitem__ Returns a Deferred to the value of item name or the value itself
Method __setitem__ Sets item name to value, saving it to the database if there
Method __delitem__ Deletes item name, removing its entry from both the in-memory
Method __contains__ Indicates if I contain item key.
Method keys Returns an immediate or deferred list of the names of all my items in
Method has_key Returns an immediate or deferred Boolean indicating whether the key is
Method clear Clears the in-memory dictionary of all items and deletes all their
Method iteritems Only for preload mode: Iterate over all my items.
Method iterkeys Only for preload mode: Iterate over all my keys.
Method itervalues Only for preload mode: Iterate over all my values.
Method items Returns an immediate or deferred sequence of (name, value) tuples
Method values Returns an immediate or deferred sequence of all my values.
Method get Returns an immediate or deferred value of the value for the key
Method setdefault Sets my item specified by key to value if it doesn't exist
Method copy Returns an immediate or deferred copy of me that is a conventional

Inherited from PersistentDictBase:

Method __init__ Instantiates me with an item store keyed to the supplied hashable
Method preload This method preloads all my items from the database (which may take a
Method shutdown Shuts down my database Transactor and its synchronous task queue.
Method loadAll Loads all items from the database, setting my in-memory dict and key
Method deferToWrites @see: L{DeferredTracker.deferToAll}
def __getitem__(self, name):

Returns a Deferred to the value of item name or the value itself if in preload mode.

The value is only loaded from the database if it isn't already in the in-memory dictionary.
def __setitem__(self, name, value):
Sets item name to value, saving it to the database if there isn't already an in-memory dictionary item with that exact value.
def __delitem__(self, name):
Deletes item name, removing its entry from both the in-memory dictionary and the database
def __contains__(self, key):

Indicates if I contain item key.

In preload mode, returns True if the item is present in my in-memory dictionary and False if not.

In normal mode, returns an immediate Deferred firing with True without a transaction if the item is already present in my in-memory dictionary. If it isn't, tries to load the item (it will probably be requested soon anyhow) and returns a Deferred that will ultimately fire with True unless the load resulted in a Missing object. In that case, deletes the loaded Missing object from my in-memory dictionary and fires the deferred with False.

Using the <key> in <dict> Python construct doesn't seem to work in normal mode. Use has_key instead.
def keys(self):
Returns an immediate or deferred list of the names of all my items in the database.
def has_key(self, key):
Returns an immediate or deferred Boolean indicating whether the key is present.
def clear(self):
Clears the in-memory dictionary of all items and deletes all their database entries.
def iteritems(self):
Only for preload mode: Iterate over all my items.
def iterkeys(self):
Only for preload mode: Iterate over all my keys.
def itervalues(self):
Only for preload mode: Iterate over all my values.
def items(self):
Returns an immediate or deferred sequence of (name, value) tuples representing all my items.
def values(self):
Returns an immediate or deferred sequence of all my values.
def get(self, *args):
Returns an immediate or deferred value of the value for the key specified as the first argument, or a default value if specified as an optional second argument. If the item is not present and no default value is supplied, raises the appropriate exception.
def setdefault(self, key, value):
Sets my item specified by key to value if it doesn't exist already. Returns an immediate or deferred reference to the item's value after its new value (if any) is set.
def copy(self):
Returns an immediate or deferred copy of me that is a conventional (non-persisted) dictionary.
API Documentation for sAsync, generated by pydoctor.