Skip to content

Commit

Permalink
add table map endpoint and l2 cache check
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesem committed Jan 16, 2024
1 parent 1e4fbbc commit 683fc0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions caveclient/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
l2cache_endpoints_v1 = {
"l2cache_data": l2cache_v1 + "/table/{table_id}/attributes",
"l2cache_meta": l2cache_v1 + "/attribute_metadata",
"l2cache_table_mapping": l2cache_v1 + "/table_mapping",
}

l2cache_api_versions = {1: l2cache_endpoints_v1}
Expand Down
36 changes: 36 additions & 0 deletions caveclient/l2cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
from .auth import AuthClient
import json
from urllib.parse import urlparse

server_key = "l2cache_server_address"

Expand Down Expand Up @@ -135,6 +136,41 @@ def attributes(self):
self._available_attributes = list(self.cache_metadata().keys())
return self._available_attributes

def table_mapping(self):
"""Retrieves table mappings for l2 cache.
Parameters
----------
Returns
-------
dict
keys are pcg table names, values are dicts with fields `l2cache_id` and `cv_path`.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["l2cache_table_mapping"].format_map(endpoint_mapping)
response = self.session.get(url)
return handle_response(response)

def has_cache(self, datastack_name=None):
"""Checks if the l2 cache is available for the dataset
Parameters
----------
datastack_name : str, optional
The name of the datastack to check, by default None (if None, uses the client's datastack)
Returns
-------
bool
True if the l2 cache is available, False otherwise
"""
seg_source = self.fc.info.segmentation_source(datastack_name=datastack_name)
if urlparse(seg_source).scheme != "graphene":
return False
table_name = self.fc.chunkedgraph.table_name
table_mapping = self.table_mapping()
return table_name in table_mapping


client_mapping = {
1: L2CacheClientLegacy,
Expand Down

0 comments on commit 683fc0a

Please sign in to comment.