pystac.cache#
- class pystac.cache.CollectionCache(cached_ids: Optional[Dict[str, Union[Collection_Type, Dict[str, Any]]]] = None, cached_hrefs: Optional[Dict[str, Union[Collection_Type, Dict[str, Any]]]] = None)[source]#
Cache of collections that can be used to avoid re-reading Collection JSON in
pystac.serialization.merge_common_properties
. The CollectionCache will contain collections as either as dicts or PySTAC Collections, and will set Collection JSON that it reads in order to merge in common properties.
- class pystac.cache.ResolvedObjectCache(id_keys_to_objects: Optional[Dict[str, STACObject_Type]] = None, hrefs_to_objects: Optional[Dict[str, STACObject_Type]] = None, ids_to_collections: Optional[Dict[str, Collection_Type]] = None)[source]#
This class tracks resolved objects tied to root catalogs. A STAC object is ‘resolved’ when it is a Python Object; a link to a STAC object such as a Catalog or Item is considered “unresolved” if it’s target is pointed at an HREF of the object.
Tracking resolved objects allows us to tie together the same instances when there are loops in the Graph of the STAC catalog (e.g. a LabelItem can link to a rel:source, and if that STAC Item exists in the same root catalog they should refer to the same Python object).
Resolution tracking is important when copying STACs in-memory: In order for object links to refer to the copy of STAC Objects rather than their originals, we have to keep track of the resolved STAC Objects and replace them with their copies.
- Parameters
id_keys_to_objects – Existing cache of a key made up of the STACObject and it’s parents IDs mapped to the cached STACObject.
hrefs_to_objects – STAC Object HREFs matched to their cached object.
ids_to_collections – Map of collection IDs to collections.
- as_collection_cache() pystac.cache.CollectionCache [source]#
- cache(obj: STACObject_Type) None [source]#
Set the given object into the cache.
- Parameters
obj – The object to cache
- contains_collection_id(collection_id: str) bool [source]#
Returns True if there is a collection with given collection ID is cached.
- get(obj: STACObject_Type) Optional[STACObject_Type] [source]#
Get the cached object that has the same cache key as the given object.
- Parameters
obj – The given object who’s cache key will be checked against the cache.
- Returns
Either the cached object that has the same cache key as the given object, or None
- Return type
STACObject or None
- get_by_href(href: str) Optional[STACObject_Type] [source]#
Gets the cached object at href.
- Parameters
href – The href to use as the key for the cached object.
- Returns
Returns the STACObject if cached, otherwise None.
- Return type
STACObject or None
- get_collection_by_id(id: str) Optional[Collection_Type] [source]#
Retrieved a cached Collection by its ID.
- Parameters
id – The ID of the collection.
- Returns
- Returns the collection if there is one cached
with the given ID, otherwise None.
- Return type
Collection or None
- get_or_cache(obj: STACObject_Type) STACObject_Type [source]#
Gets the STACObject that is the cached version of the given STACObject; or, if none exists, sets the cached object to the given object.
- Parameters
obj – The given object who’s cache key will be checked against the cache.
- Returns
Either the cached object that has the same cache key as the given object, or the given object.
- Return type
- id_keys_to_objects: Dict[str, STACObject_Type]#
Existing cache of a key made up of the STACObject and it’s parents IDs mapped to the cached STACObject.
- static merge(first: pystac.cache.ResolvedObjectCache, second: pystac.cache.ResolvedObjectCache) pystac.cache.ResolvedObjectCache [source]#
Merges two ResolvedObjectCache.
The merged cache will give preference to the first argument; that is, if there are cached keys that exist in both the first and second cache, the object cached in the first will be cached in the resulting merged ResolvedObjectCache.
- Parameters
first – The first cache to merge. This cache will be the preferred cache for objects in the case of ID conflicts.
second – The second cache to merge.
- Returns
The resulting merged cache.
- Return type
- class pystac.cache.ResolvedObjectCollectionCache(resolved_object_cache: pystac.cache.ResolvedObjectCache, cached_ids: Optional[Dict[str, Union[Collection_Type, Dict[str, Any]]]] = None, cached_hrefs: Optional[Dict[str, Union[Collection_Type, Dict[str, Any]]]] = None)[source]#
- cache(collection: Union[Collection_Type, Dict[str, Any]], href: Optional[str] = None) None [source]#
Caches a collection JSON.
- static merge(resolved_object_cache: pystac.cache.ResolvedObjectCache, first: Optional[pystac.cache.ResolvedObjectCollectionCache], second: Optional[pystac.cache.ResolvedObjectCollectionCache]) pystac.cache.ResolvedObjectCollectionCache [source]#
- resolved_object_cache: pystac.cache.ResolvedObjectCache#