Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计通过

frappe-core-cachefrappe 核心缓存

Agent Skill

frappe-core-cache 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

636

周安装

26

GitHub Stars

87

下载量

204
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:frappe-core-cache(frappe 核心缓存)
来源仓库:https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package
仓库路径:skills/frappe-core-cache
安装命令:
npx skills add https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package --skill frappe-core-cache
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/openaec-foundation/erpnext_anthropic_claude_development_skill_package --skill frappe-core-cache

简介

用于处理 GitHub 仓库、Issue 和 Pull Request 协作信息。

  • 适合在需要围绕仓库状态或代码变更进行整理时使用。frappe-core-cache 属于前端设计类 Skill,可作为该场景下的辅助能力补充。
  • 可结合来源仓库和原始 README 核验具体用法。
  • 安装前建议确认权限范围和维护状态,避免触发不必要操作。
  • 注意是否会触发联网、命令执行或文件读写,确保安全使用。

SKILL.md

Frappe Cache & Locking

Quick Reference

ActionMethodNotes
Set valuefrappe.cache.set_value(key, val)With optional TTL
Get valuefrappe.cache.get_value(key)Returns None if missing
Get or generatefrappe.cache.get_value(key, generator=fn)Calls fn() on cache miss
Delete valuefrappe.cache.delete_value(key)Single key or list of keys
Delete by patternfrappe.cache.delete_keys(pattern)Wildcard * matching
Hash setfrappe.cache.hset(name, key, val)Redis hash field
Hash getfrappe.cache.hget(name, key)Single hash field
Hash get allfrappe.cache.hgetall(name)Full hash as dict
Hash deletefrappe.cache.hdel(name, key)Remove hash field
Hash existsfrappe.cache.hexists(name, key)Returns bool
Cached documentfrappe.get_cached_doc(dt, dn)Full doc from cache
Clear doc cachefrappe.clear_document_cache(dt, dn)Invalidate cached doc
Decorator cache@redis_cacheAuto-cache function result
Request cachefrappe.local.cachePer-request dict (not Redis)

Decision Tree

What caching pattern do you need?
│
├─ Cache a function result automatically?
│  ├─ Pure function (same args → same result) → @redis_cache
│  └─ Need custom key/TTL → manual get_value/set_value
│
├─ Cache a document?
│  ├─ Read-only access → frappe.get_cached_doc()
│  └─ Need to invalidate → frappe.clear_document_cache()
│
├─ Cache structured data (multiple fields)?
│  └─ Redis hash → hset/hget/hgetall
│
├─ Per-request cache (avoid repeated DB calls in one request)?
│  └─ frappe.local.cache dict
│
├─ Prevent concurrent execution?
│  └─ Distributed lock → frappe.lock("resource_name")
│
└─ Invalidate cache?
   ├─ Single key → delete_value(key)
   ├─ Pattern → delete_keys("prefix*")
   └─ All site cache → frappe.clear_cache()

String Operations

Set and Get

# Set a value (persists until evicted or deleted)
frappe.cache.set_value("exchange_rate_USD", 1.08)

# Set with TTL (expires after N seconds)
frappe.cache.set_value("exchange_rate_USD", 1.08, expires_in_sec=3600)

# Get value (returns None if missing)
rate = frappe.cache.get_value("exchange_rate_USD")

# Get with generator (calls function on cache miss, stores result)
rate = frappe.cache.get_value(
    "exchange_rate_USD",
    generator=lambda: fetch_exchange_rate("USD"),
)

User-Scoped Values

# Store per-user preference
frappe.cache.set_value("dashboard_layout", "compact", user="user@example.com")

# Retrieve for specific user
layout = frappe.cache.get_value("dashboard_layout", user="user@example.com")

Delete

# Single key
frappe.cache.delete_value("exchange_rate_USD")

# Multiple keys
frappe.cache.delete_value(["exchange_rate_USD", "exchange_rate_EUR"])

# Pattern-based deletion (wildcard)
frappe.cache.delete_keys("exchange_rate*")

Hash Operations

Use hashes to group related fields under a single key.

# Set hash fields
frappe.cache.hset("config|notifications", "email_enabled", True)
frappe.cache.hset("config|notifications", "sms_enabled", False)
frappe.cache.hset("config|notifications", "max_retries", 3)

# Get single field
email_on = frappe.cache.hget("config|notifications", "email_enabled")

# Get all fields as dict
config = frappe.cache.hgetall("config|notifications")
# {"email_enabled": True, "sms_enabled": False, "max_retries": 3}

# Delete field
frappe.cache.hdel("config|notifications", "sms_enabled")

# Check existence
exists = frappe.cache.hexists("config|notifications", "email_enabled")

Hash with Generator

# hget with generator — calls function on miss
value = frappe.cache.hget(
    "user|permissions",
    "user@example.com",
    generator=lambda: compute_permissions("user@example.com"),
)

@redis_cache Decorator

Automatically cache function return values based on arguments.

from frappe.utils.caching import redis_cache

@redis_cache
def get_item_price(item_code, price_list):
    """Expensive query — cached automatically."""
    return frappe.db.get_value("Item Price",
        {"item_code": item_code, "price_list": price_list},
        "price_list_rate",
    )

# First call — hits database, stores in Redis
price = get_item_price("ITEM-001", "Standard Selling")

# Second call — returns from cache
price = get_item_price("ITEM-001", "Standard Selling")

# Clear all cached results for this function
get_item_price.clear_cache()

With TTL

