Never cache microscope state
This commit is contained in:
parent
6c0017be5a
commit
d9fd00b255
1 changed files with 26 additions and 18 deletions
|
|
@ -298,33 +298,41 @@ class Microscope:
|
||||||
|
|
||||||
def force_get_metadata(self):
|
def force_get_metadata(self):
|
||||||
"""
|
"""
|
||||||
Microscope system metadata, to be applied to basically all captures
|
Read cachable bits of microscope metadata.
|
||||||
|
Currently ID, settings, and configuration can be cached
|
||||||
"""
|
"""
|
||||||
settings = self.read_settings(full=False)
|
|
||||||
state = self.state
|
|
||||||
configuration = self.configuration
|
|
||||||
system_metadata = {
|
system_metadata = {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
"settings": settings,
|
"settings": self.read_settings(full=False),
|
||||||
"state": state,
|
"configuration": self.get_configuration(),
|
||||||
"configuration": configuration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return system_metadata
|
return system_metadata
|
||||||
|
|
||||||
def get_metadata(self, cache_key=None):
|
def get_metadata(self, cache_key=None):
|
||||||
logging.debug(f"Looking for cache key {cache_key}")
|
"""
|
||||||
|
Read microscope metadata, with partial caching
|
||||||
|
"""
|
||||||
|
metadata = {}
|
||||||
|
|
||||||
|
# Load cached bits of metadata
|
||||||
if cache_key:
|
if cache_key:
|
||||||
cached_metadata = self.metadata_cache.get(cache_key, None)
|
logging.debug(f"Reading cached microscope metadata: {cache_key}")
|
||||||
if cached_metadata:
|
metadata = self.metadata_cache.get(cache_key, None)
|
||||||
logging.debug(f"Reusing cached microscope metadata: {cache_key}")
|
if not metadata:
|
||||||
return cached_metadata
|
logging.debug(f"Building and caching microscope metadata: {cache_key}")
|
||||||
else:
|
metadata = self.force_get_metadata()
|
||||||
full_metadata = self.force_get_metadata()
|
self.metadata_cache[cache_key] = metadata
|
||||||
self.metadata_cache[cache_key] = full_metadata
|
else:
|
||||||
return full_metadata
|
logging.debug(f"Building microscope metadata: {cache_key}")
|
||||||
logging.debug("Generating full microscope metadata")
|
metadata = self.force_get_metadata()
|
||||||
return self.force_get_metadata()
|
|
||||||
|
# Keys that should never be cached
|
||||||
|
metadata.update({
|
||||||
|
"state": self.state,
|
||||||
|
})
|
||||||
|
|
||||||
|
return metadata
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def metadata(self):
|
def metadata(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue