mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
aider: Persist the IDENT_CACHE
to .aider.ident.cache
whenever it is updated.
# Context: USER: persist the `IDENT_CACHE` to .aider.ident.cache whenever it is updated ASSISTANT: To persist the `IDENT_CACHE` to `.aider.ident.cache` whenever it is updated, we need to modify the `get_name_identifiers` method in the `RepoMap` class. Here are the changes: ```python aider/repomap.py <<<<<<< ORIGINAL def get_name_identifiers(self, fname, uniq=True): file_mtime = os.path.getmtime(fname) cache_key = fname if cache_key in self.IDENT_CACHE and self.IDENT_CACHE[cache_key]["mtime"] == file_mtime: idents = self.IDENT_CACHE[cache_key]["data"] else: idents = self.get_name_identifiers_uncached(fname) self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents} ======= import json class RepoMap: # ... IDENT_CACHE_FILE = ".aider.ident.cache" def __init__(self, use_ctags=None, root=None, main_model="gpt-4"): # ... self.load_ident_cache() def load_ident_cache(self): if os.path.exists(self.IDENT_CACHE_FILE): with open(self.IDENT_CACHE_FILE, "r") as f: self.IDENT_CACHE = json.load(f) else: self.IDENT_CACHE = dict() def save_ident_cache(self): with open(self.IDENT_CACHE_FILE, "w") as f: json.dump(self.IDENT_CACHE, f) def get_name_identifiers(self, fname, uniq=True): file_mtime = os.path.getmtime(fname) cache_key = fname if cache_key in self.IDENT_CACHE and self.IDENT_CACHE[cache_key]["mtime"] == file_mtime: idents = self.IDENT_CACHE[cache_key]["data"] else: idents = self.get_name_identifiers_uncached(fname) self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents} self.save_ident_cache() >>>>>>> UPDATED ``` This will load the `IDENT_CACHE` from the `.aider.ident.cache` file when the `RepoMap` class is initialized and save the cache to the file whenever it is updated.
This commit is contained in:
parent
49374d04b5
commit
311fc1d6e1
1 changed files with 22 additions and 0 deletions
|
@ -206,6 +206,27 @@ class RepoMap:
|
|||
return False
|
||||
return True
|
||||
|
||||
import json
|
||||
|
||||
class RepoMap:
|
||||
# ...
|
||||
IDENT_CACHE_FILE = ".aider.ident.cache"
|
||||
|
||||
def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
|
||||
# ...
|
||||
self.load_ident_cache()
|
||||
|
||||
def load_ident_cache(self):
|
||||
if os.path.exists(self.IDENT_CACHE_FILE):
|
||||
with open(self.IDENT_CACHE_FILE, "r") as f:
|
||||
self.IDENT_CACHE = json.load(f)
|
||||
else:
|
||||
self.IDENT_CACHE = dict()
|
||||
|
||||
def save_ident_cache(self):
|
||||
with open(self.IDENT_CACHE_FILE, "w") as f:
|
||||
json.dump(self.IDENT_CACHE, f)
|
||||
|
||||
def get_name_identifiers(self, fname, uniq=True):
|
||||
file_mtime = os.path.getmtime(fname)
|
||||
cache_key = fname
|
||||
|
@ -214,6 +235,7 @@ class RepoMap:
|
|||
else:
|
||||
idents = self.get_name_identifiers_uncached(fname)
|
||||
self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents}
|
||||
self.save_ident_cache()
|
||||
|
||||
if uniq:
|
||||
idents = set(idents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue