Changeset - 8e2cd46f765b
[Not reviewed]
beta
0 4 0
Mads Kiilerich - 13 years ago 2013-04-03 15:56:12
madski@unity3d.com
Grafted from: 2bdc6d81f5a2
invalidate: encapsulate how key is generated from repo_name and kind
4 files changed with 21 insertions and 24 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/feed.py
Show inline comments
 
@@ -118,7 +118,7 @@ class FeedController(BaseRepoController)
 
        """Produce an atom-1.0 feed via feedgenerator module"""
 

	
 
        @cache_region('long_term')
 
        def _get_feed_from_cache(key):
 
        def _get_feed_from_cache(key, kind):
 
            feed = Atom1Feed(
 
                 title=self.title % repo_name,
 
                 link=url('summary_home', repo_name=repo_name,
 
@@ -140,17 +140,17 @@ class FeedController(BaseRepoController)
 
            response.content_type = feed.mime_type
 
            return feed.writeString('utf-8')
 

	
 
        key = repo_name + '_ATOM'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        kind = 'ATOM'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, key)
 
        return _get_feed_from_cache(key)
 
            region_invalidate(_get_feed_from_cache, None, repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
 

	
 
    def rss(self, repo_name):
 
        """Produce an rss2 feed via feedgenerator module"""
 

	
 
        @cache_region('long_term')
 
        def _get_feed_from_cache(key):
 
        def _get_feed_from_cache(key, kind):
 
            feed = Rss201rev2Feed(
 
                title=self.title % repo_name,
 
                link=url('summary_home', repo_name=repo_name,
 
@@ -172,8 +172,8 @@ class FeedController(BaseRepoController)
 
            response.content_type = feed.mime_type
 
            return feed.writeString('utf-8')
 

	
 
        key = repo_name + '_RSS'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        kind = 'RSS'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
        if not valid:
 
            region_invalidate(_get_feed_from_cache, None, key)
 
        return _get_feed_from_cache(key)
 
            region_invalidate(_get_feed_from_cache, None, repo_name, kind)
 
        return _get_feed_from_cache(repo_name, kind)
rhodecode/controllers/summary.py
Show inline comments
 
@@ -92,7 +92,7 @@ class SummaryController(BaseRepoControll
 
        repo_name = db_repo.repo_name
 

	
 
        @cache_region('long_term')
 
        def _get_readme_from_cache(key):
 
        def _get_readme_from_cache(key, kind):
 
            readme_data = None
 
            readme_file = None
 
            log.debug('Looking for README file')
 
@@ -124,11 +124,11 @@ class SummaryController(BaseRepoControll
 

	
 
            return readme_data, readme_file
 

	
 
        key = repo_name + '_README'
 
        valid = CacheInvalidation.test_and_set_valid(key)
 
        if not valid:
 
            region_invalidate(_get_readme_from_cache, None, key)
 
        return _get_readme_from_cache(key)
 
        kind = 'README'
 
        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
 
		if not valid:
 
            region_invalidate(_get_readme_from_cache, None, repo_name, kind)
 
        return _get_readme_from_cache(repo_name, kind)
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
rhodecode/lib/utils.py
Show inline comments
 
@@ -476,7 +476,7 @@ def repo2db_mapper(initial_repo_list, re
 
        # system, this will register all repos and multiple instances
 
        cache_key = CacheInvalidation._get_cache_key(name)
 
        log.debug("Creating invalidation cache key for %s: %s", name, cache_key)
 
        CacheInvalidation.test_and_set_valid(name)
 
        CacheInvalidation.test_and_set_valid(name, None)
 

	
 
    sa.commit()
 
    removed = []
rhodecode/model/db.py
Show inline comments
 
@@ -1186,7 +1186,7 @@ class Repository(Base, BaseModel):
 
            return self.__get_instance()
 
        rn = self.repo_name
 

	
 
        valid = CacheInvalidation.test_and_set_valid(rn, valid_cache_keys=valid_cache_keys)
 
        valid = CacheInvalidation.test_and_set_valid(rn, None, valid_cache_keys=valid_cache_keys)
 
        if not valid:
 
            log.debug('Cache for %s invalidated, getting new object' % (rn))
 
            region_invalidate(_c, None, rn)
 
@@ -1828,22 +1828,19 @@ class CacheInvalidation(Base, BaseModel)
 
            Session().rollback()
 

	
 
    @classmethod
 
    def test_and_set_valid(cls, key, valid_cache_keys=None):
 
    def test_and_set_valid(cls, repo_name, kind, valid_cache_keys=None):
 
        """
 
        Mark this cache key as active and currently cached.
 
        Return True if the existing cache registration still was valid.
 
        Return False to indicate that it had been invalidated and caches should be refreshed.
 
        """
 

	
 
        key = (repo_name + '_' + kind) if kind else repo_name
 
        cache_key = cls._get_cache_key(key)
 

	
 
        if valid_cache_keys and cache_key in valid_cache_keys:
 
            return True
 

	
 
        repo_name = key
 
        repo_name = remove_suffix(repo_name, '_README')
 
        repo_name = remove_suffix(repo_name, '_RSS')
 
        repo_name = remove_suffix(repo_name, '_ATOM')
 

	
 
        try:
 
            inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar()
 
            if not inv_obj:
0 comments (0 inline, 0 general)