MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _dump_resource

Method _dump_resource

src/commoncode/resource.py:920–933  ·  view source on GitHub ↗

Dump a Resource to the disk cache.

(self, resource)

Source from the content-addressed store, hash-verified

918 self.resources_by_path[path] = resource
919
920 def _dump_resource(self, resource):
921 """
922 Dump a Resource to the disk cache.
923 """
924 cache_location = resource.cache_location
925
926 if not cache_location:
927 raise TypeError(
928 f"Resource cannot be dumped to disk and is used onlyin memory: {resource}"
929 )
930
931 # TODO: consider messagepack or protobuf for compact/faster processing?
932 with open(cache_location, "w") as cached:
933 cached.write(json.dumps(resource.serialize(), check_circular=False))
934
935 # TODO: consider adding a small LRU cache in front of this for perf?
936 def _load_resource(self, path):

Callers 1

save_resourceMethod · 0.95

Calls 3

serializeMethod · 0.80
writeMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected