Table of Contents

Class: ICache ./src/peak/persistence/interfaces.py

In-memory object cache

The cache serves two purposes. It peforms pointer swizzling, and it keeps a bounded set of recently used but otherwise unreferenced in objects to avoid the cost of re-loading them.

Pointer swizzling is the process of converting between persistent object ids and Python object ids. When a persistent object is serialized, its references to other persistent objects are represented as persitent object ids (oids). When the object is unserialized, the oids are converted into references to Python objects. If several different serialized objects refer to the same object, they must all refer to the same object when they are unserialized.

A cache stores persistent objects, but it treats ghost objects and non-ghost or active objects differently. It has weak references to ghost objects, because ghost objects are only stored in the cache to satisfy the pointer swizzling requirement. It has strong references to active objects, because it caches some number of them even if they are unreferenced.

The cache keeps some number of recently used but otherwise unreferenced objects in memory. We assume that there is a good chance the object will be used again soon, so keeping it memory avoids the cost of recreating the object.

An ICache implementation is intended for use by an IPersistentDataManager.

Base Classes   
Interface
Methods   
activate
clear
get
invalidate
remove
set
shrink
statistics
  activate 
activate ( oid )

Notification that object oid is now active.

The caller is notifying the cache of a state change.

Raises LookupError if oid is not in cache.

  clear 
clear ()

Invalidate all the active objects.

  get 
get ( oid )

Return the object from the cache or None.

  invalidate 
invalidate ( oids )

Make all of the objects in oids ghosts.

`oids` is an iterable object that yields oids.

The cache must attempt to change each object to a ghost by calling _p_deactivate().

If an oid is not in the cache, ignore it.

  remove 
remove ( oid )

Remove oid from the cache if it exists.

  set 
set ( oid,  obj )

Store obj in the cache under oid.

obj must implement IPersistent

  shrink 
shrink ()

Remove excess active objects from the cache.

  statistics 
statistics ()

Return dictionary of statistics about cache size.

Contains at least the following keys: active -- number of active objects ghosts -- number of ghost objects


Table of Contents

This document was automatically generated on Mon Nov 11 01:11:05 2024 by HappyDoc version 2.1