-
Notifications
You must be signed in to change notification settings - Fork 459
PlatformCacheRecipes
Illustrates how to programatically use the Platform Cache feature of Salesforce. Many of these recipes are, taken together, not very DRY (don't repeat yourself). However, they're intentionally listed here as a way of repeatedly demonstrating Platform Cache functionality
Group Platform Cache Recipes
Defines the default cache partition for use in this class.
private static final DEFAULT_PARTITION
String
These methods are for the Session Cache Max TTL for Session partion is 8 hours.
public static void storeValueInSessionCache(String key, String value)
Name | Type | Description |
---|---|---|
key | String | |
value | String |
void
Stores a value in the Session cache with a custom timeout.
public static void storeValueInSessionCache(String key, String value, Integer ttl)
Name | Type | Description |
---|---|---|
key | String | key under which the value is saved. |
value | String | value to store in the cache |
ttl | Integer | Time To Live (ttl) is the number of seconds this |
item will remain in cache. |
void
Retrieves a value from the cache identified by key
public static String getValueFromSessionCache(String key)
Name | Type | Description |
---|---|---|
key | String | key of which value to retrieve. |
String
the value
removes a key/value from the cache manually
public static void removeKeyFromSessionCache(String key)
Name | Type | Description |
---|---|---|
key | String | key to remove |
void
CacheException: custom exception when key not found.
These methods relate to the ORG cache Max TTL for Org Cache is 48 hours.
public static void storeValueInOrgCache(String key, String value)
Name | Type | Description |
---|---|---|
key | String | |
value | String |
void
Stores a value in the Org cache with a custom timeout.
public static void storeValueInOrgCache(String key, String value, Integer ttl)
Name | Type | Description |
---|---|---|
key | String | key under which the value is saved. |
value | String | value to store in the cache. |
ttl | Integer | Time To Live (ttl) is the number of seconds this |
item will remain in cache. |
void
Retrieves a value from the cache identified by key
public static String getValueFromOrgCache(String key)
Name | Type | Description |
---|---|---|
key | String | key of which value to retrieve. |
String
the value associated with the supplied key
removes a key/value from the cache manually
public static void removeKeyFromOrgCache(String key)
Name | Type | Description |
---|---|---|
key | String | key to remove |
void
CacheException: custom exception when key not found.
returns a partition for a given name, and type
public static Cache.Partition getDefaultPartition(PartitionType type)
Name | Type | Description |
---|---|---|
type | PartitionType | the partition type |
Cache.Partition
the partition
internal custom exception class.
Enum for partition type.
Value | Description |
---|---|
SESSION | |
ORG |