How do I use the Anthropic cache?

Anthropic cache allows you to cache parts of a prompt. As explained in their documentation, you need to opt-in within the prompt to start caching parts of it.

To do this, add cacheControl: true to the front matter of your prompt.

---
provider: name-of-your-antropic-provider-in-latitude
model: claude-3-5-sonnet-20241022
cacheControl: true
---

Once this is set up, you can start caching specific parts of the prompt:

<system>This part of the text is not cached</system>
<system>
  Read this large book and answer users' questions.
  <text cache_control={{ { type: 'ephemeral' } }}>
    ...BIG_BOOK_CONTENT...
  </text>
</system>

If you want an entire message to be cached, add the cache directive to the user, assistant, or system tags:

<user cache_control={{ { type: 'ephemeral' } }}>
  This text will be cached.
  <text>
    This text will also be cached.
  </text>
  And this text as well.
</user>