BaseCache#

class sunpy.database.caching.BaseCache(maxsize=inf)[source]#

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 self.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 self.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]#

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]#
copy()[source]#
classmethod fromkeys(iterable, value=None)[source]#
get(key, default=None)[source]#

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]#
iteritems()[source]#
iterkeys()[source]#
itervalues()[source]#
keys()[source]#
pop(key, default=<object object>)[source]#
popitem(last=True)[source]#
abstract remove()[source]#

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]#
update(*args, **kwds)[source]#
values()[source]#
viewitems()[source]#
viewkeys()[source]#
viewvalues()[source]#