Cache¶
arkindex_worker.cache ¶
Database mappings and helper methods for the experimental worker caching feature.
On methods that support caching, the database will be used for all reads, and writes will go both to the Arkindex API and the database, reducing network usage.
Classes¶
JSONField ¶
Bases: Field
A Peewee field that stores a JSON payload as a string and parses it automatically.
Version ¶
Bases: Model
Cache version table, used to warn about incompatible cache databases
when a worker uses an outdated version of base-worker
.
CachedImage ¶
Bases: Model
Cache image table
CachedElement ¶
Bases: Model
Cache element table
Functions¶
open_image ¶
open_image(
*args,
max_width: int | None = None,
max_height: int | None = None,
**kwargs
) -> Image
Open this element’s image as a Pillow image. This does not crop the image to the element’s polygon. IIIF servers with maxWidth, maxHeight or maxArea restrictions on image size are not supported.
Warns:¶
If both, max_width
and max_height
are set, the image ratio is not preserved.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Positional arguments passed to arkindex_worker.image.open_image |
()
|
|
max_width |
int | None
|
The maximum width of the image. |
None
|
max_height |
int | None
|
The maximum height of the image. |
None
|
**kwargs |
Keyword arguments passed to arkindex_worker.image.open_image |
{}
|
Returns:
Type | Description |
---|---|
Image
|
A Pillow image. |
Raises:
Type | Description |
---|---|
ValueError
|
When this element does not have an image ID or a polygon. |
Source code in arkindex_worker/cache.py
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 |
|
CachedTranscription ¶
Bases: Model
Cache transcription table
CachedClassification ¶
Bases: Model
Cache classification table
CachedEntity ¶
Bases: Model
Cache entity table
CachedTranscriptionEntity ¶
Bases: Model
Cache transcription entity table
Functions¶
init_cache_db ¶
init_cache_db(path: Path)
Create the cache database on the given path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
Where the new database should be created |
required |
Source code in arkindex_worker/cache.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
create_tables ¶
create_tables()
Creates the tables in the cache DB only if they do not already exist.
Source code in arkindex_worker/cache.py
300 301 302 303 304 |
|
create_version_table ¶
create_version_table()
Creates the Version table in the cache DB. This step must be independent from other tables creation since we only want to create the table and add the one and only Version entry when the cache is created from scratch.
Source code in arkindex_worker/cache.py
307 308 309 310 311 312 313 314 315 |
|
check_version ¶
check_version(cache_path: str | Path)
Check the validity of the SQLite version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_path |
str | Path
|
Path towards a local SQLite database |
required |
Source code in arkindex_worker/cache.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
merge_parents_cache ¶
merge_parents_cache(paths: list, current_database: Path)
Merge all the potential parent task’s databases into the existing local one
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths |
list
|
Path to cache databases |
required |
current_database |
Path
|
Path to the current database |
required |
Source code in arkindex_worker/cache.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|