From 0288f5b28aba37109967a1f4f622e5fa249f4cc2 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 23 Oct 2011 23:22:54 +0200 Subject: [PATCH] [entropy.core] cache parser outcome whenever it's possible --- lib/entropy/core/settings/base.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/entropy/core/settings/base.py b/lib/entropy/core/settings/base.py index 804196e33..933079d41 100644 --- a/lib/entropy/core/settings/base.py +++ b/lib/entropy/core/settings/base.py @@ -116,6 +116,7 @@ class SystemSettings(Singleton, EntropyPluginStore): self.__setting_files = {} self.__setting_dirs = {} self.__mtime_files = {} + self.__mtime_cache = {} self.__persistent_settings = { 'pkg_masking_reasons': etpConst['pkg_masking_reasons'].copy(), 'pkg_masking_reference': etpConst['pkg_masking_reference'].copy(), @@ -1607,11 +1608,28 @@ class SystemSettings(Singleton, EntropyPluginStore): @return: raw text extracted from file @rtype: list """ + root = etpConst['systemroot'] + try: + mtime = os.path.getmtime(filepath) + except (OSError, IOError): + mtime = 0.0 + + cache_key = (root, filepath) + cache_obj = self.__mtime_cache.get(cache_key) + if cache_obj is not None: + if cache_obj['mtime'] == mtime: + return cache_obj['data'] + + cache_obj = {'mtime': mtime,} + lines = entropy.tools.generic_file_content_parser(filepath, comment_tag = comment_tag) # filter out non-ASCII lines lines = [x for x in lines if entropy.tools.is_valid_ascii(x)] - return SystemSettings.CachingList(lines) + data = SystemSettings.CachingList(lines) + cache_obj['data'] = data + self.__mtime_cache[cache_key] = cache_obj + return data def __remove_repo_cache(self, repoid = None): """