platform-cache

Use when designing or reviewing Salesforce Platform Cache usage in Apex, including org cache versus session cache, cache-aside patterns, invalidation, and safe key design. Triggers: 'Platform Cache', 'Cache.Org', 'Cache.Session', 'cache-aside', 'cache invalidation'. NOT for durable configuration storage or for caching user-specific sensitive data.

Best use case

platform-cache is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Use when designing or reviewing Salesforce Platform Cache usage in Apex, including org cache versus session cache, cache-aside patterns, invalidation, and safe key design. Triggers: 'Platform Cache', 'Cache.Org', 'Cache.Session', 'cache-aside', 'cache invalidation'. NOT for durable configuration storage or for caching user-specific sensitive data.

Teams using platform-cache should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/platform-cache/SKILL.md --create-dirs "https://raw.githubusercontent.com/PranavNagrecha/AwesomeSalesforceSkills/main/skills/apex/platform-cache/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/platform-cache/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How platform-cache Compares

Feature / Agentplatform-cacheStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Use when designing or reviewing Salesforce Platform Cache usage in Apex, including org cache versus session cache, cache-aside patterns, invalidation, and safe key design. Triggers: 'Platform Cache', 'Cache.Org', 'Cache.Session', 'cache-aside', 'cache invalidation'. NOT for durable configuration storage or for caching user-specific sensitive data.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

Use this skill when query load or repeated reference-data lookup is the real bottleneck and Platform Cache is under consideration. The goal is to choose the right cache scope, treat cache contents as disposable, and design fallback and invalidation behavior so the system remains correct even when the cache is empty or evicted.

## Before Starting

- Is the data org-wide reference data, session-scoped user context, or only transaction-local and better handled in-memory?
- What happens if the cache misses or is evicted early?
- How will cached values be invalidated when source configuration or data changes?

## Core Concepts

### Platform Cache Is For Recomputable Data

Cached values should be safe to lose. Platform Cache improves performance, but it is not durable storage. Design every cache read with a fallback path back to SOQL, metadata, or an external system of record.

### Org Cache And Session Cache Solve Different Problems

Org cache is shared and appropriate for non-sensitive reference data used broadly across users. Session cache is better for per-user, per-session context that is safe to keep transiently. Transaction-local caching is a separate concern and is often just an in-memory Apex pattern rather than Platform Cache at all.

### Cache Keys Need Intentional Namespacing

Without a clear key convention, collisions and accidental overwrite become operational bugs. Keys should encode enough context to distinguish object, use case, locale, or other relevant dimensions.

### Invalidation Is Part Of The Feature

Cache-aside without invalidation becomes stale-data-as-a-service. Invalidation can be explicit on config change, version-key based, or tied to scheduled refresh logic, but it must exist.

## Common Patterns

### Cache-Aside Wrapper

**When to use:** Reference data is expensive to load repeatedly but safe to recompute.

**How it works:** Read from cache first, fall back to source of truth on miss, then repopulate the cache.

**Why not the alternative:** Sprinkling direct cache calls across many services makes invalidation chaotic.

### Org Cache For Shared Reference Data

**When to use:** Many users need the same slow-changing data such as picklist mappings or integration config derivatives.

**How it works:** Use a wrapper around `Cache.Org` with a namespaced key and TTL.

### Session Cache For Non-Sensitive User Context

**When to use:** Session-specific derived data helps reduce repeated work for one user.

**How it works:** Use `Cache.Session` only when session context exists and the data is safe for transient user-level storage.

## Decision Guidance

| Situation | Recommended Approach | Reason |
|---|---|---|
| Shared reference data used by many users | Org cache | Reuse across sessions and users |
| Per-user non-sensitive session context | Session cache | Scoped to the user session |
| Data must survive eviction or act as a source of truth | Do not rely on Platform Cache | Cache is an optimization, not storage |
| Same-object lookups only within one transaction | Transaction-local in-memory caching | Simpler than Platform Cache |


## Recommended Workflow

Step-by-step instructions for an AI agent or practitioner activating this skill:

1. Gather context — confirm the org edition, relevant objects, and current configuration state
2. Review official sources — check the references in this skill's well-architected.md before making changes
3. Implement or advise — apply the patterns from Core Concepts and Common Patterns sections above
4. Validate — run the skill's checker script and verify against the Review Checklist below
5. Document — record any deviations from standard patterns and update the template if needed

---

## Review Checklist

- [ ] Cached data is safe to recompute and safe to lose.
- [ ] Org cache is not used for user-specific or sensitive data.
- [ ] Cache keys are namespaced and consistent.
- [ ] Fallback behavior on cache miss is correct and tested.
- [ ] Invalidation or versioning strategy is documented.
- [ ] Cache wrappers centralize access instead of scattering raw cache calls.

## Salesforce-Specific Gotchas

1. **Platform Cache is not durable storage** — every cache read needs a miss path.
2. **Org cache is shared broadly** — do not place user-specific or sensitive data there.
3. **Session cache is not the same thing as async-safe state** — background jobs generally should not depend on session-scoped cache behavior.
4. **A cache hit can hide stale-data bugs** — invalidation strategy matters as much as the cache call itself.

## Output Artifacts

| Artifact | Description |
|---|---|
| Cache design review | Findings on scope choice, key design, eviction safety, and invalidation |
| Cache decision table | Recommendation for org cache, session cache, or no Platform Cache |
| Cache-aside scaffold | Wrapper pattern with key namespacing and fallback behavior |

## Related Skills

