Skip to content

Commit f5e251a

Browse files
committed
Add clear cache details
1 parent 95af4f3 commit f5e251a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

CLAUDE.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ result = converter.explores("https://api.cube.dev/v1/meta", "jwt-token")
133133
- `set_config(**kwargs)` - Update configuration options
134134
- `get_config()` - Get current configuration
135135
- `validate_files(file_paths)` - Validate that files can be loaded
136+
- `clear_cache()` - Clear the file loader cache (see File Loader Caching section)
136137

137138
#### Configuration Management
138139
The converter maintains state and can be reconfigured:
@@ -237,6 +238,35 @@ Run `python scripts/generate_docs.py` when:
237238
- Adding or removing classes
238239
- Updating docstrings for clarity
239240

241+
### File Loader Caching Issue
242+
243+
**IMPORTANT**: The file loader (`lkml2cube/parser/loader.py`) uses a global `visited_path` dictionary to track which files have been processed to prevent infinite recursion when resolving includes. This caching mechanism can cause issues in certain scenarios:
244+
245+
#### Common Problems:
246+
1. **Test Failures**: When running multiple tests that load the same files, the cache may prevent files from being reloaded, causing tests to fail with `None` results
247+
2. **Stale Data**: In long-running processes or repeated calls, cached file paths may contain stale data
248+
3. **Development Issues**: When developing and testing, the cache might prevent seeing changes to included files
249+
250+
#### Solutions:
251+
1. **Clear Cache Method**: The `LookMLConverter` class provides a `clear_cache()` method that resets the `visited_path` dictionary
252+
2. **Test Setup**: In tests, always call `visited_path.clear()` or `converter.clear_cache()` before loading files
253+
3. **Fresh State**: For reliable results, clear the cache between different file loading operations
254+
255+
#### Example Usage:
256+
```python
257+
# In tests
258+
from lkml2cube.parser.loader import visited_path
259+
visited_path.clear() # Clear cache before loading
260+
261+
# Or using the converter
262+
converter = LookMLConverter()
263+
converter.clear_cache() # Clear cache before operations
264+
result = converter.cubes("path/to/file.lkml")
265+
```
266+
267+
#### Why This Happens:
268+
The `visited_path` is a module-level global variable that persists between function calls. This is necessary to prevent infinite recursion when files include each other, but can cause unexpected behavior when the same files are loaded multiple times in different contexts.
269+
240270
### Code Review Checklist
241271

242272
Before committing changes:
@@ -245,6 +275,7 @@ Before committing changes:
245275
- [ ] Generated docs reflect the changes
246276
- [ ] Examples in docstrings are accurate
247277
- [ ] Parameter types and descriptions are correct
278+
- [ ] Tests clear the file loader cache when needed
248279

249280
## 🔒 Enforcement Rules
250281

0 commit comments

Comments
 (0)