class Dcache(object): _nodeRing = None _cachePool = {} _cacheGen = CacheInterface def __init__(self, nodes=[], rep=3, cache=RedisCache): ''' init all node to caches''' if nodes: self._nodeRing = CSHash(nodes=nodes, replicas=rep) self._cacheGen = cache for key, node in self._nodeRing.sorted_nodes(): if node not in self._cachePool: self._cachePool[node] = self._cacheGen.alloc(node) else: raise DcacheException, 'try to init with no nodes\n' def get_all_nodes(self, ): for key, node in self._nodeRing.sorted_nodes(): yield key, node def add_node(self, node): ''' add node to caches, preload the nearest forward node data to self''' for fnode in self._nodeRing.get_fnode(node): try: self.preload(fnode, node) except Exception, ex: raise DcacheException, '%s' % ex self._nodeRing.add_node(node) self._cachePool[node] = self._cacheGen.alloc(node)
class Dcache(object): _nodeRing = None _cachePool = {} _cacheGen = CacheInterface def __init__(self, nodes=[], rep=3, cache=RedisCache): ''' init all node to caches''' if nodes: self._nodeRing = CSHash(nodes=nodes, replicas=rep) self._cacheGen = cache for key, node in self._nodeRing.sorted_nodes(): if node not in self._cachePool: self._cachePool[node] = self._cacheGen.alloc(node) else: raise DcacheException, 'try to init with no nodes\n' def add_node(self, node): ''' add node to caches, preload the nearest forward node data to self''' for fnode in self._nodeRing.get_fnode(node): try: self.preload(fnode, node) except Exception, ex: raise DcacheException, '%s' % ex self._nodeRing.add_node(node) self._cachePool[node] = self._cacheGen.alloc(node)
def __init__(self, nodes=[], rep=3, cache=RedisCache): ''' init all node to caches''' if nodes: self._nodeRing = CSHash(nodes=nodes, replicas=rep) self._cacheGen = cache for key, node in self._nodeRing.sorted_nodes(): if node not in self._cachePool: self._cachePool[node] = self._cacheGen.alloc(node) else: raise DcacheException, 'try to init with no nodes\n'