0Pricing
MCP Academy · レッスン

上流サービスをキャッシュしてレート制限する

モデルからの過剰な呼び出しからバックエンドを保護します。

「上流サービスをキャッシュしてレート制限する」はCoddyKit上の無料MCP Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMCP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MCP Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🎯

よくある質問

「上流サービスをキャッシュしてレート制限する」レッスンは無料ですか?

はい。「上流サービスをキャッシュしてレート制限する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MCP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MCP Academyコースには全4レッスンが含まれています。

「上流サービスをキャッシュしてレート制限する」で何を学びますか?

モデルからの過剰な呼び出しからバックエンドを保護します。 ブラウザで直接実行するハンズオンコードでMCP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

MCP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMCP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「上流サービスをキャッシュしてレート制限する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMCP Academyレッスンでコードを書いて実行できますか?

はい。すべてのMCP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. SQLクエリを安全に公開する
  2. REST APIをツールとしてラップする
  3. Lifespanで接続をプールする
  4. 上流サービスをキャッシュしてレート制限する
← MCP Academyに戻る