- `apex/apex-cpu-and-heap-optimization` — use when the issue is CPU or heap waste inside the transaction, not repeated data access across transactions.
- `apex/governor-limits` — use when the broader problem is query and transaction budgeting.
- `apex/custom-metadata-in-apex` — use when configuration belongs in metadata rather than in a transient cache.

Related Skills

omnistudio-cache-strategies

8
from PranavNagrecha/AwesomeSalesforceSkills

Configure caching on DataRaptors and Integration Procedures to cut response times, with cache-bust and freshness guarantees. NOT for platform-level org cache.

integration-procedure-cacheable-patterns

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when designing Integration Procedures (IPs) with platform cache to cut latency and callout load. Covers cache key design, TTL selection, per-user vs org-wide partitions, invalidation on data changes, and safe fallback on cache miss/stale. Does NOT cover general IP authoring (see omnistudio-error-handling-patterns) or LWC client-side caching.

platform-events-integration

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when publishing Platform Events from external systems via REST API, subscribing to Platform Events from outside Salesforce via CometD or Pub/Sub API, designing replay ID strategy for durable external consumers, or handling high-volume event delivery guarantees. Trigger keywords: 'external publish platform event', 'CometD subscribe', 'Pub/Sub API', 'replay ID external', 'durable subscription', 'RetainUntilDate'. NOT for Apex-only event publishing or triggering (use platform-events-apex). NOT for Change Data Capture external subscription (use change-data-capture-integration).

platform-event-schema-evolution

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when modifying the schema of a Platform Event that already has live publishers and subscribers — adding fields, deprecating fields, or splitting events. Triggers: 'add field to platform event without breaking subscribers', 'platform event versioning', 'evolve event schema safely', 'rename a field on a published event'. NOT for initial event design (use integration/platform-events-integration) or for Change Data Capture event schemas.

platform-event-publish-patterns

8
from PranavNagrecha/AwesomeSalesforceSkills

Publishing Platform Events: EventBus.publish, PublishBehavior (PublishImmediately vs PublishAfterCommit), high-volume events, event allocation, publish failures, Change Data Capture comparison. NOT for subscribing/consuming (use platform-event-subscribe-patterns). NOT for CDC architecture (use cdc-patterns).

flow-platform-events-integration

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when Flow is a Platform Event publisher, subscriber, or both. Triggers: 'publish platform event from flow', 'platform-event-triggered flow', 'high-volume platform event', 'publish after commit vs immediate', 'PE subscriber error handling', 'integration fan-out from save'. NOT for Change Data Capture (see integration skills) or for generic async work that does not need pub/sub (see flow/scheduled-flows).

flow-and-platform-events

8
from PranavNagrecha/AwesomeSalesforceSkills

Publish and subscribe to Platform Events from Flow for async decoupling, high-volume triggers, and cross-org signaling. NOT for regular DML-triggered flows.

platform-selection-guidance

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when choosing which Salesforce platform capability to use for a requirement — covering metadata storage (Custom Metadata vs Custom Settings vs Custom Objects), UI framework (LWC vs Aura), integration approach (Platform Events vs Change Data Capture vs Outbound Messaging), and data extension (OmniStudio vs standard automation). Triggers: custom metadata vs custom settings, LWC vs Aura, which salesforce feature to use, platform events vs change data capture, omnistudio vs flow. NOT for automation-specific tool selection between Flow / Apex / Workflow (use admin/process-automation-selection) or for implementing the chosen platform feature.

nonprofit-platform-architecture

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when designing or evaluating the holistic platform architecture for a Nonprofit Cloud (Agentforce Nonprofit) implementation — spanning module selection, data model foundations, integration strategy, and phased adoption across the six independently licensable modules. Trigger keywords: Nonprofit Cloud architecture, NPC platform design, nonprofit Salesforce architecture, program and fundraising architecture, nonprofit data model strategy, Agentforce Nonprofit. NOT for individual feature design within a single module, NPSP configuration, the NPSP-vs-NPC migration decision, or day-to-day admin setup of a specific module.

ai-platform-architecture

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when designing or evaluating the holistic Salesforce AI platform strategy: model tier selection (Salesforce Default vs BYOLLM vs zero-data-retention partner models), Trust Layer design decisions at the architecture level, and multi-agent Supervisor/Specialist orchestration topology. Trigger keywords: AI platform strategy, model selection strategy, Supervisor agent topology, multi-agent orchestration, Einstein LLM gateway, BYOLLM architecture, trust layer design, agentic platform design, model tier decision. NOT for individual agent action development, Trust Layer feature configuration steps, RAG grounding mechanics, or BYOLLM registration procedures (see agentforce/einstein-trust-layer, agentforce/rag-patterns-in-salesforce, agentforce/model-builder-and-byollm for those).

platform-events-apex

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when publishing or subscribing to Salesforce Platform Events from Apex, comparing Platform Events with Change Data Capture, or designing event-triggered error handling and monitoring. Triggers: 'EventBus.publish', 'platform event trigger', 'CDC vs Platform Events', 'replay ID', 'high-volume event'. NOT for Flow-only publish/subscribe automation.

xss-and-injection-prevention

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when writing or reviewing Visualforce pages, Apex controllers, or LWC components that output user-supplied data, build dynamic queries, or construct HTTP responses. Triggers: 'XSS in Visualforce', 'SOQL injection vulnerability', 'how to encode output in Apex', 'JSENCODE Visualforce', 'open redirect prevention'. NOT for Apex CRUD/FLS enforcement (use soql-security or apex-crud-and-fls), NOT for Shield encryption (use shield-encryption-key-management), NOT for AppExchange security review process (use secure-coding-review-checklist).