BaseCache

class sunpy.database.caching.BaseCache(maxsize=inf)[source] [edit on github]

Bases: object

BaseCache is a class that saves and operates on an OrderedDict. It has a certain capacity, stored in the attribute maxsize. Whether this capacity is reached, can be checked by using the boolean property is_full. To implement a custom cache, inherit from this class and override the methods __getitem__ and __setitem__. Call the method sunpy.database.caching.BaseCache.callback as soon as an item from the cache is removed.

Attributes Summary

is_full True if the number of items in the cache equals maxsize, False otherwise.
to_be_removed The item that will be removed on the next sunpy.database.caching.BaseCache.remove() call.

Methods Summary

callback(key, value) This method should be called (by convention) if an item is removed from the cache because it is full.
clear()
copy()
fromkeys(iterable[, value])
get(key[, default]) Return the corresponding value to key if key is in the cache, default otherwise.
items()
iteritems()
iterkeys()
itervalues()
keys()
pop(key[, default])
popitem([last])
remove() Call this method to manually remove one item from the cache.
setdefault(key[, default])
update(*args, **kwds)
values()
viewitems()
viewkeys()
viewvalues()

Attributes Documentation

is_full

True if the number of items in the cache equals maxsize, False otherwise.

to_be_removed

The item that will be removed on the next sunpy.database.caching.BaseCache.remove() call.

Methods Documentation

callback(key, value)[source] [edit on github]

This method should be called (by convention) if an item is removed from the cache because it is full. The passed key and value are the ones that are removed. By default this method does nothing, but it can be customized in a custom cache that inherits from this base class.

clear()[source] [edit on github]
copy()[source] [edit on github]
classmethod fromkeys(iterable, value=None)[source] [edit on github]
get(key, default=None)[source] [edit on github]

Return the corresponding value to key if key is in the cache, default otherwise. This method has no side-effects, multiple calls with the same cache and the same passed key must always return the same value.

items()[source] [edit on github]
iteritems()[source] [edit on github]
iterkeys()[source] [edit on github]
itervalues()[source] [edit on github]
keys()[source] [edit on github]
pop(key, default=<object object>)[source] [edit on github]
popitem(last=True)[source] [edit on github]
remove()[source] [edit on github]

Call this method to manually remove one item from the cache. Which item is removed, depends on the implementation of the cache. After the item has been removed, the callback method is called.

setdefault(key, default=None)[source] [edit on github]
update(*args, **kwds)[source] [edit on github]
values()[source] [edit on github]
viewitems()[source] [edit on github]
viewkeys()[source] [edit on github]
viewvalues()[source] [edit on github]