From 4121b9900e35c0b81d9264824fe71830e8e85dc8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 5 Jun 2023 08:30:00 -0700 Subject: [PATCH] aider: Added cache versioning to `RepoMap` class. # Context: USER: is there a standard way to version these cache files? ASSISTANT: Yes, a standard way to version cache files is to include a version number in the cache file name or within the cache data. This allows you to easily identify and manage different versions of the cache, and update the cache handling logic when needed. Here's how you can implement cache versioning in your `RepoMap` class: 1. Add a constant for the cache version at the beginning of the class. 2. Modify the cache directory names to include the version number. 3. When loading the cache, check if the version matches the current version. If not, clear the cache and start fresh. Here are the changes you need to make in `aider/repomap.py`: ```python aider/repomap.py <<<<<<< ORIGINAL class RepoMap: ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] IDENT_CACHE_DIR = ".aider.ident.cache" TAGS_CACHE_DIR = ".aider.tags.cache" ======= class RepoMap: CACHE_VERSION = 1 ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}" TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}" >>>>>>> UPDATED ``` Now, whenever you need to change the cache format or handling logic, you can simply increment the `CACHE_VERSION` constant, and the cache will be automatically invalidated and recreated with the new version. --- aider/repomap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index ff301fc25..324897a1a 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -60,9 +60,10 @@ def fname_to_components(fname, with_colon): class RepoMap: + CACHE_VERSION = 1 ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"] - IDENT_CACHE_DIR = ".aider.ident.cache" - TAGS_CACHE_DIR = ".aider.tags.cache" + IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}" + TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}" def __init__(self, map_tokens=1024, root=None, main_model="gpt-4", io=None): self.io = io