# eric7.EricUtilities.EricCache

Module implementing classes used for caching objects.

### Global Attributes

None

### Classes

EricCache | Class implementing a LRU cache of a specific size.

### Functions

None

## EricCache

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

None

### Class Attributes

None

### Class Methods

None

### Methods

EricCache | 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

#### EricCache (Constructor)

EricCache(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

#### EricCache.__adjustToSize

__adjustToSize()

Private method to adjust the cache to its size.

#### EricCache.__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

#### EricCache.__pruneCache

__pruneCache()

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

#### EricCache.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

#### EricCache.clear

clear()

Public method to clear the cache.

#### EricCache.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

Return:
  cached item for the given key or None, if the key is not present

Return Type:
  object or None

#### EricCache.getMaximumCacheTime

getMaximumCacheTime()

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

Return:
  maximum cache time in seconds

Return Type:
  int

#### EricCache.getSize

getSize()

Public method to get the maximum size of the cache.

Return:
  maximum number of entries of the cache

Return Type:
  int

#### EricCache.info

info()

Public method to get some information about the cache.

Return:
  dictionary containing the cache info

Return Type:
  dict (with keys "hits", "misses", "maxsize", "currsize")

#### EricCache.length

length()

Public method to get the current length of the cache.

Return:
  current length of the cache

Return Type:
  int

#### EricCache.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

#### EricCache.reset

reset()

Public method to reset the cache.

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

#### EricCache.setMaximumCacheTime

setMaximumCacheTime(time)

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

time (int)
  maximum cache time in seconds

#### EricCache.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