@redis_cache(ttl=300)  # expires after 5 minutes
def get_exchange_rate(from_currency, to_currency):
    return fetch_rate_from_api(from_currency, to_currency)

Rules for @redis_cache:

  • ALWAYS ensure arguments are hashable (strings, numbers, tuples). NEVER pass dicts or lists as arguments.
  • ALWAYS call .clear_cache() when underlying data changes.
  • NEVER use on functions with side effects — the function will NOT execute on cache hits.

frappe.local.cache: Request-Scoped Cache

frappe.local.cache is a plain Python dict that lives for the duration of a single HTTP request. It is NOT stored in Redis.

def get_user_settings():
    """Avoid repeated DB calls within a single request."""
    if "user_settings" not in frappe.local.cache:
        frappe.local.cache["user_settings"] = frappe.get_doc(
            "User Settings", frappe.session.user
        )
    return frappe.local.cache["user_settings"]

Use frappe.local.cache when:

  • The same data is needed multiple times in one request
  • The data does NOT need to persist across requests
  • You want zero Redis overhead

Document Caching

# Get cached document (read-only, no permission check)
settings = frappe.get_cached_doc("System Settings")
item = frappe.get_cached_doc("Item", "ITEM-001")

# Invalidate when document changes
frappe.clear_document_cache("Item", "ITEM-001")

# Cached single value
val = frappe.db.get_value("Item", "ITEM-001", "item_name", cache=True)

NEVER modify a document returned by frappe.get_cached_doc() — it returns a shared reference. Modifications corrupt the cache for all subsequent reads.


Distributed Locking

Prevent concurrent execution of critical sections using Redis-based locks.

# Context manager (recommended)
with frappe.lock("process_payroll"):
    # Only one worker executes this block at a time
    process_all_salary_slips()
    # Lock auto-released on exit

# Manual lock/unlock
frappe.lock("inventory_sync")
try:
    sync_inventory()
finally:
    frappe.unlock("inventory_sync")  # ALWAYS unlock in finally

Rules:

  • ALWAYS use with frappe.lock() (context manager) to guarantee release.
  • NEVER hold locks for more than a few seconds — long locks cause worker starvation.
  • ALWAYS use descriptive lock names to avoid collisions.

Cache Invalidation Patterns

Pattern 1: TTL-Based (Time-to-Live)

frappe.cache.set_value("dashboard_stats", compute_stats(), expires_in_sec=300)

Best for: Data that can be slightly stale (exchange rates, dashboard aggregates).

Pattern 2: Event-Based Invalidation

# In hooks.py
doc_events = {
    "Item Price": {
        "on_update": "my_app.cache.invalidate_price_cache",
        "on_trash": "my_app.cache.invalidate_price_cache",
    }
}

# In my_app/cache.py
def invalidate_price_cache(doc, method):
    frappe.cache.delete_keys("item_price*")
    # Or clear specific function cache:
    # get_item_price.clear_cache()

Best for: Data that MUST be fresh immediately after changes.

Pattern 3: Hybrid (TTL + Event)

@redis_cache(ttl=600)
def get_pricing_rules():
    return frappe.get_all("Pricing Rule", fields=["*"])

# Event hook clears cache immediately on change
def on_pricing_rule_update(doc, method):
    get_pricing_rules.clear_cache()

Best for: Frequently read data with occasional updates.


Common Cache Keys (Internal)

Key PatternContent
doctype::meta::{dt}DocType metadata
user_permissions::{user}User permission cache
bootinfo::{user}User boot info
notifications::{user}Notification counts
document_cache::{dt}::{dn}Cached document

NEVER write to internal cache keys directly. ALWAYS use the documented API methods (get_cached_doc, clear_document_cache, etc.).


Performance Guidelines

  1. ALWAYS set TTL on cached values that derive from external data — without TTL, stale data persists until manual invalidation or Redis eviction.
  2. NEVER cache large objects (>1 MB) — Redis uses pickle serialization, and large values increase serialization overhead and memory usage.
  3. ALWAYS use frappe.local.cache for data needed multiple times within a single request — it avoids Redis round-trips entirely.
  4. NEVER use frappe.clear_cache() as a routine invalidation strategy — it clears ALL cache keys for the site, causing a cold-cache performance hit.
  5. ALWAYS prefix custom cache keys with your app name (e.g., myapp|exchange_rate) to avoid collisions with Frappe internals.

Redis Configuration

Default config: {bench}/config/redis_cache.conf

SettingDefaultDescription
Port13000Redis cache port
Bind127.0.0.1Listen address
maxmemory-policyallkeys-lruEviction policy
maxmemory256mbMax memory (adjustable)

Key Namespacing

All cache keys are automatically prefixed by Frappe with the site name:

# You write:
frappe.cache.set_value("my_key", "value")

# Redis stores:
# "mysite.localhost|my_key"

frappe.cache.make_key(key, user, shared) handles prefixing. The shared=True parameter removes the site prefix for cross-site keys (rare use case).


Version Differences

Featurev14v15v16
frappe.cache.set_valueAvailableAvailableAvailable
@redis_cacheNot availableAvailableAvailable
@redis_cache(ttl=)Not availableAvailableAvailable
frappe.lock context mgrAvailableAvailableAvailable
frappe.local.cacheAvailableAvailableAvailable
hget with generatorAvailableAvailableAvailable

See Also

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.99%
按下载量换算77

Claude

29.77%
按下载量换算61

Cursor

19.31%
按下载量换算39

Gemini CLI

10.87%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills