Package omeroweb :: Package webgateway :: Module webgateway_cache :: Class FileCache
[hide private]
[frames] | no frames]

Class FileCache

source code


Implements file-based caching within the directory specified in constructor.

Instance Methods [hide private]
 
__init__(self, dir, timeout=60, max_entries=0, max_size=0)
Initialises the class.
source code
 
add(self, key, value, timeout=None, invalidateGroup=None)
Adds data to cache, returning False if already cached.
source code
 
get(self, key, default=None)
Gets data from cache
source code
 
set(self, key, value, timeout=None, invalidateGroup=None)
Adds data to cache, overwriting if already cached.
source code
 
delete(self, key)
Attempt to delete the cache data referenced by key
source code
 
_delete(self, fname)
Tries to delete the data at the specified absolute file path
source code
 
wipe(self)
Deletes everything in the cache
source code
 
_check_entry(self, fname)
Verifies if a specific cache entry (provided as absolute file path) is expired.
source code
Boolean
has_key(self, key)
Returns true if the cache has the specified key
source code
int
_du(self)
Disk Usage count on the filesystem the cache is based at
source code
Boolean
_full(self, _on_retry=False)
Checks whether the cache is full, either because we have exceeded max number of entries or the cache space is full.
source code
 
_purge(self)
Iterate the whole cache structure searching and cleaning expired entries.
source code
 
_createdir(self)
Creates a directory for the root dir of the cache.
source code
String
_key_to_file(self, key)
Uses the key to construct an absolute path to the cache data.
source code
int
_get_num_entries(self)
Returns the number of files in the cache
source code
int
_num_entries(self)
Returns the number of files in the cache
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _purge_holdoff = 4
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, dir, timeout=60, max_entries=0, max_size=0)
(Constructor)

source code 

Initialises the class.

Parameters:
  • dir - Path to directory to place cached files.
  • timeout - Cache timeout in secs
  • max_entries - If specified, limits number of items to cache
  • max_size - Maxium size of cache in KB
Overrides: object.__init__

add(self, key, value, timeout=None, invalidateGroup=None)

source code 

Adds data to cache, returning False if already cached. Otherwise delegating to set

Parameters:
  • key - Unique key for cache
  • value - Value to cache - must be String
  • timeout - Optional timeout - otherwise use default
  • invalidateGroup - Not used?

get(self, key, default=None)

source code 

Gets data from cache

Parameters:
  • key - cache key
  • default - default value to return
Returns:
cache data or default if timout has passed
Overrides: CacheBase.get

set(self, key, value, timeout=None, invalidateGroup=None)

source code 

Adds data to cache, overwriting if already cached.

Parameters:
  • key - Unique key for cache
  • value - Value to cache - must be String
  • timeout - Optional timeout - otherwise use default
  • invalidateGroup - Not used?
Overrides: CacheBase.set

delete(self, key)

source code 

Attempt to delete the cache data referenced by key

Parameters:
  • key - Cache key
Overrides: CacheBase.delete

_delete(self, fname)

source code 

Tries to delete the data at the specified absolute file path

Parameters:
  • fname - File name of data to delete

wipe(self)

source code 

Deletes everything in the cache

Overrides: CacheBase.wipe

_check_entry(self, fname)

source code 

Verifies if a specific cache entry (provided as absolute file path) is expired. If expired, it gets deleted and method returns false. If not expired, returns True.

Parameters:
  • fname - File path

has_key(self, key)

source code 

Returns true if the cache has the specified key

Parameters:
  • key - Key to look for.
Returns: Boolean

_du(self)

source code 

Disk Usage count on the filesystem the cache is based at

Returns: int
the current usage, in KB

_full(self, _on_retry=False)

source code 

Checks whether the cache is full, either because we have exceeded max number of entries or the cache space is full.

Parameters:
  • _on_retry - Flag allows calling this method again after purge() without recursion
Returns: Boolean
True if cache is full

_purge(self)

source code 

Iterate the whole cache structure searching and cleaning expired entries. this method may be expensive, so only call it when really necessary.

_key_to_file(self, key)

source code 

Uses the key to construct an absolute path to the cache data.

Parameters:
  • key - Cache key
Returns: String
Path