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=None, max_height=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.
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 |
Optional[int]
|
The maximum width of the image. |
None
|
max_height |
Optional[int]
|
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
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 |
|
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 |
Path
|
Where the new database should be created |
required |
Source code in arkindex_worker/cache.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
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
279 280 281 282 283 |
|
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
286 287 288 289 290 291 292 293 294 |
|
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
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
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 |
Path
|
Path to the current database |
required |
Source code in arkindex_worker/cache.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|