forked from VimPlug/jedi
move module cache to cache.py - centralize all caches there
This commit is contained in:
@@ -38,7 +38,6 @@ class CachedModule(object):
|
|||||||
The base type for all modules, which is not to be confused with
|
The base type for all modules, which is not to be confused with
|
||||||
`parsing.Module`. Caching happens here.
|
`parsing.Module`. Caching happens here.
|
||||||
"""
|
"""
|
||||||
cache = {}
|
|
||||||
|
|
||||||
def __init__(self, path=None, name=None):
|
def __init__(self, path=None, name=None):
|
||||||
self.path = path and os.path.abspath(path)
|
self.path = path and os.path.abspath(path)
|
||||||
@@ -50,7 +49,7 @@ class CachedModule(object):
|
|||||||
""" get the parser lazy """
|
""" get the parser lazy """
|
||||||
if not self._parser:
|
if not self._parser:
|
||||||
try:
|
try:
|
||||||
timestamp, parser = self.cache[self.path or self.name]
|
timestamp, parser = cache.module_cache[self.path or self.name]
|
||||||
if not self.path or os.path.getmtime(self.path) <= timestamp:
|
if not self.path or os.path.getmtime(self.path) <= timestamp:
|
||||||
self._parser = parser
|
self._parser = parser
|
||||||
else:
|
else:
|
||||||
@@ -73,7 +72,7 @@ class CachedModule(object):
|
|||||||
p_time = None if not self.path else os.path.getmtime(self.path)
|
p_time = None if not self.path else os.path.getmtime(self.path)
|
||||||
|
|
||||||
if self.path or self.name:
|
if self.path or self.name:
|
||||||
self.cache[self.path or self.name] = p_time, self._parser
|
cache.module_cache[self.path or self.name] = p_time, self._parser
|
||||||
|
|
||||||
|
|
||||||
class Parser(CachedModule):
|
class Parser(CachedModule):
|
||||||
@@ -104,8 +103,6 @@ class Parser(CachedModule):
|
|||||||
if is_py3k:
|
if is_py3k:
|
||||||
map_types['file object'] = 'import io; return io.TextIOWrapper()'
|
map_types['file object'] = 'import io; return io.TextIOWrapper()'
|
||||||
|
|
||||||
module_cache = {}
|
|
||||||
|
|
||||||
def __init__(self, path=None, name=None, sys_path=None):
|
def __init__(self, path=None, name=None, sys_path=None):
|
||||||
if sys_path is None:
|
if sys_path is None:
|
||||||
sys_path = get_sys_path()
|
sys_path = get_sys_path()
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ time_caches = []
|
|||||||
|
|
||||||
star_import_cache = {}
|
star_import_cache = {}
|
||||||
|
|
||||||
# for fast_parser, should never be deleted
|
# for fast_parser, should not be deleted
|
||||||
parser_cache = {}
|
parser_cache = {}
|
||||||
|
# should also not be deleted
|
||||||
|
module_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def clear_caches(delete_all=False):
|
def clear_caches(delete_all=False):
|
||||||
@@ -38,6 +40,7 @@ def clear_caches(delete_all=False):
|
|||||||
time_caches = []
|
time_caches = []
|
||||||
star_import_cache.clear()
|
star_import_cache.clear()
|
||||||
parser_cache.clear()
|
parser_cache.clear()
|
||||||
|
module_cache.clear()
|
||||||
|
|
||||||
|
|
||||||
def memoize_default(default=None, cache=memoize_caches):
|
def memoize_default(default=None, cache=memoize_caches):
|
||||||
|
|||||||
Reference in New Issue
Block a user