top of page

Salesforce Caching Isn't Just an Optimization — It's an Engineering Mindset


Discover how caching transforms Salesforce engineering from a coding trick into a mindset. Learn why smart caching matters for scaling, user experience, and respecting platform limits.

The Real Purpose Behind Caching

When most developers hear "caching," they think:"Make it faster."


But what if caching is actually much deeper? What if caching is about respecting time, user experience, and governor limits?


Our discussions opened up a fundamental realization: Caching is not just a technique. It’s a philosophy about how you treat expensive operations — and when you realize that, it changes how you architect.


🔥 Caching is Paramount: And It's Already Happening More Than You Think

Caching already runs under the hood in Salesforce:

  • Lightning Data Service (LDS): Shares cached record data between components on a page.

  • Browser Caching: Stores Salesforce's static resources (JS, CSS) to speed up page loads.

  • RecentlyViewed Object: Internally tracks records a user recently accessed without querying live data every time.

  • Dashboard Snapshots: Dashboards don't run live SOQL every view — they show cached data until a refresh.

➡️ So even without you asking for it, caching is everywhere.



🏛️ Browser Cache, LDS Cache, Platform Cache — All Have Their Place

  • Browser Cache: Good for static files, session-bound.

  • LDS Cache: Good for sharing record data on the same page load.

  • Platform Cache: Good for serious server-side, cross-component reuse — especially across transactions, across records, across batches.

Each solves a different layer of the caching puzzle.


🤔 Why Didn't I Think About Caching Before?

Because Salesforce apps often "just work" —until they don’t:

  • A slow VPN network cripples the user experience -> This is where we have started the exploration of cache

  • A batch job processing 1000+ Accounts chokes on governor limits.

  • A Lightning page feels sluggish because of silent redundant SOQL queries.

That's when you realize:Caching wasn’t a luxury. It was a necessity all along.


📋 Two Rules Before Caching Anything

We discovered two hard rules:

  1. Only cache things that won't hurt if slightly stale.(For example: Yesterday’s exchange rates are fine for a few minutes.)

  2. Always think how you'll invalidate the cache.(If your cache never expires or does not refresh properly, it will slowly poison your system.)

Without those two rules, caching becomes dangerous instead of helpful.


📚 Real-World Cache Candidates

What makes a good cache candidate in Salesforce?

  • Reference Data: Countries, States, Currencies, Product Categories.

  • Permission Matrices: User to Role mappings, Custom security rules.

  • Computed Discounts: Promotions, Commission Rates.

  • Session Info: User Profile Attributes that don't change minute-by-minute.


Things that are:

  • Expensive to query

  • Stable over minutes or hours

  • Needed across multiple transactions


📉 Where We See Salesforce Teams Missing Out

Sadly, Platform Cache is criminally underused because:

  • Devs are unaware of it.

  • Fear of stale data.

  • Platform Cache size limits (free tier is small unless upgraded).

  • People wrongly believe "SOQL is cheap."

Meanwhile, systems could be twice as fast with half the CPU cost — if caching was used smartly.


🧩 Caching Isn't Just for Custom LWC Components

In the beginning, we thought:

"Caching makes sense only when you're building tons of custom LWCs."

But we realized:

  • Even pure backend jobs (Batch Apex, Scheduled Apex) can benefit massively.

  • Even pure Apex controller methods (with no UI) can optimize SOQL-heavy logic.

Caching is a backend superpower —especially in big data or multi-object operations.


🏗️ Designing Caching Right: Cache Formats and Keys

Before caching anything, we need to design:

Aspect

Good Practice

Cache Key Format

Predictable keys like "RecentContacts_UserId" or "ExchangeRate_USD_EUR"

Cache Value Format

Serialize Lists or Maps (avoid caching raw sObjects if possible)

TTL (Time to Live)

Set reasonable expiration (10 min, 1 hour, 1 day) depending on data nature

This prevents:

  • Cache collisions

  • Cache blowups

  • Data deserialization errors


🎯 Platform Cache TTL vs Manual Invalidation

Two valid strategies:

Strategy

When to Use

TTL Expiry

Good for soft-stale data (recent contacts, rates)

Event-Driven Invalidation

Good for highly accurate data (invalidate when record is updated)

In our architecture discussions, we decided to use both, depending on the use case.



🧠 Why Most Salesforce Projects Survive Without Caching (But Suffer Quietly)

Salesforce is powerful enough to hide performance issues...for a while.

But:

  • When user count grows,

  • When record count explodes,

  • When multiple departments use the same org,

Suddenly caching goes from a “nice to have” to “the only way forward.”

If you build with caching early, you scale painlessly later.


🛡️ Caching is Not About Laziness — It's About Respecting Limits

Caching is engineering discipline:

  • Respect the CPU time.

  • Respect the network bandwidth.

  • Respect the user's patience.

  • Respect Salesforce governor limits.

You don't cache because you're lazy to write good queries. You cache because you respect the full-stack cost of every query.



"In Salesforce engineering, caching isn't a hack.Caching is an act of respect for systems, users, and business value."

🌟 Closing Note

In Part 2, we’ll walk you through a real-world project where caching slashed execution time dramatically.



Comments


Contact Us

Thanks for submitting!

 Address. 249 Commerce Ave #1053 Manteca, CA 95336

© 2025 by YFC.

bottom of page