Home ⌂Doc Index ◂Up ▴

eric6.E5Utilities.E5Cache

Module implementing classes used for caching objects.

Global Attributes

None

Classes

E5Cache Class implementing a LRU cache of a specific size.

Functions

None


E5Cache

Class implementing a LRU cache of a specific size.

If the maximum number of entries is exceeded, the least recently used item is removed from the cache. A cache hit moves the entry to the front of the cache.

Derived from

object

Class Attributes

None

Class Methods

None

Methods

E5Cache Constructor
__adjustToSize Private method to adjust the cache to its size.
__moveLast Private method to move a cached item to the MRU position.
__pruneCache Private slot to prune outdated cache entries and restart the timer.
add Public method to add an item to the cache.
clear Public method to clear the cache.
get Public method to get an entry from the cache given its key.
getMaximumCacheTime Public method to get the maximum time entries may exist in the cache.
getSize Public method to get the maximum size of the cache.
info Public method to get some information about the cache.
length Public method to get the current length of the cache.
remove Public method to remove an item from the cache.
reset Public method to reset the cache.
setMaximumCacheTime Public method to set the maximum time entries may exist in the cache.
setSize Public method to change the maximum size of the cache.

Static Methods

None

E5Cache (Constructor)

E5Cache(size=100)

Constructor

size (int)
maximum number of entries that may be stored in the cache
Raises ValueError:
raised to indicate an illegal 'size' parameter

E5Cache.__adjustToSize

__adjustToSize()

Private method to adjust the cache to its size.

E5Cache.__moveLast

__moveLast(key)

Private method to move a cached item to the MRU position.

key (any hashable type that can be used as a dict key)
key of the item to be retrieved

E5Cache.__pruneCache

__pruneCache()

Private slot to prune outdated cache entries and restart the timer.

E5Cache.add

add(key, item)

Public method to add an item to the cache.

If the key is already in use, the cached item is replaced by the new one given and is moved to the MRU position

key (any hashable type that can be used as a dict key)
key of the item to be retrieved
item (object)
item to be cached under the given key

E5Cache.clear

clear()

Public method to clear the cache.

E5Cache.get

get(key)

Public method to get an entry from the cache given its key.

If the key is present in the cache, it is moved to the MRU position.

key (any hashable type that can be used as a dict key)
key of the item to be retrieved
Returns:
cached item for the given key or None, if the key is not present
Return Type:
object or None

E5Cache.getMaximumCacheTime

getMaximumCacheTime()

Public method to get the maximum time entries may exist in the cache.

Returns:
maximum cache time in seconds
Return Type:
int

E5Cache.getSize

getSize()

Public method to get the maximum size of the cache.

Returns:
maximum number of entries of the cache
Return Type:
int

E5Cache.info

info()

Public method to get some information about the cache.

Returns:
dictionary containing the cache info
Return Type:
dict (with keys "hits", "misses", "maxsize", "currsize")

E5Cache.length

length()

Public method to get the current length of the cache.

Returns:
current length of the cache
Return Type:
int

E5Cache.remove

remove(key)

Public method to remove an item from the cache.

key (any hashable type that can be used as a dict key)
key of the item to be retrieved

E5Cache.reset

reset()

Public method to reset the cache.

This is like clear() but sets the various counters to their initial value as well.

E5Cache.setMaximumCacheTime

setMaximumCacheTime(time)

Public method to set the maximum time entries may exist in the cache.

time (int)
maximum cache time in seconds

E5Cache.setSize

setSize(newSize)

Public method to change the maximum size of the cache.

newSize (int)
maximum number of entries that may be stored in the cache
Up



Home ⌂Doc Index ◂Up ▴