def _incr(self, prop, amt = 1): if self._dirty: raise ValueError, "cannot incr dirty thing" prefix = thing_prefix(self.__class__.__name__) key = prefix + prop + '_' + str(self._id) cache_val = old_val = cache.get(key) if old_val is None: old_val = getattr(self, prop) if self._defaults.has_key(prop) and self._defaults[prop] == old_val: #potential race condition if the same property gets incr'd #from default at the same time setattr(self, prop, old_val + amt) self._commit(prop) else: self.__setattr__(prop, old_val + amt, False) #db if prop.startswith('_'): tdb.incr_thing_prop(self._type_id, self._id, prop[1:], amt) else: self._incr_data(self._type_id, self._id, prop, amt) cache.set(prefix + str(self._id), self) #cache if cache_val: cache.incr(key, amt) else: cache.set(key, getattr(self, prop))