Пример #1
0
 def getUserStamps(self, params):
     params['scope'] = 'user'
     
     if self._ec2:
         key = str("web::getUserStamps::%s" % generateKeyFromDictionary(params))
         ret = self._try_get_cache(key)
         
         if ret is not None:
             return ret
         
         ts  = HTTPTimeSlice.exportTimeSlice(HTTPTimeSlice().dataImport(params))
         ret = self._transform_stamps(self.api.getStampCollection(ts, None))
         
         return self._try_set_cache(key, ret)
     else:
         return self._handle_get("stamps/collection.json", params)
Пример #2
0
 def getUser(self, params, no_cache=False):
     if self._ec2:
         key = str("web::getUser::%s" % generateKeyFromDictionary(params))
         
         if not no_cache:
             ret = self._try_get_cache(key)
             
             if ret is not None:
                 return ret
         
         user = self.api.getUser(HTTPUserId().dataImport(params), None)
         ret  = HTTPUser().importUser(user).dataExport()
         
         return self._try_set_cache(key, ret)
     else:
         return self._handle_get("users/show.json", params)
Пример #3
0
    def getPopularStampIds(self, **kwargs):
        key = str("fn::MongoStampCollection.getPopularStampIds::%s" % generateKeyFromDictionary(kwargs))
        try:
            return self._cache[key]
        except KeyError:
            pass

        limit = kwargs.pop('limit', 0)
        
        query = self._buildPopularQuery(**kwargs)

        documents = self._collection.find(query, fields=['_id']) \
                        .sort([('score', pymongo.DESCENDING)]) \
                        .limit(limit)

        result = map(lambda x: self._getStringFromObjectId(x['_id']), documents)

        cacheLength = 60 * 10 # 10 minutes
        try:
            self._cache.set(key, result, time=cacheLength)
        except Exception as e:
            logs.warning("Unable to set cache for key '%s': %s" % (key, e))

        return result