#Astro content loader, config persistence

11 messages · Page 1 of 1 (latest)

sinful prairie
#

looking into Astro's content loader API for retrieving AT Protocol records from a given repository (like Bluesky posts).

the loader is provided a KV store for the actual content, but is there no KV store for loader config? I need to store the repository revision so it doesn't have to refetch the entire repository from scratch.

modest notchBOT
#

Hi @sinful prairie. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro’s content loader API provides a KV store called the DataStore for storing and retrieving the actual content entries of a collection. However, for storing loader-specific configuration or metadata—such as a repository revision to avoid refetching everything—Astro provides a separate key-value store called meta, available as the meta property on the LoaderContext object passed to your loader’s load() method.

You can use meta to persist values like sync tokens, last-modified times, or repository revisions between builds. This metadata is scoped to the collection and is persisted alongside the collection data, but is only available inside the loader:

const lastRevision = meta.get("lastRevision");
// ... fetch new data if needed ...
meta.set("lastRevision", newRevision);

This allows you to store and retrieve the repository revision (or any other loader-specific state) without having to refetch the entire repository each time the loader runs. The meta store is designed exactly for this use case and is documented in the Astro Content Loader API reference LoaderContext and MetaStore sections.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@sinful prairie Kapa.ai is still learning and improving, please let me know how I did by reacting below.

sinful prairie
#

@modest notch does Astro have a mechanism/command to clear that meta store?

modest notchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I'm sorry, but the knowledge sources do not explicitly mention any Astro mechanism or CLI command to clear the meta store used by the content loader API. The documentation describes how to use the meta store within a loader to get and set metadata, but does not provide information about clearing or resetting it outside of the loader context LoaderContext.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@sinful prairie Kapa.ai is still learning and improving, please let me know how I did by reacting below.

sinful prairie
#

@modest notch what about a command for resetting/clearing all data from content loaders? not just the meta store

modest notchBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Astro does not provide a dedicated CLI command specifically for resetting or clearing all data from content loaders (including both the content and the meta store) according to the available documentation. However, you can force a full rebuild of the content layer—which will clear the content layer cache—by using the --force flag with commands like astro dev or astro build:

astro dev --force

This flag is documented as clearing the content layer cache, which would trigger a full reload of your content collections and their loaders. While the documentation does not explicitly state that this also clears the meta store, it is the closest mechanism described for resetting loader data Common flags.

If you need more granular control (such as clearing only the meta store), the documentation does not mention a built-in command for that purpose.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: