Package ganeti :: Module cache :: Class SimpleCache
[hide private]
[frames] | no frames]

Class SimpleCache

source code


Implements a very simple, dict base cache.

Instance Methods [hide private]
 
__init__(self, _time_fn=time.time)
Initialize this class.
source code
 
_UnlockedCleanup(self)
Does cleanup of the cache.
source code
 
Cleanup(self)
Cleanup our cache.
source code
 
Store(self, key, value, ttl=0)
Stores a value at key in the cache.
source code
 
GetMulti(self, keys)
Retrieve the values of keys from cache.
source code
 
Get(self, key)
Retrieve the value of key from cache.
source code
 
Invalidate(self, keys)
Invalidates value for keys in cache.
source code
 
Flush(self)
Invalidates all keys and values in cache.
source code
 
_UnlockedInvalidate(self, keys)
Invalidate keys in cache.
source code
 
_ExtractValue(self, key)
Extracts just the value for a key.
source code

Inherited from CacheBase: ResetState

Class Variables [hide private]
  CLEANUP_ROUND = 1800
  _LOCK = "lock"
Method Details [hide private]

__init__(self, _time_fn=time.time)
(Constructor)

source code 

Initialize this class.

Parameters:
  • _time_fn - Function used to return time (unittest only)
Overrides: CacheBase.__init__

Cleanup(self)

source code 

Cleanup our cache.

Decorators:
  • @locking.ssynchronized(_LOCK)
Overrides: CacheBase.Cleanup

Store(self, key, value, ttl=0)

source code 

Stores a value at key in the cache.

See CacheBase.Store for parameter description

Parameters:
  • key - The key to associate this cached value
  • value - The value to cache
  • ttl - TTL in seconds after when this entry is considered outdated
Returns:
True on success, False on failure
Decorators:
  • @locking.ssynchronized(_LOCK)
Overrides: CacheBase.Store

GetMulti(self, keys)

source code 

Retrieve the values of keys from cache.

See CacheBase.GetMulti for parameter description

Parameters:
  • keys - The keys to retrieve
Returns:
The list of values
Decorators:
  • @locking.ssynchronized(_LOCK, shared= 1)
Overrides: CacheBase.GetMulti

Get(self, key)

source code 

Retrieve the value of key from cache.

See CacheBase.Get for parameter description

Parameters:
  • key - The key to retrieve
Returns:
The value or None if not found
Decorators:
  • @locking.ssynchronized(_LOCK, shared= 1)
Overrides: CacheBase.Get

Invalidate(self, keys)

source code 

Invalidates value for keys in cache.

See CacheBase.Invalidate for parameter description

Parameters:
  • keys - The list of keys to invalidate
Returns:
True on success, False otherwise
Decorators:
  • @locking.ssynchronized(_LOCK)
Overrides: CacheBase.Invalidate

Flush(self)

source code 

Invalidates all keys and values in cache.

See CacheBase.Flush for parameter description

Decorators:
  • @locking.ssynchronized(_LOCK)
Overrides: CacheBase.Flush

_UnlockedInvalidate(self, keys)

source code 

Invalidate keys in cache.

This is the unlocked version, see Invalidate for parameter description

_ExtractValue(self, key)

source code 

Extracts just the value for a key.

This method is taking care if the value did not expire ans returns it

Parameters:
  • key - The key to look for
Returns:
The value if key is not expired, None otherwise