typerdrive Cache modules
typerdrive.cache.attach
Provide a decorator that attaches the typerdrive
cache to a typer
command function.
Attributes
Classes
Functions
attach_cache
Attach the typerdrive
cache to the decorated typer
command function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show
|
bool
|
If set, show the cache after the function runs. |
False
|
Source code in src/typerdrive/cache/attach.py
get_cache_manager
Retrieve the CacheManager
from the TyperdriveContext
.
Source code in src/typerdrive/cache/attach.py
typerdrive.cache.commands
Provide commands that can be added to a typer
app to interact with the cache.
Classes
Functions
add_cache_subcommand
Add all cache
subcommands to the given app.
Source code in src/typerdrive/cache/commands.py
add_clear
add_show
clear
clear(
ctx: Context,
path: Annotated[
str | None,
Option(
help="Clear only the entry matching this path. If not provided, clear the entire cache"
),
] = None,
)
Remove data from the cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Annotated[str | None, Option(help='Clear only the entry matching this path. If not provided, clear the entire cache')]
|
If provided, only remove the data at the given cache key. Otherwise, clear the entire cache. |
None
|
Source code in src/typerdrive/cache/commands.py
show
Show the current cache directory.
typerdrive.cache.exceptions
Provide exceptions specific to the cache feature of typerdrive
.
Classes
CacheClearError
Bases: CacheError
Indicate that there was a problem clearing data from the cache.
Source code in src/typerdrive/cache/exceptions.py
CacheError
Bases: TyperdriveError
The base exception for cache errors.
Source code in src/typerdrive/cache/exceptions.py
CacheInitError
Bases: CacheError
Indicate that there was a problem initializing the cache.
Source code in src/typerdrive/cache/exceptions.py
CacheLoadError
Bases: CacheError
Indicate that there was a problem loading data from the cache.
Source code in src/typerdrive/cache/exceptions.py
CacheStoreError
Bases: CacheError
Indicate that there was a problem storing data in the cache.
Source code in src/typerdrive/cache/exceptions.py
typerdrive.cache.manager
Provide a class for managing the typerdrive
cache feature.
Classes
CacheManager
Manage the typerdrive
cache feature.
Source code in src/typerdrive/cache/manager.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
Attributes
Functions
__init__
clear_all
Removes all data from the cache.
clear_path
Removes data from the cache at the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The cache key where the data should be cleared |
required |
Source code in src/typerdrive/cache/manager.py
list_items
List items at a given path.
Items will be all non-directory entries in the given path.
If the path doesn't exist or is not a directory, an exception will be raised.
Source code in src/typerdrive/cache/manager.py
load_bytes
Load data from the cache at the given key.
If there is no data at the given key, an exception will be raised. If there is an error reading the data, an exception will be raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The cache key where the data should be loaded from |
required |
Source code in src/typerdrive/cache/manager.py
load_json
Load a dictionary from the cache at the given key.
The data at the given key must be json deserializable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The cache key where the dict should be loaded from |
required |
Source code in src/typerdrive/cache/manager.py
load_text
Load text from the cache at the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The cache key where the text should be loaded from |
required |
resolve_path
Resolve a given cache key path to an absolute path within the cache directory.
If the resolved path is outside the cache directory, an exception will be raised. If the resolved path is the same as the cache directory, an exception will be raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The cache key |
required |
mkdir
|
bool
|
If set, create the directory for the cache key if it does not exist. |
False
|
Source code in src/typerdrive/cache/manager.py
store_bytes
Store data at the given cache key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
bytes
|
The data to store in the cache |
required |
path
|
Path | str
|
The cache key where the data should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the cache entry |
None
|
Source code in src/typerdrive/cache/manager.py
store_json
Store a dictionary at the given cache key.
The dictionary must be json serializable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, Any]
|
The dict to store in the cache |
required |
path
|
Path | str
|
The cache key where the dict should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the cache entry |
None
|
Source code in src/typerdrive/cache/manager.py
store_text
Store text at the given cache key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text to store in the cache |
required |
path
|
Path | str
|
The cache key where the text should be stored |
required |
mode
|
int | None
|
The file mode to use when creating the cache entry |
None
|