diff --git a/powerline/ext/vim/segments/core.py b/powerline/ext/vim/segments/core.py index 9709ca31..0dc538a2 100644 --- a/powerline/ext/vim/segments/core.py +++ b/powerline/ext/vim/segments/core.py @@ -163,7 +163,7 @@ def branch(): # TODO Drop cache on BufWrite event -@memoize(2) +@memoize(2, additional_key=lambda: vim.current.buffer.number) def file_vcs_status(): if vim.current.buffer.name and not vim.eval('&buftype'): repo = guess(os.path.abspath(vim.current.buffer.name)) diff --git a/powerline/lib/memoize.py b/powerline/lib/memoize.py index 05f71181..a683c25f 100644 --- a/powerline/lib/memoize.py +++ b/powerline/lib/memoize.py @@ -11,8 +11,9 @@ class memoize(object): _caches = {} _timeouts = {} - def __init__(self, timeout): + def __init__(self, timeout, additional_key=None): self.timeout = timeout + self.additional_key = additional_key def collect(self): '''Clear cache of results which have timed out. @@ -31,7 +32,10 @@ class memoize(object): def func(*args, **kwargs): kw = kwargs.items() kw.sort() - key = (args, tuple(kw)) + if self.additional_key: + key = (args, tuple(kw), self.additional_key()) + else: + key = (args, tuple(kw)) try: v = self.cache[key] if (time.time() - v[1]) > self.timeout: