本文整理汇总了Python中DIRAC.Core.Utilities.DictCache.DictCache.purgeAll方法的典型用法代码示例。如果您正苦于以下问题:Python DictCache.purgeAll方法的具体用法?Python DictCache.purgeAll怎么用?Python DictCache.purgeAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Core.Utilities.DictCache.DictCache
的用法示例。
在下文中一共展示了DictCache.purgeAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cache
# 需要导入模块: from DIRAC.Core.Utilities.DictCache import DictCache [as 别名]
# 或者: from DIRAC.Core.Utilities.DictCache.DictCache import purgeAll [as 别名]
#.........这里部分代码省略.........
def cacheKeys( self ):
"""
Cache keys getter
:returns: list with valid keys on the cache
"""
return self.__cache.getKeys( validSeconds = self.__validSeconds )
#.............................................................................
# acquire / release Locks
def acquireLock( self ):
"""
Acquires Cache lock
"""
self.__cacheLock.acquire( self.__class__.__name__ )
def releaseLock( self ):
"""
Releases Cache lock
"""
self.__cacheLock.release( self.__class__.__name__)
#.............................................................................
# Cache getters
def get( self, 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
:return: S_OK | S_ERROR
"""
result = {}
for cacheKey in cacheKeys:
cacheRow = self.__cache.get( cacheKey, validSeconds = self.__validSeconds )
if not cacheRow:
self.log.error( str( cacheKey ) )
return S_ERROR( 'Cannot get %s' % str( cacheKey ) )
result.update( { cacheKey : cacheRow } )
return S_OK( result )
#.............................................................................
# Cache refreshers
def refreshCache( self ):
"""
Purges the cache and gets fresh data from the update function.
:return: S_OK | S_ERROR. If the first, its content is the new cache.
"""
self.log.verbose( 'refreshing...' )
self.__cache.purgeAll()
newCache = self.__updateFunc()
if not newCache[ 'OK' ]:
self.log.error( newCache[ 'Message' ] )
return newCache
newCache = self.__updateCache( newCache[ 'Value' ] )
self.log.verbose( 'refreshed' )
return newCache
#.............................................................................
# Private methods
def __updateCache( self, newCache ):
"""
Given the new cache dictionary, updates the internal cache with it. It sets
a duration to the entries of <self.__lifeTime> seconds.
:Parameters:
**newCache** - `dict`
dictionary containing a new cache
:return: dictionary. It is newCache argument.
"""
for cacheKey, cacheValue in newCache.items():
self.__cache.add( cacheKey, self.__lifeTime, value = cacheValue )
# We are assuming nothing will fail while inserting in the cache. There is
# no apparent reason to suspect from that piece of code.
return S_OK( newCache )
示例2: RSSCache
# 需要导入模块: from DIRAC.Core.Utilities.DictCache import DictCache [as 别名]
# 或者: from DIRAC.Core.Utilities.DictCache.DictCache import purgeAll [as 别名]
#.........这里部分代码省略.........
#cacheKey = '%s#%s' % ( resourceName, resourceStatusType )
self.__rssCacheLock.acquire()
resourceStatus = self.__rssCache.get( resourceKey )
self.__rssCacheLock.release()
if resourceStatus:
return S_OK( { resourceKey : resourceStatus } )
return S_ERROR( 'Cannot get %s' % resourceKey )
def getBulk( self, resourceKeys ):
'''
Gets values for resourceKeys in one ATOMIC operation.
'''
result = {}
self.__rssCacheLock.acquire()
for resourceKey in resourceKeys:
resourceRow = self.__rssCache.get( resourceKey )
if not resourceRow:
return S_ERROR( 'Cannot get %s' % resourceKey )
result.update( { resourceKey : resourceRow } )
self.__rssCacheLock.release()
return S_OK( result )
def resetCache( self ):
'''
Reset cache.
'''
self.__rssCacheLock.acquire()
self.__rssCache.purgeAll()
self.__rssCacheLock.release()
return S_OK()
def refreshCache( self ):
'''
Clears the cache and gets its latest version, not Thread safe !
Acquire a lock before using it ! ( and release it afterwards ! )
'''
self.__rssCache.purgeAll()
if self.__updateFunc is None:
return S_ERROR( 'RSSCache has no updateFunction' )
newCache = self.__updateFunc()
if not newCache[ 'OK' ]:
return newCache
itemsAdded = self.__updateCache( newCache[ 'Value' ] )
return itemsAdded
def refreshCacheAndHistory( self ):
'''
Method that refreshes the cache and updates the history. Not thread safe,
you must acquire a lock before using it, and release it right after !
'''
refreshResult = self.refreshCache()
now = datetime.datetime.utcnow()
示例3: __init__
# 需要导入模块: from DIRAC.Core.Utilities.DictCache import DictCache [as 别名]
# 或者: from DIRAC.Core.Utilities.DictCache.DictCache import purgeAll [as 别名]
class ProxyManagerClient:
__metaclass__ = DIRACSingleton.DIRACSingleton
def __init__( self ):
self.__usersCache = DictCache()
self.__proxiesCache = DictCache()
self.__vomsProxiesCache = DictCache()
self.__pilotProxiesCache = DictCache()
self.__filesCache = DictCache( self.__deleteTemporalFile )
def __deleteTemporalFile( self, filename ):
try:
os.unlink( filename )
except:
pass
def clearCaches( self ):
self.__usersCache.purgeAll()
self.__proxiesCache.purgeAll()
self.__vomsProxiesCache.purgeAll()
self.__pilotProxiesCache.purgeAll()
def __getSecondsLeftToExpiration( self, expiration, utc = True ):
if utc:
td = expiration - datetime.datetime.utcnow()
else:
td = expiration - datetime.datetime.now()
return td.days * 86400 + td.seconds
def __refreshUserCache( self, validSeconds = 0 ):
rpcClient = RPCClient( "Framework/ProxyManager", timeout = 120 )
retVal = rpcClient.getRegisteredUsers( validSeconds )
if not retVal[ 'OK' ]:
return retVal
data = retVal[ 'Value' ]
#Update the cache
for record in data:
cacheKey = ( record[ 'DN' ], record[ 'group' ] )
self.__usersCache.add( cacheKey,
self.__getSecondsLeftToExpiration( record[ 'expirationtime' ] ),
record )
return S_OK()
@gUsersSync
def userHasProxy( self, userDN, userGroup, validSeconds = 0 ):
"""
Check if a user(DN-group) has a proxy in the proxy management
- Updates internal cache if needed to minimize queries to the
service
"""
cacheKey = ( userDN, userGroup )
if self.__usersCache.exists( cacheKey, validSeconds ):
return S_OK( True )
#Get list of users from the DB with proxys at least 300 seconds
gLogger.verbose( "Updating list of users in proxy management" )
retVal = self.__refreshUserCache( validSeconds )
if not retVal[ 'OK' ]:
return retVal
return S_OK( self.__usersCache.exists( cacheKey, validSeconds ) )
@gUsersSync
def getUserPersistence( self, userDN, userGroup, validSeconds = 0 ):
"""
Check if a user(DN-group) has a proxy in the proxy management
- Updates internal cache if needed to minimize queries to the
service
"""
cacheKey = ( userDN, userGroup )
userData = self.__usersCache.get( cacheKey, validSeconds )
if userData:
if userData[ 'persistent' ]:
return S_OK( True )
#Get list of users from the DB with proxys at least 300 seconds
gLogger.verbose( "Updating list of users in proxy management" )
retVal = self.__refreshUserCache( validSeconds )
if not retVal[ 'OK' ]:
return retVal
userData = self.__usersCache.get( cacheKey, validSeconds )
if userData:
return S_OK( userData[ 'persistent' ] )
return S_OK( False )
def setPersistency( self, userDN, userGroup, persistent ):
"""
Set the persistency for user/group
"""
#Hack to ensure bool in the rpc call
persistentFlag = True
if not persistent:
persistentFlag = False
rpcClient = RPCClient( "Framework/ProxyManager", timeout = 120 )
retVal = rpcClient.setPersistency( userDN, userGroup, persistentFlag )
if not retVal[ 'OK' ]:
return retVal
#Update internal persistency cache
cacheKey = ( userDN, userGroup )
record = self.__usersCache.get( cacheKey, 0 )
if record:
record[ 'persistent' ] = persistentFlag
self.__usersCache.add( cacheKey,
#.........这里部分代码省略.........