Platform Cache
A new way to do things
​Josh Kaplan
​Director, Product Management
​jkaplan@salesforce.com
​@JoshSFDC
​
• What’s a cache?
• How can I use the cache?
• How does it work?
• How do I get some?
Agenda
Cache Primer
What is a Cache?
Computer Cache
RAM Hard Drive
Platform
Cache
Database
Your Computer
Our Cloud
When To Use Platform Cache
Examples of where this feature can help you
Good Idea?
or Bad Idea?
My Bitcoin Exchange
​Simple key-value programming model
• Just like interacting with a Map<String,Object>
• put(key, value); get(key); remove(key); contains(key);
• Type casting easily handled
​Atomic Transactions
• Cache puts done at end of transaction
• “local cache” during transaction
• Data put to cache only if transaction succeeds
For sharing data that can be reused across your whole org
Org Cache
Customer Service
My Bitcoin Exchange
​A specialized version of org cache
• Same programming model
• User session ID logically appended to cache key
• TTL always is the user’s session
​Eviction managed for you
• Time-To-Live (TTL)
• Least-recently used (LRU)
For retaining data throughout a user session
Session Cache
To Make Your Application Faster
• Eliminate redundant expensive queries
• Eliminate redundant expensive calculations
• Stop overcrowding the Visualforce View State
​To Make Application Development Easier
• Create structures in Apex
• Avoid the unique patterns for developing against Custom Settings
• No need to sweep for old stale data
Why Use Platform Cache?
​Org Cache
• Data that is very likely to be needed again by multiple users
• Data that is expensive to re-create repeatedly
• Not data that can be retrieved by a simple SOQL query
• Data that is accessed frequently but changed infrequently
​Session Cache
• Data that is very likely to be needed again across transactions throughout the session
• Data that is only needed in this particular user session
Hint: NOT ALWAYS
When Do I Use Platform Cache?
The Gory Details
Guts of the Machine
Total
Distributed
Cache
Guts of the Machine
​Data put to the cache may not be there when you try to get it
• Application Server Shutdown
• Capacity Eviction
• Service Protection
​Always expect to miss
• Builder Pattern
​Consider what data belongs in the cache
• Shopping Cart: durable or not?
​Consider what data does not belong in the cache
Platform Cache is NOT a durable store
Where’s My Data?
“Take only what you need to survive”
Platform Cache and Economics 101
​Some for free
• 10MB for EE orgs
• 30MB for UE orgs
​Some to buy
• 10MB increments
• Per-year subscription
ISV application-specific cache
• Restricted to a namespace
​Temporary Free Trial
• How much should I buy?
To Avoid The Tragedy of the Commons
Cash For Cache
​Things we must protect:
• The Network
• Size of each stored value – serialized size
• Redis
• Number of keys
• Minimum partition size
Yes, Limits. Sorry.
Limits?
Divide your cache space into the logical partitions that suit your needs
Partitions
Service Cloud
13MB
Shared Menus
7MB
Sales Cloud
10MB
Session
Cache
8MB
Org
Cache
5MB
Divide your cache space into the logical partitions that suit your needs
Partitions
Service Cloud
13MB
Shared Menus
7MB
Sales Cloud
40MB
Session
Cache
8MB
Org
Cache
5MB
​Platform Cache can make your applications faster
​Use Platform Cache where it makes sense
​Do not abuse Platform Cache!
​Platform Cache data is not durable – expect misses and handle them
​Use partitions to manage churn
​Purchase more Platform Cache space to improve your application performance
What To Remember
Thank you

Platform Cache (DF15 session)

  • 1.
    Platform Cache A newway to do things ​Josh Kaplan ​Director, Product Management ​jkaplan@salesforce.com ​@JoshSFDC ​
  • 2.
    • What’s acache? • How can I use the cache? • How does it work? • How do I get some? Agenda
  • 3.
  • 4.
    What is aCache?
  • 5.
    Computer Cache RAM HardDrive Platform Cache Database Your Computer Our Cloud
  • 6.
    When To UsePlatform Cache Examples of where this feature can help you
  • 7.
  • 8.
  • 9.
    ​Simple key-value programmingmodel • Just like interacting with a Map<String,Object> • put(key, value); get(key); remove(key); contains(key); • Type casting easily handled ​Atomic Transactions • Cache puts done at end of transaction • “local cache” during transaction • Data put to cache only if transaction succeeds For sharing data that can be reused across your whole org Org Cache
  • 10.
  • 11.
    ​A specialized versionof org cache • Same programming model • User session ID logically appended to cache key • TTL always is the user’s session ​Eviction managed for you • Time-To-Live (TTL) • Least-recently used (LRU) For retaining data throughout a user session Session Cache
  • 12.
    To Make YourApplication Faster • Eliminate redundant expensive queries • Eliminate redundant expensive calculations • Stop overcrowding the Visualforce View State ​To Make Application Development Easier • Create structures in Apex • Avoid the unique patterns for developing against Custom Settings • No need to sweep for old stale data Why Use Platform Cache?
  • 13.
    ​Org Cache • Datathat is very likely to be needed again by multiple users • Data that is expensive to re-create repeatedly • Not data that can be retrieved by a simple SOQL query • Data that is accessed frequently but changed infrequently ​Session Cache • Data that is very likely to be needed again across transactions throughout the session • Data that is only needed in this particular user session Hint: NOT ALWAYS When Do I Use Platform Cache?
  • 14.
  • 15.
    Guts of theMachine Total Distributed Cache
  • 16.
    Guts of theMachine
  • 17.
    ​Data put tothe cache may not be there when you try to get it • Application Server Shutdown • Capacity Eviction • Service Protection ​Always expect to miss • Builder Pattern ​Consider what data belongs in the cache • Shopping Cart: durable or not? ​Consider what data does not belong in the cache Platform Cache is NOT a durable store Where’s My Data?
  • 18.
    “Take only whatyou need to survive” Platform Cache and Economics 101
  • 19.
    ​Some for free •10MB for EE orgs • 30MB for UE orgs ​Some to buy • 10MB increments • Per-year subscription ISV application-specific cache • Restricted to a namespace ​Temporary Free Trial • How much should I buy? To Avoid The Tragedy of the Commons Cash For Cache
  • 20.
    ​Things we mustprotect: • The Network • Size of each stored value – serialized size • Redis • Number of keys • Minimum partition size Yes, Limits. Sorry. Limits?
  • 21.
    Divide your cachespace into the logical partitions that suit your needs Partitions Service Cloud 13MB Shared Menus 7MB Sales Cloud 10MB Session Cache 8MB Org Cache 5MB
  • 22.
    Divide your cachespace into the logical partitions that suit your needs Partitions Service Cloud 13MB Shared Menus 7MB Sales Cloud 40MB Session Cache 8MB Org Cache 5MB
  • 23.
    ​Platform Cache canmake your applications faster ​Use Platform Cache where it makes sense ​Do not abuse Platform Cache! ​Platform Cache data is not durable – expect misses and handle them ​Use partitions to manage churn ​Purchase more Platform Cache space to improve your application performance What To Remember
  • 24.