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 propertyis_full
. To implement a custom cache, inherit from this class and override the methods__getitem__
and__setitem__
. Call the methodsunpy.database.caching.BaseCache.callback
as soon as an item from the cache is removed.Attributes Summary
True if the number of items in the cache equals
self.maxsize
, False otherwise.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
ifkey
is in the cache,default
otherwise.items
()iterkeys
()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
()viewkeys
()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.
- get(key, default=None)[source]#
Return the corresponding value to
key
ifkey
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.