mirror of
https://github.com/powerline/powerline.git
synced 2025-07-24 06:15:41 +02:00
parent
5b43960e0e
commit
332dc45bf9
@ -163,7 +163,7 @@ def branch():
|
|||||||
|
|
||||||
|
|
||||||
# TODO Drop cache on BufWrite event
|
# TODO Drop cache on BufWrite event
|
||||||
@memoize(2)
|
@memoize(2, additional_key=lambda: vim.current.buffer.number)
|
||||||
def file_vcs_status():
|
def file_vcs_status():
|
||||||
if vim.current.buffer.name and not vim.eval('&buftype'):
|
if vim.current.buffer.name and not vim.eval('&buftype'):
|
||||||
repo = guess(os.path.abspath(vim.current.buffer.name))
|
repo = guess(os.path.abspath(vim.current.buffer.name))
|
||||||
|
@ -11,8 +11,9 @@ class memoize(object):
|
|||||||
_caches = {}
|
_caches = {}
|
||||||
_timeouts = {}
|
_timeouts = {}
|
||||||
|
|
||||||
def __init__(self, timeout):
|
def __init__(self, timeout, additional_key=None):
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.additional_key = additional_key
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
'''Clear cache of results which have timed out.
|
'''Clear cache of results which have timed out.
|
||||||
@ -31,7 +32,10 @@ class memoize(object):
|
|||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
kw = kwargs.items()
|
kw = kwargs.items()
|
||||||
kw.sort()
|
kw.sort()
|
||||||
key = (args, tuple(kw))
|
if self.additional_key:
|
||||||
|
key = (args, tuple(kw), self.additional_key())
|
||||||
|
else:
|
||||||
|
key = (args, tuple(kw))
|
||||||
try:
|
try:
|
||||||
v = self.cache[key]
|
v = self.cache[key]
|
||||||
if (time.time() - v[1]) > self.timeout:
|
if (time.time() - v[1]) > self.timeout:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user