comparison rhodecode/model/db.py @ 3234:21cccfea18bf beta

Return a list of invlidated keys on mark_for_invalidation func - log.debug list of invalidated keys
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Jan 2013 23:11:40 +0100
parents 99ce5d097a09
children a9565b8b429b
comparison
equal deleted inserted replaced
3233:11b005b2d5e8 3234:21cccfea18bf
1651 Mark this Cache key for invalidation, either by key or whole 1651 Mark this Cache key for invalidation, either by key or whole
1652 cache sets based on repo_name 1652 cache sets based on repo_name
1653 1653
1654 :param key: 1654 :param key:
1655 """ 1655 """
1656 invalidated_keys = []
1656 if key: 1657 if key:
1657 key, _prefix, _org_key = cls._get_key(key) 1658 key, _prefix, _org_key = cls._get_key(key)
1658 inv_objs = Session().query(cls).filter(cls.cache_key == key).all() 1659 inv_objs = Session().query(cls).filter(cls.cache_key == key).all()
1659 elif repo_name: 1660 elif repo_name:
1660 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all() 1661 inv_objs = Session().query(cls).filter(cls.cache_args == repo_name).all()
1661 1662
1662 log.debug('marking %s key[s] for invalidation based on key=%s,repo_name=%s'
1663 % (len(inv_objs), key, repo_name))
1664 try: 1663 try:
1665 for inv_obj in inv_objs: 1664 for inv_obj in inv_objs:
1666 inv_obj.cache_active = False 1665 inv_obj.cache_active = False
1666 log.debug('marking %s key for invalidation based on key=%s,repo_name=%s'
1667 % (inv_obj, key, repo_name))
1668 invalidated_keys.append(inv_obj.cache_key)
1667 Session().add(inv_obj) 1669 Session().add(inv_obj)
1668 Session().commit() 1670 Session().commit()
1669 except Exception: 1671 except Exception:
1670 log.error(traceback.format_exc()) 1672 log.error(traceback.format_exc())
1671 Session().rollback() 1673 Session().rollback()
1674 return invalidated_keys
1672 1675
1673 @classmethod 1676 @classmethod
1674 def set_valid(cls, key): 1677 def set_valid(cls, key):
1675 """ 1678 """
1676 Mark this cache key as active and currently cached 1679 Mark this cache key as active and currently cached