Example #1
0
 def utx():
   user = PMMUser.get(self.request.user.key())
   user.rec_pub -= 1
   if user.rec_pub < 0:
     user.rec_pub = 0
   user.put()
   cache_delete('gfcu', self.request.user.key().name())
Example #2
0
 def utx():
   user = PMMUser.get(recipe.parent_key())
   user.rec_pub -= 1
   if user.rec_pub < 0:
     user.rec_pub = 0
   user.put()
   cache_delete('gfcu', recipe.parent_key().name())
Example #3
0
def incrementCounter(key, property="counter", update_interval=10):
  """Increments a memcached counter.
  Args:
    key: The key of a datastore entity that contains the counter.
    update_interval: Minimum interval between updates.
  """
  lock_key = "icl:%s" % key
  count_key = "icv:%s" % key
  if cache_add(None, lock_key, time=update_interval):
    # Time to update the DB
    count = int(cache_get(count_key) or 0) + 1
    def tx():
      entity = db.get(key)
      setattr(entity, property, getattr(entity, property) + count)
      entity.put()
    db.run_in_transaction(tx)
    cache_delete(count_key)
  else:
    # Just update memcache
    cache_incr(1, count_key, initial_value=0)