feat: Add last_map attribute and implement caching logic based on refresh mode

This commit is contained in:
Paul Gauthier 2024-08-17 06:30:46 -07:00 committed by Paul Gauthier (aider)
parent 88dc1c63fd
commit bcd6257c90

View file

@ -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