Example #1
0
 def cache_user_activeRewards(self, uid):
     #returns {user:rewards}
     r = ActiveReward.by_uid(uid) 
     key = 'activeRewards_%s' %(uid)
     #activeRewards_cache[uid] = r
     #cacheEntry = r #activeRewards_cache
     memcache.add(key, r)#cacheEntry)
     result = r
     return result
Example #2
0
 def post(self, uid, rid):
     #link reward to user
     #    get rid data
     #    create linkedReward object
     #    write object to CACHE
     #    return 200, ok to client
     
     #get reward info from DB...Change to cache hit
     
     #use rid to pull up reward info
     reward = Reward.by_rid(rid)
     logging.error("got reward from db")
     for r in reward:
         mid = r.mid
         type = r.type
         summary = r.summary
         details = r.details
         fineprint = r.fineprint
         discount = r.discount
         credit = r.credit
         l_amount = r.l_amount
         l_visits = r.l_visits
         l_maxNumber = r.l_maxNumber
         exp = r.exp
     #insert active reward into datastore    
     r = ActiveReward.register(uid, rid, mid, type, summary, details, fineprint, discount, credit, l_amount, l_visits, l_maxNumber, exp)
     #update cache
     if r:
         message = {
             'status': 200,
             'message': 'linked reward and updated cache',
         }    
         resp = jsonify(message)
         resp.status_code = 200
         
         #check for object in cache
         key = "activeRewards_%s" %(uid)
         activeRewards_cache = memcache.get(key)
         if activeRewards_cache:
             #if found, delete object to force a db read next get request
             memcache.delete(key)
             return resp
         else:
             return resp
     else:
         #if no r linking failed
         pass