add model update and delete

This commit is contained in:
Dinesh Yeduguru 2024-11-13 15:30:17 -08:00
parent 4253cfcd7f
commit 4b1b196251
6 changed files with 356 additions and 49 deletions

View file

@ -36,6 +36,8 @@ class DistributionRegistry(Protocol):
# The current approach could lead to inconsistencies if the same logical object has different data across providers.
async def register(self, obj: RoutableObjectWithProvider) -> bool: ...
async def delete(self, type: str, identifier: str) -> None: ...
REGISTER_PREFIX = "distributions:registry"
KEY_VERSION = "v1"
@ -120,6 +122,9 @@ class DiskDistributionRegistry(DistributionRegistry):
)
return True
async def delete(self, type: str, identifier: str) -> None:
await self.kvstore.delete(KEY_FORMAT.format(type=type, identifier=identifier))
class CachedDiskDistributionRegistry(DiskDistributionRegistry):
def __init__(self, kvstore: KVStore):
@ -206,6 +211,13 @@ class CachedDiskDistributionRegistry(DiskDistributionRegistry):
return success
async def delete(self, type: str, identifier: str) -> None:
await super().delete(type, identifier)
cache_key = (type, identifier)
async with self._locked_cache() as cache:
if cache_key in cache:
del cache[cache_key]
async def create_dist_registry(
metadata_store: Optional[KVStoreConfig],