Cache Reference
sqldeps.cache
Caching utilities for SQL dependency extraction.
This module provides functions for caching extraction results to avoid repeatedly processing the same SQL files, which can save API calls, cost, and time.
cleanup_cache(cache_dir=Path(CACHE_DIR))
Clean up cache directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path
|
The cache directory to clean up |
Path(CACHE_DIR)
|
Returns:
| Type | Description |
|---|---|
bool
|
True if cleaned up successfully, False otherwise |
Source code in sqldeps/cache.py
get_cache_path(file_path, cache_dir=CACHE_DIR)
Generate a consistent cache file path based on SQL file content.
Creates a unique cache filename by hashing the SQL file's content. Includes the original filename in the cache name for easier debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the SQL file to be processed |
required |
cache_dir
|
str | Path
|
Directory where cache files will be stored. Defaults to ".sqldeps_cache" |
CACHE_DIR
|
Returns:
| Type | Description |
|---|---|
Path
|
Path object pointing to the cache file location |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the SQL file doesn't exist |
PermissionError
|
If the SQL file can't be read |
Source code in sqldeps/cache.py
load_from_cache(file_path, cache_dir=Path(CACHE_DIR))
Load extraction result from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The original SQL file path |
required |
cache_dir
|
Path
|
The cache directory |
Path(CACHE_DIR)
|
Returns:
| Type | Description |
|---|---|
SQLProfile | None
|
SQLProfile if loaded successfully, None otherwise |
Source code in sqldeps/cache.py
save_to_cache(result, file_path, cache_dir=Path(CACHE_DIR))
Save extraction result to cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
SQLProfile
|
The SQLProfile to save |
required |
file_path
|
Path
|
The original SQL file path |
required |
cache_dir
|
Path
|
The cache directory |
Path(CACHE_DIR)
|
Returns:
| Type | Description |
|---|---|
bool
|
True if saved successfully, False otherwise |