2. Sensitivity: Internal & Restricted
Increase your Salesforce Performance
using Lightning Platform Cache
Vineet Goel, Lead Salesforce Consultant
QA Infotech Software Services Limited
@vineet1817
Email: vineet1817@gmail.com
Blogging at: https://vineetgoelcloudblog.wordpress.com/
3. Forward-Looking Statement
Statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks,
uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could
differ materially from the results expressed or implied by the forward looking statements we make. All statements other than statements of historical fact could
be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any
statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded
services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service,
new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions
or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and
acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and
manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and
utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These
documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Website.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update
these forward-looking statements.
4. Agenda
● Cache
● Caching Options in Salesforce
● Salesforce Platform Cache
● Benefits
● Types of Lightning Platform Cache
● Demo
● Cache Builder
● Use Cases
● Key Points
● References
● Q & A
5. Cache
Caching is very important part of any application. In this modern times, cache helps end
users experience better performance and allows processes to execute faster.
How does caching enhance end user experience?
● Caching reduces database consumption, frees up critical resources for other
processes.
● A cache stores data in-memory, this make retrieval very fast.
● Cached is data closer to where the data is required i.e, processing or presentation
layers this reduces the round trip time for transactions
● To achieve this on the Salesforce platform, we can utilize a managed product called
Platform Cache.
6. Previous Caching Options
Useful but very limited like Custom Setting, Sobjects and Custom Metadata
(Inflexible)
Recent Cache Options
These days Caching is present in every layer, Now Platform Cache is available for
Salesforce Developers
7. Salesforce Platform Cache
Developer Edition (0 MB by Default), but can get 10 MB as a trial.
Enterprise (10 MB by default)
Unlimited/ Performance Edition (30 MB by default)
Enterprise and Unlimited licenses can get up to 3GB upon request.
Purchase Option Always Available!!!
8. While querying data from database directly
Benefits
After using Platform Cache, we see good reduction in DB usage and Heap as well
9. Types of Lighting Platform Cache
Session cache
Stores data for individual user sessions.The maximum life of a session is 8 hours.
Session cache expires when its specified time-to-live (ttlsecs value) is reached or
when the session expires after 8 hours, whichever comes first.
Cache.SessionPartition and Cache.Session are 2 classes used to get and put
data. If you’re managing cache values in one partition, use the
Cache.SessionPartition methods instead acc. to below code snippet.
10. Org cache
Stores data that any user in an org reuses.
Unlike session cache, the org cache is accessible across sessions, requests, and org
users and profiles. Org cache expires when its specified time-to-live (ttlsecs value) is
reached.The maximum life of a Org Cache is 48 hours.Cache.Org and
Cache.OrgPartition are 2 classes used to get and put the data.
If you’re managing cache values in one partition, use the Cache.OrgPartition
methods instead.
11. Sensitivity: Internal & Restricted
Demo
Using Lightning Web Component to fetch Object Names
Git Repo for Code Reference
https://github.com/vineet-goel-salesforce/platformCache
12. Cache Builder
Cache Misses actually happen if we don’t write the code in such a way.Too many
cache misses will reduce the effectiveness of the cache.
Salesforce Platform Cache provides CacheBuilder interface which helps with this
use case.
A simple method doLoad() used for safely retrieving and removing values from a
session or org cache. The interface checks for cache misses, which means you no
longer need to check for null cache values yourself.
One limitation with this is you cannot specify the TTL. This interface doesn’t provide this
ability.
13. Org Cache Use Cases
● Case list for service agents
● Leads list for sales agents
● Report summary data
● Shared user profiles, metadata, org info
Session Cache use Cases
● Accounts, contacts or user info private to the user
● Order history, order items, discount information
● Custom data with calculations in a transaction
● Financial data
14. Key Points to Consider
● Know the limits
https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_platform_cache_limits.htm
● Best practices
https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_platform_cache_best_practices.htm
Not all data can be cached. Data that is shared among multiple users and
getting constantly updated can lead to race conditions.
15. References
Trailhead
https://trailhead.salesforce.com/en/content/learn/modules/platform_cache
Thanks to Anil Jacob and Josh Kaplan
https://developer.salesforce.com/blogs/2020/06/caching-in-the-salesforce-platform.html
https://developer.salesforce.com/blogs/2019/08/scaling-data-access-with-app-layer-cache.html
https://developer.salesforce.com/blogs/engineering/2015/05/platform-cache.html
Developer Guide
https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_cache_namespace_overview.htm
Trailmix
https://trailhead.salesforce.com/en/users/isvteprograms/trailmixes/isv-product-team-platform-cache