0Pricing
MCP Academy · Aula

Armazenar em cache e limitar a taxa dos serviços upstream

Proteja os back-ends contra chamadas descontroladas do modelo.

Armazenar em cache e limitar a taxa dos serviços upstream é uma aula grátis de MCP Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de MCP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de MCP Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Models Can Hammer Backends

An eager model may call a tool again and again. Without guards, it can overload the database or API behind it. ⚠️

Cache Repeated Reads

A cache stores recent results so an identical request returns instantly instead of hitting the upstream a second time.

Key the Cache by Inputs

Build the cache key from the tool arguments, so the same city or id reuses its stored answer and anything new fetches fresh.

key = ("weather", city)
if key in cache:
    return cache[key]

Give Entries a TTL

Set a time-to-live so cached data expires. Stale answers get refreshed, keeping results both fast and reasonably current.

Cache Only Safe Reads

Cache idempotent reads, never actions with side effects. You would not want a cached write to silently skip a real change.

Rate-Limit the Calls

A rate limit caps how often a tool may run, so a runaway model cannot fire thousands of requests in a burst.

The Token Bucket Idea

A common scheme is the token bucket: each call spends a token, tokens refill over time, and an empty bucket means wait.

Respect Upstream Limits

Match your limit to the API quota. Staying under its quota avoids 429 responses and keeps your access from being throttled.

Back Off on 429

If an upstream replies 429 Too Many Requests, pause and retry later with backoff instead of pounding it harder.

Bound Concurrency

A semaphore limits how many calls hit the backend at once, smoothing spikes so the upstream is never swamped.

sem = asyncio.Semaphore(5)
async with sem:
    ...

Return a Clear Limit Message

When you do throttle, tell the model plainly that it is rate-limited so it can wait or try a different approach.

Quick Check

What kind of result is safe to cache?

Recap: Cache & Limit

You shielded upstreams with a cache plus rate limits and backoff, keeping backends safe from runaway model calls. 🎯

Perguntas Frequentes

A aula “Armazenar em cache e limitar a taxa dos serviços upstream” é grátis?

Sim — o texto completo de “Armazenar em cache e limitar a taxa dos serviços upstream” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de MCP Academy, atualize para CoddyKit PRO. O curso de MCP Academy inclui 4 aulas no total.

O que vou aprender em “Armazenar em cache e limitar a taxa dos serviços upstream”?

Proteja os back-ends contra chamadas descontroladas do modelo. Você pratica MCP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar MCP Academy?

Nenhuma experiência prévia é necessária. MCP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Armazenar em cache e limitar a taxa dos serviços upstream”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de MCP Academy?

Sim. Cada aula de MCP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Expor consultas SQL com segurança
  2. Transformar uma API REST em ferramentas
  3. Agrupar conexões no ciclo de vida
  4. Armazenar em cache e limitar a taxa dos serviços upstream
← Voltar para MCP Academy