##// END OF EJS Templates
Added universal cache invalidator for two cached functions....
marcink -
r171:52bbeb1e default
parent child Browse files
Show More
@@ -82,7 +82,7 b' class AdminController(BaseController):'
82 c.new_repo = new_repo
82 c.new_repo = new_repo
83 c.msg = 'added repo'
83 c.msg = 'added repo'
84 #clear our cached list for refresh with new repo
84 #clear our cached list for refresh with new repo
85 invalidate_cache('repo_list_2')
85 invalidate_cache('cached_repo_list')
86 except Exception as e:
86 except Exception as e:
87 c.new_repo = 'Exception when adding: %s' % new_repo
87 c.new_repo = 'Exception when adding: %s' % new_repo
88 c.msg = str(e)
88 c.msg = str(e)
@@ -1,7 +1,7 b''
1 import os
1 import os
2 from mercurial.hgweb import hgweb
2 from mercurial.hgweb import hgweb
3 from mercurial.hgweb.request import wsgiapplication
3 from mercurial.hgweb.request import wsgiapplication
4 from pylons_app.lib.utils import make_ui
4 from pylons_app.lib.utils import make_ui, invalidate_cache
5 from pylons.controllers.util import abort
5 from pylons.controllers.util import abort
6 from webob.exc import HTTPNotFound
6 from webob.exc import HTTPNotFound
7 class SimpleHg(object):
7 class SimpleHg(object):
@@ -22,12 +22,17 b' class SimpleHg(object):'
22 #since we wrap into hgweb, just reset the path
22 #since we wrap into hgweb, just reset the path
23 environ['PATH_INFO'] = '/'
23 environ['PATH_INFO'] = '/'
24 self.baseui = make_ui()
24 self.baseui = make_ui()
25 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '')
25 self.basepath = self.baseui.configitems('paths')[0][1]\
26 .replace('*', '')
26 self.repo_path = os.path.join(self.basepath, repo_name)
27 self.repo_path = os.path.join(self.basepath, repo_name)
27 try:
28 try:
28 app = wsgiapplication(self._make_app)
29 app = wsgiapplication(self._make_app)
29 except Exception as e:
30 except Exception as e:
30 return HTTPNotFound()(environ, start_response)
31 return HTTPNotFound()(environ, start_response)
32
33 """we know that some change was made to repositories and we should
34 invalidate the cache to see the changes right away"""
35 invalidate_cache('full_changelog', repo_name)
31 return app(environ, start_response)
36 return app(environ, start_response)
32
37
33 def _make_app(self):
38 def _make_app(self):
@@ -90,14 +90,25 b" def make_ui(path='hgwebdir.config', chec"
90
90
91 return baseui
91 return baseui
92
92
93 def invalidate_cache(name):
93 def invalidate_cache(name, *args):
94 from beaker.cache import region_invalidate
94 from beaker.cache import region_invalidate
95 if name == 'repo_list_2':
95 log.info('INVALIDATING CACHE FOR %s', name)
96 log.info('INVALIDATING CACHE FOR %s', name)
96
97 from pylons_app.lib.base import _get_repos
97 """propaget our arguments to make sure invalidation works. First
98 #clear our cached list for refresh with new repo
98 argument has to be the name of cached func name give to cache decorator
99 region_invalidate(_get_repos, None, 'repo_list_2')
99 without that the invalidation would not work"""
100
100 tmp = [name]
101 tmp.extend(args)
102 args = tuple(tmp)
103
104 if name == 'cached_repo_list':
105 from pylons_app.lib.base import _get_repos_cached
106 region_invalidate(_get_repos_cached, None, *args)
107
108 if name == 'full_changelog':
109 from pylons_app.controllers.changelog import _full_changelog_cached
110 region_invalidate(_full_changelog_cached, None, *args)
111
101 from vcs.backends.base import BaseChangeset
112 from vcs.backends.base import BaseChangeset
102 from vcs.utils.lazy import LazyProperty
113 from vcs.utils.lazy import LazyProperty
103 class EmptyChangeset(BaseChangeset):
114 class EmptyChangeset(BaseChangeset):
General Comments 0
You need to be logged in to leave comments. Login now