DictCache

DictCache.

class DIRAC.Core.Utilities.DictCache.DictCache(deleteFunction=False, threadLocal=False)

Bases: object

DictCache is a generic cache implementation. The user can decide whether this cache should be shared among the threads or not, but it is always thread safe Note that when shared, the access to the cache is protected by a lock, but not necessarily the object you are retrieving from it.

__init__(deleteFunction=False, threadLocal=False)

Initialize the dict cache.

param deleteFunction:
 if not False, invoked when deleting a cached object
param threadLocal:
 if False, the cache will be shared among all the threads, otherwise, each thread gets its own cache.
add(cKey, validSeconds, value=None)

Add a record to the cache

Parameters:
  • cKey – identification key of the record
  • validSeconds – valid seconds of this record
  • value – value of the record
delete(cKey)

Delete a key from the cache

Parameters:cKey – identification key of the record
exists(cKey, validSeconds=0)

Returns True/False if the key exists for the given number of seconds Arguments: :param cKey: identification key of the record :param validSeconds: The amount of seconds the key has to be valid for

get(cKey, validSeconds=0)

Get a record from the cache

Parameters:
  • cKey – identification key of the record
  • validSeconds – The amount of seconds the key has to be valid for
getKeys(validSeconds=0)

Get keys for all contents

lock

Return the lock. In practice, if the cache is shared among threads, it is a LockRing. Otherwise, it is just a mock object.

purgeAll(useLock=True)

Purge all entries CAUTION: useLock parameter should ALWAYS be True except when called from __del__

purgeExpired(expiredInSeconds=0)

Purge all entries that are expired or will be expired in <expiredInSeconds>

showContentsInString()

Return a human readable string to represent the contents

class DIRAC.Core.Utilities.DictCache.MockLockRing

Bases: object

This mock class is just used to expose the acquire and release method

__init__

x.__init__(…) initializes x; see help(type(x)) for signature

acquire(*args, **kwargs)

Really does nothing !

doNothing(*args, **kwargs)

Really does nothing !

release(*args, **kwargs)

Really does nothing !

class DIRAC.Core.Utilities.DictCache.ThreadLocalDict

Bases: thread._local

This class is just useful to have a mutable object (in this case, a dict) as a thread local Read the _threading_local docstring for more details.

Its purpose is to have a different cache per thread

__init__()

c’tor