Platform Cache
By the end of this lesson, you'll be able to:
- Explain what Platform Cache is and the problem it solves
- Distinguish org cache from session cache
- Identify a realistic candidate for caching from an earlier project module
Prerequisites: "Big Objects: Storing Massive Data Volumes"
The problem: re-querying data that barely changes
Module 43's OverdraftPolicyFactory decision might depend on org-wide configuration — say, the current overdraft limit for Business accounts — stored in a Custom Setting (Module 29) or Custom Metadata Type. Querying that same, rarely-changing configuration value on every single transaction is technically correct but wasteful, especially at the scale Lesson 1's Big Objects discussion implied.
Org cache versus session cache
Cache.OrgPartition orgPart = Cache.Org.getPartition('local.BankingConfig');
Decimal limit = (Decimal) orgPart.get('businessOverdraftLimit');
if (limit == null) {
limit = [SELECT Business_Overdraft_Limit__c FROM Banking_Config__mdt LIMIT 1].Business_Overdraft_Limit__c;
orgPart.put('businessOverdraftLimit', limit, 3600); // cache for 1 hour
}
Org cache is shared across every user and session — ideal for org-wide configuration like this overdraft limit. Session cache is scoped to a single user's session — better suited to per-user data that shouldn't leak between different users, like a user's current in-progress wizard state.
Caching is an optimization, applied deliberately
Not every query is worth caching — Module 42's per-transaction Balance__c lookups genuinely need fresh data every time, since a stale cached balance would be a real bug in a banking system. Platform Cache earns its keep specifically for data that changes rarely and is read often, exactly Module 41's "reach for a tool because it solves a real problem" principle applied to performance rather than architecture.
Exercise
As a comment, explain why Module 42's Bank_Account__c.Balance__c should NOT be read from Platform Cache, even though caching it would reduce SOQL queries.
Show hint
Think about how often a balance changes and what happens if a cached value is stale.
Platform Cache Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
Platform Cache stores frequently-accessed, rarely-changing data in memory across transactions, avoiding repeated SOQL queries for data that does not need to be fetched fresh every single time.