Caching framework for PyXWF. This is probably not as mature as we may need it in the future, but it provides basic means for caching resources used by the PyXWF instance.
It may, in the future, also be used to cache complete rendered pages.
Represents an object which can reside in a cache. This class defines the interface neccessary for a cache entry to work properly. The following attributes are used (and reserved by) the caching framework on Cachables:
Set the timestamp of last use in the past so that uncaching of this object in case of reached limits is more likely than for other objects.
Master object representing a full application cache. Objects are not directly stored in the Cache instance but in sub-caches. The Cache object provides dictionary-like access to sub caches. If no cache is associated with a certain key, a new raw SubCache is created for that key.
Specialized sub caches can be created using specialized_cache().
How many cache entries are kept at max. This does not differentiate between different sub-caches and is a global hard-limit. If this limit is exceeded, old (i.e. not used for some time) entries are purged.
Setting this limit to 0 will disable limiting.
This is an abstract baseclass for caches which are backed by files on the file system. The file names are used as keys relative to a given root directory rootpath.
A deriving class has to implement the _load method which is called if a file accessed through this cache is not available in the cache.
In contrast to the implementation given in SubCache, this implementation uses the timestamp of last modification of the file referenced by key. This implies that a resource is not neccessarily loaded (or even loadable!) even if a LastModified can be retrieved successfully.
The big master cache (Cache instance) is subdivided into smaller parts, SubCache instances, which can be thought of namespaces inside the cache.
They’re used to separate different kinds of cachable objects, which can be handled by different SubCache-derived classes. See FileSourcedCache as an example for optimizations possible using this.
SubCaches provide dictionary-like access to cachables, associating keys to the cachables. An object can be added to the cache by simply assigning a key to it. Objects can also be uncached by using the del operator. The in operator and the len function work properly.
Try to get an object from the cache and return default (defaults to None) if no object is associated with key.
Return the datetime representing the last modification of the cached content. The default implementation requests the cached element from the cache and queries the LastModified property.
Derived classes may (and should!) provide mechanisms which can query the LastModified timestamp without completely loading an object.