cd /news/ai-tools/cache-repeated-answers-to-cut-llm-ca… · home › topics › ai-tools › article
[ARTICLE · art-170017] src=ainexusdaily.vercel.app ↗ pub= topic=ai-tools verified=true sentiment=· neutral

Cache Repeated Answers to Cut LLM Calls in a Small-Business FAQ Bot (Python + SQLite)

A Dev.to tutorial by Ujjwal Dubey, who discloses he co-founded the automation agency NxFlowAI, shows how a small business FAQ bot can cache repeated answers in a SQLite table keyed by a SHA-256 hash of the normalized question, cutting redundant LLM calls. The code refreshes entries after MAX_AGE of 7 days (7 * 24 * 3600 seconds) so answers do not go stale, increments a hits counter on each cache hit, and returns a "cache" or "model" label so operators can log what the cache saves. The tutorial warns never to cache answers containing a customer's name, order or account details, and to clear the table whenever prices, hours or policies change.

read2 min views1 publishedNov 15, 2026
Cache Repeated Answers to Cut LLM Calls in a Small-Business FAQ Bot (Python + SQLite)
Image: Ainexusdaily (auto-discovered)

Small businesses get the same ten questions all day: opening hours, delivery areas, how to book. Sending each one to a language model is wasted money. A small cache is one of the simplest ways to control AI automation costs for a small business. import hashlib, re, sqlite3, time db = sqlite3.connec

t("answers.db") db.execute("""CREATE TABLE IF NOT EXISTS cache( key TEXT PRIMARY KEY, question TEXT, answer TEXT, created REAL, hits INTEGER DEFAULT 0)""") def normalise(q: str) -> str: q = q.lower() q = re.sub(r"[^a-z0-9 ]+", " ", q) return " ".join(q.split()) def key(q: str) -> str: return hashlib.sha256(normalise(q).encode()).hexdigest() MAX_AGE = 7 * 24 * 3600 # refresh weekly so answers do not go stale def answer(q, call_model): k = key(q) row = db.execute("SELECT answer, created FROM cache WHERE key=?", (k,)).fetchone() if row and time.time() - row[1] < MAX_AGE: db.execute("UPDATE cache SET hits = hits + 1 WHERE key=?", (k,)) db.commit() return row[0], "cache" a = call_model(q) db.execute("REPLACE INTO cache(key, question, answer, created) VALUES (?,?,?,?)", (k, q, a, time.time())) db.commit() return a, "model" Cache only general questions. Never cache answers that include a customer's name, order or account details. Expire entries when prices, hours or policies change (clear the table on any website update). Log cache versus model so you can see what the cache actually saves.

Exact matching catches more than you expect once text is normalised. Fuzzy or embedding matching adds complexity; measure first. Why we often prefer small custom pieces like this over packaged bots: why small custom pieces often beat packaged bots. Disclosure: I co-founded NxFlowAI, an automation agency.

Key Takeaways #

  • •Never cache answers that include a customer's name, order or account details.
  • •This story was reported by Dev.to , covering developments in thedev space.
  • •AI advancements continue to reshape industries — read the full article on Dev.to for complete coverage.

📖 Continue reading the full article:

Read Full Article on Dev.to →

── more in #ai-tools 4 stories · sorted by recency
── more on @dev.to 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/cache-repeated-answe…] indexed:0 read:2min 2026-11-15 · —