Cache
cache
LRU cache for parsed PackageInfo objects.
Avoids redundant analyze_package calls when multiple tools
query the same codebase within a single session.
The cache automatically invalidates entries when the set of .py
files in the package directory changes — including content
modifications (tracked via mtime).
Example::
>>> from axm_ast.core.cache import get_package, clear_cache
>>> pkg = get_package(Path("src/mylib")) # parses on first call
>>> pkg2 = get_package(Path("src/mylib")) # cache hit
>>> pkg is pkg2
True
>>> clear_cache() # reset for re-parsing
PackageCache
Thread-safe cache for PackageInfo and call-site data.
Stores results keyed by resolved absolute path. On cache hit,
the current .py file fingerprint (paths + mtime) is compared
to the fingerprint recorded at parse time — if it differs the
entry is evicted and the package is re-parsed.
Source code in packages/axm-ast/src/axm_ast/core/cache.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
clear()
get(path)
Return cached PackageInfo or parse and cache on miss.
On cache hit the file fingerprint is re-checked; if the set
of .py files changed (addition, deletion, or content
modification) the stale entry is evicted and the package
is re-parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package root directory. |
required |
Returns:
| Type | Description |
|---|---|
PackageInfo
|
Cached or freshly parsed |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is not a directory (from |
Source code in packages/axm-ast/src/axm_ast/core/cache.py
get_calls(path)
Return cached call-sites per module, extracting on first call.
Call-sites share the same invalidation lifecycle as
PackageInfo — when the fingerprint changes, both are
evicted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package root directory. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[CallSite]]
|
Dict mapping dotted module names to their call-sites. |
Source code in packages/axm-ast/src/axm_ast/core/cache.py
clear_cache()
get_calls(path)
Return cached call-sites for path, using the global cache.
Equivalent to extracting calls from every module but avoids re-reading files when the package is already cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package root directory. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[CallSite]]
|
Dict mapping dotted module names to call-site lists. |
Source code in packages/axm-ast/src/axm_ast/core/cache.py
get_package(path)
Return PackageInfo for path, using the global cache.
Equivalent to analyze_package(path) but avoids re-parsing
if the same path was already analyzed in this session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package root directory. |
required |
Returns:
| Type | Description |
|---|---|
PackageInfo
|
Cached or freshly parsed |