RSSCacheNoThread

Cache

This module provides a generic Cache extended to be used on RSS, RSSCache. This cache features a lazy update method. It will only be updated if it is empty and there is a new query. If not, it will remain in its previous state. However, Cache class internal cache: DictCache sets a validity to its entries. After that, the cache is empty.

class DIRAC.ResourceStatusSystem.Utilities.RSSCacheNoThread.Cache(lifeTime, updateFunc)

Bases: object

Cache basic class.

WARNING: None of its methods is thread safe. Acquire / Release lock when using them !

__init__(lifeTime, updateFunc)

Constructor

Parameters:
lifeTime - int

Lifetime of the elements in the cache ( seconds ! )

updateFunc - function

This function MUST return a S_OK | S_ERROR object. In the case of the first, its value must be a dictionary.

acquireLock()

Acquires Cache lock

cacheKeys()

Cache keys getter

Returns:

list with keys in the cache valid for at least twice the validity period of the element

check(cacheKeys, vO)

Modified get() method. Attempts to find keys with a vO value appended or ‘all’ value appended. The cacheKeys passed in are ‘flattened’ cache keys (no vO) Gets values for cacheKeys given, if all are found ( present on the cache and valid ), returns S_OK with the results. If any is not neither present not valid, returns S_ERROR.

Parameters:
cacheKeys - list

list of keys to be extracted from the cache

Returns:

S_OK | S_ERROR

get(cacheKeys)

Gets values for cacheKeys given, if all are found ( present on the cache and valid ), returns S_OK with the results. If any is not neither present not valid, returns S_ERROR.

Parameters:
cacheKeys - list

list of keys to be extracted from the cache

Returns:

S_OK | S_ERROR

refreshCache()

Purges the cache and gets fresh data from the update function.

Returns:

S_OK | S_ERROR. If the first, its content is the new cache.

releaseLock()

Releases Cache lock

class DIRAC.ResourceStatusSystem.Utilities.RSSCacheNoThread.RSSCache(lifeTime, updateFunc)

Bases: Cache

The RSSCache is an extension of Cache in which the cache keys are pairs of the form: ( elementName, statusType ).

When instantiating one object of RSSCache, we need to specify the RSS elementType it applies, e.g. : StorageElement, CE, Queue, …

It provides a unique public method match which is thread safe. All other methods are not !!

__init__(lifeTime, updateFunc)

Constructor

Parameters:
elementType - string

RSS elementType, e.g.: StorageElement, CE, Queue… note that one RSSCache can only hold elements of a single elementType to avoid issues while doing the Cartesian product.

lifeTime - int

Lifetime of the elements in the cache ( seconds ! )

updateFunc - function

This function MUST return a S_OK | S_ERROR object. In the case of the first, its value must follow the dict format: ( key, value ) being key ( elementName, statusType ) and value status.

acquireLock()

Acquires Cache lock

cacheKeys()

Cache keys getter

Returns:

list with keys in the cache valid for at least twice the validity period of the element

check(cacheKeys, vO)

Modified get() method. Attempts to find keys with a vO value appended or ‘all’ value appended. The cacheKeys passed in are ‘flattened’ cache keys (no vO) Gets values for cacheKeys given, if all are found ( present on the cache and valid ), returns S_OK with the results. If any is not neither present not valid, returns S_ERROR.

Parameters:
cacheKeys - list

list of keys to be extracted from the cache

Returns:

S_OK | S_ERROR

get(cacheKeys)

Gets values for cacheKeys given, if all are found ( present on the cache and valid ), returns S_OK with the results. If any is not neither present not valid, returns S_ERROR.

Parameters:
cacheKeys - list

list of keys to be extracted from the cache

Returns:

S_OK | S_ERROR

match(elementNames, elementType, statusTypes, vO)

In first instance, if the cache is invalid, it will request a new one from the server. It make the Cartesian product of elementNames x statusTypes to generate a key set that will be compared against the cache set. If the first is included in the second, we have a positive match and a dictionary will be returned. Otherwise, we have a cache miss.

However, arguments ( elementNames or statusTypes ) can have a None value. If that is the case, they are considered wildcards.

Parameters:
elementNames - [ None, string, list ]

name(s) of the elements to be matched

elementType - [ string ]

type of the elements to be matched

statusTypes - [ None, string, list ]

name(s) of the statusTypes to be matched

Returns:

S_OK() || S_ERROR()

refreshCache()

Purges the cache and gets fresh data from the update function.

Returns:

S_OK | S_ERROR. If the first, its content is the new cache.

releaseLock()

Releases Cache lock