forked from VimPlug/jedi
move module caching from builtin to cache
This commit is contained in:
@@ -47,18 +47,9 @@ class CachedModule(object):
|
|||||||
@property
|
@property
|
||||||
def parser(self):
|
def parser(self):
|
||||||
""" get the parser lazy """
|
""" get the parser lazy """
|
||||||
if not self._parser:
|
if self._parser is None:
|
||||||
try:
|
self._parser = cache.load_module(self.path, self.name)
|
||||||
timestamp, parser = cache.module_cache[self.path or self.name]
|
if self._parser is None:
|
||||||
if not self.path or os.path.getmtime(self.path) <= timestamp:
|
|
||||||
self._parser = parser
|
|
||||||
else:
|
|
||||||
# In case there is already a module cached and this module
|
|
||||||
# has to be reparsed, we also need to invalidate the import
|
|
||||||
# caches.
|
|
||||||
cache.invalidate_star_import_cache(parser.module)
|
|
||||||
raise KeyError()
|
|
||||||
except KeyError:
|
|
||||||
self._load_module()
|
self._load_module()
|
||||||
return self._parser
|
return self._parser
|
||||||
|
|
||||||
@@ -69,10 +60,7 @@ class CachedModule(object):
|
|||||||
source = self._get_source()
|
source = self._get_source()
|
||||||
p = self.path or self.name
|
p = self.path or self.name
|
||||||
self._parser = fast_parser.FastParser(source, p)
|
self._parser = fast_parser.FastParser(source, p)
|
||||||
p_time = None if not self.path else os.path.getmtime(self.path)
|
cache.save_module(self.path, self.name, self._parser)
|
||||||
|
|
||||||
if self.path or self.name:
|
|
||||||
cache.module_cache[self.path or self.name] = p_time, self._parser
|
|
||||||
|
|
||||||
|
|
||||||
class Parser(CachedModule):
|
class Parser(CachedModule):
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
# memoize caches will be deleted after every action
|
# memoize caches will be deleted after every action
|
||||||
@@ -87,6 +89,7 @@ def time_cache(time_add_setting):
|
|||||||
def _temp(key_func):
|
def _temp(key_func):
|
||||||
dct = {}
|
dct = {}
|
||||||
time_caches.append(dct)
|
time_caches.append(dct)
|
||||||
|
|
||||||
def wrapper(optional_callable, *args, **kwargs):
|
def wrapper(optional_callable, *args, **kwargs):
|
||||||
key = key_func(*args, **kwargs)
|
key = key_func(*args, **kwargs)
|
||||||
value = None
|
value = None
|
||||||
@@ -144,3 +147,41 @@ def invalidate_star_import_cache(module, only_main=False):
|
|||||||
for key, (t, mods) in list(star_import_cache.items()):
|
for key, (t, mods) in list(star_import_cache.items()):
|
||||||
if module in mods:
|
if module in mods:
|
||||||
invalidate_star_import_cache(key)
|
invalidate_star_import_cache(key)
|
||||||
|
|
||||||
|
|
||||||
|
def load_module(path, name):
|
||||||
|
"""
|
||||||
|
Returns the module or None, if it fails.
|
||||||
|
"""
|
||||||
|
if path is None and name is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
timestamp, parser = module_cache[path or name]
|
||||||
|
if not path or os.path.getmtime(path) <= timestamp:
|
||||||
|
return parser
|
||||||
|
else:
|
||||||
|
# In case there is already a module cached and this module
|
||||||
|
# has to be reparsed, we also need to invalidate the import
|
||||||
|
# caches.
|
||||||
|
invalidate_star_import_cache(parser.module)
|
||||||
|
return None
|
||||||
|
except KeyError:
|
||||||
|
return load_pickle_module(path or name)
|
||||||
|
|
||||||
|
|
||||||
|
def save_module(path, name, parser):
|
||||||
|
if path is None and name is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
p_time = None if not path else os.path.getmtime(path)
|
||||||
|
module_cache[path or name] = p_time, parser
|
||||||
|
save_pickle_module(path or name)
|
||||||
|
|
||||||
|
|
||||||
|
def load_pickle_module(path):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def save_pickle_module(path):
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user