Skip to content

Use a fetch library for caching #25

@gadomski

Description

@gadomski

Not every STAC-based application will be coupled to a single API. For one example, stac-map is designed to load in arbitrary STAC values (catalogs, collections, items, and item collections), similar to stac-browser. In this case, it's common to navigate back to previously-loaded values, or to pre-fetch values (e.g. a "root" link). In this case, request caching can be a big performance win.

Right now we're doing bare fetch in stac-react:

fetch(url, {
headers: {
'Content-Type': 'application/json',
...options?.headers
}
})
.then(response => {
baseUrl = response.url;
return response;
})
.then(response => response.json())
.then(response => {
const doesPost = response.links.find(({ rel, method }: Link) => rel === 'search' && method === 'POST');
if (doesPost) {
searchMode = SearchMode.POST;
}
})
.then(() => setStacApi(new StacApi(baseUrl, searchMode, options)));
. If we were to switch to using a request library that includes cacheing (TanStack Query is a comonly-used example), we'd make stac-react a more attractive option to downstream applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions