##// END OF EJS Templates
Cleaned the way cache keys are invalidated...
marcink -
r3020:00498b3e beta
parent child Browse files
Show More
@@ -448,8 +448,10 b' def repo2db_mapper(initial_repo_list, re'
448 448 # during starting install all cache keys for all repositories in the
449 449 # system, this will register all repos and multiple instances
450 450 key, _prefix, _org_key = CacheInvalidation._get_key(name)
451 log.debug("Creating a cache key for %s instance_id:`%s`" % (name, _prefix))
452 CacheInvalidation._get_or_create_key(key, _prefix, _org_key, commit=False)
451 CacheInvalidation.invalidate(name)
452 log.debug("Creating a cache key for %s instance_id=>`%s`"
453 % (name, _prefix or '-'))
454
453 455 sa.commit()
454 456 removed = []
455 457 if remove_obsolete:
@@ -937,7 +937,7 b' class Repository(Base, BaseModel):'
937 937 """
938 938 set a cache for invalidation for this instance
939 939 """
940 CacheInvalidation.set_invalidate(self.repo_name)
940 CacheInvalidation.set_invalidate(repo_name=self.repo_name)
941 941
942 942 @LazyProperty
943 943 def scm_instance(self):
@@ -1438,25 +1438,27 b' class CacheInvalidation(Base, BaseModel)'
1438 1438 """
1439 1439 import rhodecode
1440 1440 prefix = ''
1441 org_key = key
1441 1442 iid = rhodecode.CONFIG.get('instance_id')
1442 1443 if iid:
1443 1444 prefix = iid
1444 #remove specific suffixes like _README or _RSS
1445 key = remove_suffix(key, '_README')
1446 key = remove_suffix(key, '_RSS')
1447 key = remove_suffix(key, '_ATOM')
1448 return "%s%s" % (prefix, key), prefix, key
1445
1446 return "%s%s" % (prefix, key), prefix, org_key
1449 1447
1450 1448 @classmethod
1451 1449 def get_by_key(cls, key):
1452 1450 return cls.query().filter(cls.cache_key == key).scalar()
1453 1451
1454 1452 @classmethod
1455 def _get_or_create_key(cls, key, prefix, org_key, commit=True):
1453 def get_by_repo_name(cls, repo_name):
1454 return cls.query().filter(cls.cache_args == repo_name).all()
1455
1456 @classmethod
1457 def _get_or_create_key(cls, key, repo_name, commit=True):
1456 1458 inv_obj = Session().query(cls).filter(cls.cache_key == key).scalar()
1457 1459 if not inv_obj:
1458 1460 try:
1459 inv_obj = CacheInvalidation(key, org_key)
1461 inv_obj = CacheInvalidation(key, repo_name)
1460 1462 Session().add(inv_obj)
1461 1463 if commit:
1462 1464 Session().commit()
@@ -1474,30 +1476,38 b' class CacheInvalidation(Base, BaseModel)'
1474 1476
1475 1477 :param key:
1476 1478 """
1479 repo_name = key
1480 repo_name = remove_suffix(repo_name, '_README')
1481 repo_name = remove_suffix(repo_name, '_RSS')
1482 repo_name = remove_suffix(repo_name, '_ATOM')
1477 1483
1484 # adds instance prefix
1478 1485 key, _prefix, _org_key = cls._get_key(key)
1479 inv = cls._get_or_create_key(key, _prefix, _org_key)
1486 inv = cls._get_or_create_key(key, repo_name)
1480 1487
1481 1488 if inv and inv.cache_active is False:
1482 1489 return inv
1483 1490
1484 1491 @classmethod
1485 def set_invalidate(cls, key):
1492 def set_invalidate(cls, key=None, repo_name=None):
1486 1493 """
1487 Mark this Cache key for invalidation
1494 Mark this Cache key for invalidation, either by key or whole
1495 cache sets based on repo_name
1488 1496
1489 1497 :param key:
1490 1498 """
1491
1499 if key:
1492 1500 key, _prefix, _org_key = cls._get_key(key)
1493 inv_objs = Session().query(cls).filter(cls.cache_args == _org_key).all()
1494 log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs),
1495 _org_key))
1501 inv_objs = Session().query(cls).filter(cls.cache_key == key).all()
1502 elif repo_name:
1503 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all()
1504
1505 log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s'
1506 % (len(inv_objs), key, repo_name))
1496 1507 try:
1497 1508 for inv_obj in inv_objs:
1498 if inv_obj:
1509 print inv_obj
1499 1510 inv_obj.cache_active = False
1500
1501 1511 Session().add(inv_obj)
1502 1512 Session().commit()
1503 1513 except Exception:
@@ -291,7 +291,7 b' class ScmModel(BaseModel):'
291 291
292 292 :param repo_name: this repo that should invalidation take place
293 293 """
294 CacheInvalidation.set_invalidate(repo_name)
294 CacheInvalidation.set_invalidate(repo_name=repo_name)
295 295
296 296 def toggle_following_repo(self, follow_repo_id, user_id):
297 297
@@ -1627,6 +1627,7 b' div.form div.fields div.field div.button'
1627 1627 background: #eee;
1628 1628 border-bottom: 1px solid #ddd;
1629 1629 padding: 5px 0px 5px 5px;
1630 text-align: left;
1630 1631 }
1631 1632
1632 1633 #content div.box table th.left {
@@ -196,11 +196,20 b''
196 196 </div>
197 197 <div class="field" style="border:none;">
198 198 ${_('List of cached values')}
199 <ul>
199 <table>
200 <tr>
201 <th>${_('Prefix')}</th>
202 <th>${_('Key')}</th>
203 <th>${_('Active')}</th>
204 </tr>
200 205 %for cache in c.repo_info.cache_keys:
201 <li>INSTANCE ID:${cache.prefix or '-'} ${cache.cache_args} CACHED: ${h.bool2icon(cache.cache_active)}</li>
206 <tr>
207 <td>${cache.prefix or '-'}</td>
208 <td>${cache.cache_key}</td>
209 <td>${h.bool2icon(cache.cache_active)}</td>
210 </tr>
202 211 %endfor
203 </ul>
212 </table>
204 213 </div>
205 214 </div>
206 215 </div>
General Comments 0
You need to be logged in to leave comments. Login now