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_size=None, **kwargs)
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Positional arguments passed to arkindex_worker.image.open_image |
()
|
|
max_size |
Optional[int]
|
Subresolution 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
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 |
|
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)
Create the cache database on the given path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Where the new database should be created |
required |
Source code in arkindex_worker/cache.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
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
270 271 272 273 274 |
|
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
277 278 279 280 281 282 283 284 285 |
|
check_version ¶
check_version(cache_path)
Check the validity of the SQLite version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_path |
Union[str, Path]
|
Path towards a local SQLite database |
required |
Source code in arkindex_worker/cache.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
retrieve_parents_cache_path ¶
retrieve_parents_cache_path(
parent_ids, data_dir="/data", chunk=None
)
Retrieve the path of the given parent’s in the
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_ids |
list
|
List of element IDs to search |
required |
data_dir |
str
|
Base folder where to look for |
'/data'
|
chunk |
int
|
Index of the chunk of the db that might contain the paths |
None
|
Returns:
Type | Description |
---|---|
list
|
The corresponding list of paths |
Source code in arkindex_worker/cache.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
merge_parents_cache ¶
merge_parents_cache(paths, current_database)
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 |
str
|
Path to the current database |
required |
Source code in arkindex_worker/cache.py
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 377 378 |
|