stac-utils / stac-utils/stac-fastapi

Single Item and Collection entity caching

Open
#377 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

api layer enhancement
Dominant language
Python
Stars
324
Forks
126
Avg merge
1d 22h
Merged PRs (30d)
10

Description

The collection (/collections/{collection_id}) and item (/collections/{collections_id}/items/{item_id} endpoints should be cacheable in most cases.

I tried implementing this in my BaseCoreClient implementation using cachetools, but was unable to actually get it to hit the cache, even when using a class variable for the cache. I don't really understand the internals of fastapi or stac-fastapi, so there's likely something I'm missing.

https://github.com/long2ice/fastapi-cache look like a better option, and supports non-in-memory options.

One complexity here is the Fields Extension, so caching should only occur if the fields parameter is the same.

The cache would need to be integrated with the Transaction Extension client, so that when an item was updated or delete, the cache would be cleared of that item.

One motivating use case of this is the use of a STAC API Item resource URL (e.g., /collections/c1/items/my_item) as the input to a distributed tiler (e.g., titiler), where different instances of the tiler retrieve the same item URL repeatedly. As it is now, these each require a DB retrieval and serialization/transformation, whereas caching them would be fairly straightforward.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the BaseCoreClient implementation and the Transaction Extension client mentioned in the issue, then examine how FastAPI and stac-fastapi handle request and response caching. Done should include cacheable collection and item responses that respect the fields parameter and are cleared when items are updated or deleted.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.