##// END OF EJS Templates
caches: newly generated cache object should have always unique UIDs to prevent...
marcink -
r3861:58b00196 default
parent child Browse files
Show More
@@ -284,13 +284,22 b' class InvalidationContext(object):'
284 284 self.proc_id, self.thread_id, self.cache_key)
285 285 self.compute_time = 0
286 286
287 def get_or_create_cache_obj(self, uid, invalidation_namespace=''):
288 cache_obj = CacheKey.get_active_cache(self.cache_key)
287 def get_or_create_cache_obj(self, cache_type, invalidation_namespace=''):
288 invalidation_namespace = invalidation_namespace or self.invalidation_namespace
289 # fetch all cache keys for this namespace and convert them to a map to find if we
290 # have specific cache_key object registered. We do this because we want to have
291 # all consistent cache_state_uid for newly registered objects
292 cache_obj_map = CacheKey.get_namespace_map(invalidation_namespace)
293 cache_obj = cache_obj_map.get(self.cache_key)
289 294 log.debug('Fetched cache obj %s using %s cache key.', cache_obj, self.cache_key)
290 invalidation_namespace = invalidation_namespace or self.invalidation_namespace
291 295 if not cache_obj:
292 296 new_cache_args = invalidation_namespace
293 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args)
297 first_cache_obj = next(cache_obj_map.itervalues()) if cache_obj_map else None
298 cache_state_uid = None
299 if first_cache_obj:
300 cache_state_uid = first_cache_obj.cache_state_uid
301 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args,
302 cache_state_uid=cache_state_uid)
294 303 return cache_obj
295 304
296 305 def __enter__(self):
@@ -300,7 +309,7 b' class InvalidationContext(object):'
300 309 """
301 310 log.debug('Entering cache invalidation check context: %s', self.invalidation_namespace)
302 311 # register or get a new key based on uid
303 self.cache_obj = self.get_or_create_cache_obj(uid=self.uid)
312 self.cache_obj = self.get_or_create_cache_obj(cache_type=self.uid)
304 313 cache_data = self.cache_obj.get_dict()
305 314 self._start_time = time.time()
306 315 if self.cache_obj.cache_active:
@@ -3521,7 +3521,7 b' class CacheKey(Base, BaseModel):'
3521 3521 self.cache_args = cache_args
3522 3522 self.cache_active = False
3523 3523 # first key should be same for all entries, since all workers should share it
3524 self.cache_state_uid = cache_state_uid or self.generate_new_state_uid(based_on=cache_args)
3524 self.cache_state_uid = cache_state_uid or self.generate_new_state_uid()
3525 3525
3526 3526 def __unicode__(self):
3527 3527 return u"<%s('%s:%s[%s]')>" % (
@@ -3598,6 +3598,12 b' class CacheKey(Base, BaseModel):'
3598 3598 return inv_obj
3599 3599 return None
3600 3600
3601 @classmethod
3602 def get_namespace_map(cls, namespace):
3603 return {
3604 x.cache_key: x
3605 for x in cls.query().filter(cls.cache_args == namespace)}
3606
3601 3607
3602 3608 class ChangesetComment(Base, BaseModel):
3603 3609 __tablename__ = 'changeset_comments'
General Comments 0
You need to be logged in to leave comments. Login now