InvokeAI/invokeai/app/services
psychedelicious 0a09f84b07 feat(backend): selective invalidation for invocation cache
This change enhances the invocation cache logic to delete cache entries when the resources to which they refer are deleted.

For example, a cached output may refer to "some_image.png". If that image is deleted, and this particular cache entry is later retrieved by a node, that node's successors will receive references to the now non-existent "some_image.png". When they attempt to use that image, they will fail.

To resolve this, we need to invalidate the cache when the resources to which it refers are deleted. Two options:
- Invalidate the whole cache on every image/latents/etc delete
- Selectively invalidate cache entries when their resources are deleted

Node outputs can be any shape, with any number of resource references in arbitrarily nested pydantic models. Traversing that structure to identify resources is not trivial.

But invalidating the whole cache is a bit heavy-handed. It would be nice to be more selective.

Simple solution:
- Invocation outputs' resource references are always string identifiers - like the image's or latents' name
- Invocation outputs can be stringified, which includes said identifiers
- When the invocation is cached, we store the stringified output alongside the "live" output classes
- When a resource is deleted, pass its identifier to the cache service, which can then invalidate any cache entries that refer to it

The images and latents storage services have been outfitted with `on_deleted()` callbacks, and the cache service registers itself to handle those events. This logic was copied from `ItemStorageABC`.

`on_changed()` callback are also added to the images and latents services, though these are not currently used. Just following the existing pattern.
2023-09-20 18:26:47 +10:00
..
config feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
invocation_cache feat(backend): selective invalidation for invocation cache 2023-09-20 18:26:47 +10:00
models isort wip 2023-09-12 13:01:58 -04:00
session_processor feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
session_queue feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
shared feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
__init__.py all files migrated; tweaks needed 2023-03-03 00:02:15 -05:00
board_image_record_storage.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
board_images.py isort wip 2023-09-12 13:01:58 -04:00
board_record_storage.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
boards.py isort wip 2023-09-12 13:01:58 -04:00
default_graphs.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
events.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
graph.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
image_file_storage.py fix(nodes): fix uploading image metadata retention 2023-08-30 14:52:50 +10:00
image_record_storage.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
images.py feat(backend): selective invalidation for invocation cache 2023-09-20 18:26:47 +10:00
invocation_queue.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
invocation_services.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
invocation_stats.py isort wip 2023-09-12 13:01:58 -04:00
invoker.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
item_storage.py Apply black 2023-07-27 10:54:01 -04:00
latent_storage.py feat(backend): selective invalidation for invocation cache 2023-09-20 18:26:47 +10:00
model_manager_service.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
processor.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
resource_name.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
sqlite.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
thread.py feat: queued generation (#4502) 2023-09-20 15:09:24 +10:00
urls.py feat: add multi-select to gallery 2023-08-03 11:46:59 +10:00