def __doRequest(self, ctx, callback): requestType = ctx.getRequestType() cachedValue = self.__webCache.get(requestType, None) if cachedValue is not None and cachedValue.isExpired(): cachedValue = None if cachedValue is None: if requestType not in self.__processingRequests: self.__processingRequests[requestType].append(callback) result = yield self._webCtrl.sendRequest(ctx) if result.isSuccess(): formattedData = ctx.getDataObj(result.data) if ctx.isCaching(): cachedValue = CachedValue(CLAN_DOSSIER_LIFE_TIME) cachedValue.set(formattedData) self.__webCache[requestType] = cachedValue else: formattedData = ctx.getDefDataObj() for cb in self.__processingRequests[requestType]: cb(formattedData) del self.__processingRequests[requestType] else: self.__processingRequests[requestType].append(callback) else: callback(cachedValue.getCachedValue()) return
def __init__(self, clansCtrl, accountDbID, clanDbID=0, clanBwInfo=None): self._clansCtrl = weakref.proxy(clansCtrl) self._accountDbID = accountDbID self._clanDbID = clanDbID self._clanBwInfo = clanBwInfo self._waitForSync = 0 self._syncState = 0 self._vitalWebInfo = defaultdict(lambda: None) self._cache = defaultdict(lambda: None) self._isInvitesLimitReached = CachedValue(INVITE_LIMITS_LIFE_TIME)