Skip to content

Commit 512142e

Browse files
ciaranjCiaran Jessup
andauthored
feat: support cache location overrides (#177) (#178)
Adds support for a new environment variable 'SEMBLE_CACHE_LOCATION'. The value of this variable will be the full path location of the cache folder that semble stores its caches and savings information. This variable takes precedence over and OS defaults and the Arch XDG_CACHE_HOME convention. Co-authored-by: Ciaran Jessup <ciaran.jessup@lokulus.com>
1 parent ea3c918 commit 512142e

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ semble savings --verbose # also show breakdown by call type
402402

403403
Savings are calculated as follows: for each call, semble records the total character count of the unique files containing returned chunks and the character count of the snippets returned. Estimated tokens saved is `(file chars − snippet chars) / 4` (4 chars per token). This is a conservative estimate: the baseline is reading matched files in full, which is how coding agents often explore unfamiliar code.
404404

405-
Stats are stored in the OS cache folder (`~/Library/Caches/semble/` on macOS, `~/.cache/semble/` on Linux, `%LOCALAPPDATA%\semble\Cache\` on Windows).
405+
By default, stats are stored in the OS cache folder (`~/Library/Caches/semble/` on macOS, `~/.cache/semble/` on Linux, `%LOCALAPPDATA%\semble\Cache\` on Windows). To override this location you can supply an environment variable `SEMBLE_CACHE_LOCATION` which should be the full path to the target cache location e.g. 'd:\caches\storemysemblecachehere'.
406406

407407
</details>
408408

src/semble/cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ def _linux_cache_dir(name: str) -> Path:
4949

5050

5151
def resolve_cache_folder() -> Path:
52-
"""Resolves a cache folder, respects XDG_CACHE_HOME."""
52+
"""Resolves a cache folder, respects SEMBLE_CACHE_LOCATION (highest precedence), XDG_CACHE_HOME."""
5353
name = "semble"
54-
if sys.platform == "win32":
54+
if semble_cache_location := os.getenv("SEMBLE_CACHE_LOCATION"):
55+
cache_dir = Path(semble_cache_location)
56+
elif sys.platform == "win32":
5557
cache_dir = _windows_cache_dir(name)
5658
elif sys.platform == "darwin":
5759
cache_dir = _macos_cache_dir(name)

tests/test_cache.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ def test_resolve_cache_folder(platform: str, mock_target: str, expected: Path) -
9393
assert result == expected
9494

9595

96+
def test_resolve_cache_folder_semble_cache_location(tmp_path: Path) -> None:
97+
"""SEMBLE_CACHE_LOCATION takes precedence over all platform-specific helpers."""
98+
custom = tmp_path / "custom_cache"
99+
with patch.dict("os.environ", {"SEMBLE_CACHE_LOCATION": str(custom)}):
100+
result = resolve_cache_folder()
101+
assert result == custom
102+
assert custom.exists()
103+
104+
96105
def test_clear_cache(tmp_path: Path) -> None:
97106
"""clear_cache removes the index directory when it exists and is a no-op otherwise."""
98107
index_path = tmp_path / "index"

0 commit comments

Comments
 (0)