frappe-core-cache

Implement Redis caching with TTL, invalidation, and distributed locking for Frappe.

163|53|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-core-cache-impertio-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: frappe-core-cache
Source: https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package/tree/main/skills/source/core/frappe-core-cache
Command: npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-core-cache-impertio-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents Frappe/ERPNext production issues where Redis caching goes stale, concurrent workers race without locks, or cache keys grow unbounded until they cause memory and performance problems.

Core Features & Use Cases

  • Redis cache reads/writes: Use frappe.cache.set_value() and frappe.cache.get_value() with optional TTL to keep cached data fresh.
  • Generator-based cache misses: Use generator= with get_value() (and the @redis_cache decorator) to avoid repeated expensive queries and reduce stampedes.
  • Targeted invalidation and locking: Use frappe.cache.delete_value(), delete_keys() patterns, frappe.clear_document_cache(), and with frappe.lock() to coordinate concurrent workflows safely.
  • Structured caching: Use Redis hash helpers hset/hget/hgetall/hdel/hexists for grouping related fields under one cache name.

Quick Start

When you need safe Redis caching and distributed locking in a Frappe feature, tell the AI: "Use frappe-core-cache to implement Redis caching with TTL and invalidation for document updates, including a distributed lock to prevent concurrent stampedes."

Frequently Asked Questions about frappe-core-cache

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent stale Frappe cache data when updating documents?

To prevent stale Frappe cache data, apply targeted cache invalidation using frappe.clear_document_cache() and frappe.cache.delete_value() after updates. This removes specific Redis keys, ensuring cached documents remain consistent with database changes.

How does distributed locking work for concurrent Frappe workers?

Distributed locking in Frappe uses 'with frappe.lock()' to restrict critical code sections to one worker at a time. This prevents race conditions and concurrent stampedes by guaranteeing the lock is released safely upon completion.

What is the best way to avoid cache stampedes in Frappe?

The best way to avoid cache stampedes in Frappe is using the generator parameter with frappe.cache.get_value() or the @redis_cache decorator. This automatically populates the cache on a miss, preventing repeated expensive database queries from concurrent requests.

Can I use Redis hashes for structured caching in Frappe?

Yes, you can use Redis hashes for structured caching in Frappe using hset, hget, hgetall, hdel, and hexists helpers. This groups related fields under one cache name, organizing complex data efficiently within a single Redis key.

Why does frappe.get_cached_doc cause shared-reference mutations?

frappe.get_cached_doc can cause shared-reference mutations because it returns a shared cached object. If multiple requests modify this object directly, they mutate the cached instance, leading to inconsistent application data and unpredictable behavior.

Does this Frappe caching approach work across multiple framework versions?

Yes, this Frappe caching and distributed locking approach works across Frappe v14 to v16. It safely applies cache-aside reads, structured Redis hashes, and concurrency control using standard frappe.cache APIs and redis_cache patterns.