Changeset - 52bbeb1e813f
[Not reviewed]
default
0 3 0
Marcin Kuzminski - 15 years ago 2010-05-21 02:44:40
marcin@python-works.com
Added universal cache invalidator for two cached functions.
added invalidation when repository was added or deleted, and another invalidation when there was a mercurial command involved.
3 files changed with 26 insertions and 10 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/admin.py
Show inline comments
 
@@ -82,7 +82,7 @@ class AdminController(BaseController):
 
            c.new_repo = new_repo
 
            c.msg = 'added repo'
 
            #clear our cached list for refresh with new repo
 
            invalidate_cache('repo_list_2')
 
            invalidate_cache('cached_repo_list')
 
        except Exception as e:
 
            c.new_repo = 'Exception when adding: %s' % new_repo
 
            c.msg = str(e)
pylons_app/lib/simplehg.py
Show inline comments
 
import os
 
from mercurial.hgweb import hgweb
 
from mercurial.hgweb.request import wsgiapplication
 
from pylons_app.lib.utils import make_ui
 
from pylons_app.lib.utils import make_ui, invalidate_cache
 
from pylons.controllers.util import abort
 
from webob.exc import HTTPNotFound
 
class SimpleHg(object):
 
@@ -22,12 +22,17 @@ class SimpleHg(object):
 
            #since we wrap into hgweb, just reset the path
 
            environ['PATH_INFO'] = '/'
 
            self.baseui = make_ui()
 
            self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '')
 
            self.basepath = self.baseui.configitems('paths')[0][1]\
 
                                                            .replace('*', '')
 
            self.repo_path = os.path.join(self.basepath, repo_name)
 
            try:
 
                app = wsgiapplication(self._make_app)
 
            except Exception as e:
 
                return HTTPNotFound()(environ, start_response)
 
            
 
            """we know that some change was made to repositories and we should
 
            invalidate the cache to see the changes right away"""
 
            invalidate_cache('full_changelog', repo_name)
 
            return app(environ, start_response)            
 

	
 
    def _make_app(self):
pylons_app/lib/utils.py
Show inline comments
 
@@ -90,14 +90,25 @@ def make_ui(path='hgwebdir.config', chec
 
    
 
    return baseui
 

	
 
def invalidate_cache(name):
 
def invalidate_cache(name, *args):
 
    from beaker.cache import region_invalidate
 
    if name == 'repo_list_2':
 
        log.info('INVALIDATING CACHE FOR %s', name)
 
        from pylons_app.lib.base import _get_repos
 
        #clear our cached list for refresh with new repo
 
        region_invalidate(_get_repos, None, 'repo_list_2')
 

	
 
    log.info('INVALIDATING CACHE FOR %s', name)
 
    
 
    """propaget our arguments to make sure invalidation works. First
 
    argument has to be the name of cached func name give to cache decorator
 
    without that the invalidation would not work"""
 
    tmp = [name]
 
    tmp.extend(args)
 
    args = tuple(tmp)
 
    
 
    if name == 'cached_repo_list':
 
        from pylons_app.lib.base import _get_repos_cached
 
        region_invalidate(_get_repos_cached, None, *args)
 
        
 
    if name == 'full_changelog':
 
        from pylons_app.controllers.changelog import _full_changelog_cached
 
        region_invalidate(_full_changelog_cached, None, *args)
 
        
 
from vcs.backends.base import BaseChangeset
 
from vcs.utils.lazy import LazyProperty
 
class EmptyChangeset(BaseChangeset):
0 comments (0 inline, 0 general)