def getJ3mDoc(self,param): j3mDoc = J3mCache.getJ3mFromCache(param) if j3mDoc is None : handle = yield getDocWrapper(self,param) self.objectHandle = json_decode(handle) url = "%s%s%s%s%s" % (buildServerURL(),"/documents/?doc_type=ic_j3m&_id=" ,self.objectHandle['data']['j3m_id'], '&media_id=', self.objectHandle['data']['_id']) if DEBUG: print str(self) +"SENDING REQUEST TO %s" % url http_client = AsyncHTTPClient() future = http_client.fetch(url) J3mCache.putJ3mInCache(param,future) response = yield future raise gen.Return(response.body) elif isinstance(j3mDoc, Future) : if DEBUG: print str(self) + "is j3mDoc future" response = yield j3mDoc J3mCache.putJ3mInCache(param,response) raise gen.Return(response.body) else : if DEBUG: print str(self) +"got j3mDoc otherwise" raise gen.Return(j3mDoc.body)
def getDocWrapper(self,param): doc = J3mCache.getWrapFromCache(param) if doc is None : url = "%s%s%s" % (buildServerURL(),"/documents/?_id=" ,param) if DEBUG: print str(self) +"SENDING REQUEST TO %s" % url http_client = AsyncHTTPClient() future = http_client.fetch(url) J3mCache.putWrapInCache(param,future) response = yield future J3mCache.putWrapInCache(param,response) raise gen.Return(response.body) elif isinstance(doc, Future) : if DEBUG: print str(self) +"is future" response = yield doc J3mCache.putWrapInCache(param,response) raise gen.Return(response.body) else : if DEBUG: print str(self) +"got otherwise: " + str(doc) raise gen.Return(doc.body)