caching-management

caching-management is a cursor rule for Cursor from hhx465453939/mcp-pubmed-server. It costs 0 tokens per session (1,364 once invoked), scanned A, original, Apache-2.0.

A set of rules for storing frequently used data in memory and in JSON files, with expiry times and a size limit.

In plain words
What is it for?
Use it when building an application that repeatedly fetches papers or other data and needs temporary storage for those results.
Why use it?
It helps avoid repeating slow or expensive work by reusing recent results while removing old or excess entries.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when building an application that repeatedly fetches papers or other data and needs temporary storage for those results.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/hhx465453939/mcp-pubmed-server/caching-management
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/hhx465453939/mcp-pubmed-server

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for caching-management

README.md
[![agentmods](https://agentmods.dev/badge/rules/hhx465453939/mcp-pubmed-server/caching-management/github.svg)](https://agentmods.dev/rules/hhx465453939/mcp-pubmed-server/caching-management)
Your own site
<a href="https://agentmods.dev/rules/hhx465453939/mcp-pubmed-server/caching-management"><img src="https://agentmods.dev/badge/rules/hhx465453939/mcp-pubmed-server/caching-management/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for caching-management

Your own site · 80×15
<a href="https://agentmods.dev/rules/hhx465453939/mcp-pubmed-server/caching-management"><img src="https://agentmods.dev/badge/rules/hhx465453939/mcp-pubmed-server/caching-management.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,364 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01364
Opus 5 $0.00000 $0.00682
Sonnet 5 $0.00000 $0.00273
Haiku 4.5 $0.00000 $0.00136

Measured 9d ago against content hash 6a7a1eb9529f, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

caching-management scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/caching-management.mdc · 215 lines

How it starts

The opening of the file, as written. The whole thing — 215 lines — stays where its author put it; the contents beside it link to each section on GitHub.

缓存管理规范

双层缓存架构

1. 内存缓存 (Map对象)

// 内存缓存配置
this.cache = new Map();
this.cacheTimeout = 5 * 60 * 1000; // 5分钟过期
this.maxCacheSize = 100; // 最大100个条目

2. 文件缓存 (JSON文件)

// 文件缓存配置
const CACHE_DIR = path.join(process.cwd(), 'cache');
const PAPER_CACHE_DIR = path.join(CACHE_DIR, 'papers');
const PAPER_CACHE_EXPIRY = 30 * 24 * 60 * 60 * 1000; // 30天过期

缓存操作模式

内存缓存操作

// 获取缓存
getFromCache(key) {
    const cached = this.cache.get(key);
    if (cached && Date.now() - cached.timestamp < this.cacheTimeout) {
        this.cacheStats.hits++;
        return cached.data;
    }
    this.cacheStats.misses++;
    return null;
}

// 设置缓存
setCache(key, data) {
    // LRU淘汰策略
    if (this.cache.size >= this.maxCacheSize) {
        const oldestKey = this.cache.keys().next().value;
        this.cache.delete(oldestKey);
        this.cacheStats.evictions++;
    }
    
    this.cache.set(key, {
        data,
        timestamp: Date.now()
    });
    this.cacheStats.sets++;
}

文件缓存操作

// 从文件缓存获取
getPaperFromFileCache(pmid) {
    const cachePath = this.getPaperCachePath(pmid);
    if (!fs.existsSync(cachePath)) {
        this.cacheStats.fileMisses++;
        return null;
    }
    
    const fileContent = fs.readFileSync(cachePath, 'utf8');
    const cachedData = JSON.parse(fileContent);
    
    // 检查过期时间
    if (Date.now() - cachedData.timestamp > PAPER_CACHE_EXPIRY) {
        fs.unlinkSync(cachePath);
        return null;
    }
    
    this.cacheStats.fileHits++;
    return cachedData.data;
}

// 保存到文件缓存
setPaperToFileCache(pmid, data) {
    const cachePath = this.getPaperCachePath(pmid);
    const cacheData = {
        version: CACHE_VERSION,
        pmid: pmid,
        timestamp: Date.now(),
        data: data
    };
    
    fs.writeFileSync(cachePath, JSON.stringify(cacheData, null, 2));
    this.cacheStats.fileSets++;
}

缓存统计和监控

统计数据结构

this.cacheStats = {
    hits: 0,           // 内存缓存命中
    misses: 0,          // 内存缓存未命中
    sets: 0,            // 内存缓存设置
    evictions: 0,       // 内存缓存淘汰
    fileHits: 0,        // 文件缓存命中
    fileMisses: 0,      // 文件缓存未命中
    fileSets: 0         // 文件缓存设置
};

Read the full file on GitHub · 215 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 215 lines · 1,364 tokens per session scan A 6a7a1eb9529f

Subscribe to this mod's changes

caching-management is a cursor rule published in the GitHub repository hhx465453939/mcp-pubmed-server (6 stars, last pushed 6mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,364 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.