From bcd6257c90cbcd41fa63d1131712f9009de44c1c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 17 Aug 2024 06:30:46 -0700 Subject: [PATCH] feat: Add last_map attribute and implement caching logic based on refresh mode --- aider/repomap.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/aider/repomap.py b/aider/repomap.py index 5b260f057..175c42600 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -67,6 +67,7 @@ class RepoMap: self.tree_context_cache = {} self.map_cache = {} self.map_processing_time = 0 + self.last_map = None def token_count(self, text): len_text = len(text) @@ -419,8 +420,18 @@ class RepoMap: max_map_tokens, ) + if self.refresh == "manual" and self.last_map: + return self.last_map + + if self.refresh == "always": + use_cache = False + elif self.refresh == "files": + use_cache = True + elif self.refresh == "auto": + use_cache = (self.map_processing_time > 1.0) + # Check if the result is in the cache - if cache_key in self.map_cache: + if use_cache and cache_key in self.map_cache: return self.map_cache[cache_key] # If not in cache, generate the map @@ -433,6 +444,7 @@ class RepoMap: # Store the result in the cache self.map_cache[cache_key] = result + self.last_map = result return result