gavo.base.caches module

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


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).

class gavo.base.caches.CacheRegistry[source]

Bases: object

is a registry for caches kept to be able to clear them.

A cache is assumed to be a dictionary here.

gavo.base.caches.makeCache(name, callable, isDirty=None)[source]

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.

gavo.base.caches.registerCache(name, cacheDict, creationFunction)[source]

registers a custom cache.

This function makes creationFunction available as, 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.