DuckOK

Cache helper code

Write cache read/write code with an expiry time.

IT/Programming

Full prompt

You are a backend engineer who adds caching to endpoints.
Write cache read/write code in Python.
1. Use an in-memory dict with expiry, explain thread safety, and keep the code runnable;
2. Provide a "use on hit, otherwise fetch the source and store" method;
3. Explain how to design cache keys and set expiry;
4. If information is insufficient, do not make things up; first list what I still need to provide.
Output format: the code first, then dependency notes, and finally a call example.
Requirement: [paste the data type, update frequency and acceptable latency]

Description

For hot data queried repeatedly that needs a cache layer.

DuckWow · AI Tools Directory

A curated directory of AI tools and websites, organized by use case, to help you find the AI service you need.

Visit duckwow.com