Package gavo :: Package base :: Module caches
[frames] | no frames]

Module caches

source code

Accessor functions for the various immutables we have.

The main purpose of this module is to keep caches of resource descriptors, and other items the parsing of which may take some time.

All you need to do is provide a function taking a "key" (a string, most likely) and returning the object. Then call

base.caches.makeCache(<accessorName>, <function>)

After that, clients can call

base.caches.<accessorName>(key)

You can additionally provide an isDirty(res) function when calling makeCache. This can return True if the resource is out of date and should be reloaded.

An alternative interface to registering caches is the registerCache function (see there).

Classes
  CacheRegistry
is a registry for caches kept to be able to clear them.
Functions
 
clearCaches() source code
 
clearForName(key) source code
 
registerCache(name, cacheDict, creationFunction)
registers a custom cache.
source code
 
makeCache(name, callable, isDirty=None)
creates a new function name to cache results to calls to callable.
source code
 
getMTH(id) source code
 
getPageCache(id) source code
Variables
  __package__ = None
hash(x)
Function Details

registerCache(name, cacheDict, creationFunction)

source code 

registers a custom cache.

This function makes creationFunction available as base.caches.name, and it registers cacheDict with the cache manager such that cacheDict is cleared as necessary.

creationFunction must manage cacheDict itself, and of course it must always use the instance passed to registerCache.

This is for "magic" things like getRD that has to deal with aliases and such. For normal use, use makeCache.

makeCache(name, callable, isDirty=None)

source code 

creates a new function name to cache results to calls to callable.

isDirty can be a function returning true when the cache should be cleared. The function is passed the current resource.