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.
This commit is contained in:
Paul Gauthier 2023-06-05 08:30:00 -07:00
parent baa08e12f8
commit 4121b9900e

View file

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