UTIL_Cache.Store
Class
global interface UTIL_Cache.StoreInterface for Platform Cache operations
Since: 1.0
Methods
| Method | Description |
|---|---|
| global abstract Boolean contains(String key) | Checks if a key exists in cache |
| global abstract Object get(String key) | Retrieves a value from cache. |
| global abstract Map getAll(Set<String> keys) | Retrieves multiple values from cache |
| global abstract UTIL_Cache.OperationResult getLastOperationResult() | Gets the result of the last cache operation for diagnostics |
| global abstract Boolean isCacheAvailable() | Checks if Platform Cache is available for the configured partition |
| global abstract Boolean put(String key, Object value) | Stores a value in cache with default TTL. |
| global abstract Boolean put(String key, Object value, Integer ttlSeconds) | Stores a value in cache with custom TTL. |
| global abstract Boolean putAll(Map<String, Object> valuesMap) | Stores multiple values in cache with default TTL |
| global abstract Boolean putAll(Map<Map ttlSeconds) | Stores multiple values in cache with custom TTL |
| global abstract Boolean remove(String key) | Removes a value from cache |
| global abstract Boolean removeAll(Set<String> keys) | Removes multiple keys from cache |
| global abstract UTIL_Cache.Store withPartition(String partitionName) | Sets the partition name (fluent API) |
| global abstract UTIL_Cache.Store withScope(UTIL_Cache.Scope cacheType) | Sets the cache type preference (fluent API) |
| global abstract UTIL_Cache.Store withUserScope(Boolean userScoped) | Enables or disables user-scoped keys (fluent API) |
Method Details
contains
global abstract Boolean contains(String key)Checks if a key exists in cache
Parameters:
key(String) - The cache key
Returns: Boolean - True if key exists in cache
get
global abstract Object get(String key)Retrieves a value from cache.
Warning — read-modify-write is unsafe across parallel transactions. A get paired with a subsequent put to mutate the value is non-atomic; concurrent transactions reading the same key see the same pre-mutation value and overwrite each other on put. See the class-level "Concurrency model" note.
Parameters:
key(String) - The cache key
Returns: Object - The cached value or null if not found
getAll
global abstract Map<String, Object> getAll(Set<String> keys)Retrieves multiple values from cache
Parameters:
keys(Set) - Set of keys to retrieve
Returns: Object - Map of Key -> Value (found items only)
getLastOperationResult
global abstract UTIL_Cache.OperationResult getLastOperationResult()Gets the result of the last cache operation for diagnostics
Returns: UTIL_Cache.OperationResult - Last operation result with detailed status information
isCacheAvailable
global abstract Boolean isCacheAvailable()Checks if Platform Cache is available for the configured partition
Returns: Boolean - True if cache is available
put
global abstract Boolean put(String key, Object value)Stores a value in cache with default TTL.
Warning — non-atomic against concurrent writes. Platform Cache exposes no compare-and-swap and no cross-transaction lock, so a read-modify-write loop (get → mutate → put) loses 80-95% of writes under 50-100 parallel transaction contention. For counter-style use cases (rate limiters, dedupe, semaphores) use a custom object with SOQL FOR UPDATE row locks instead.
Parameters:
Returns: Boolean - True if stored successfully
put
global abstract Boolean put(String key, Object value, Integer ttlSeconds)Stores a value in cache with custom TTL.
Warning — non-atomic against concurrent writes. Same caveat as the no-TTL overload: read-modify-write across parallel transactions silently loses writes. See the class-level "Concurrency model" note.
Parameters:
key(String) - The cache keyvalue(Object) - The value to cachettlSeconds(Integer) - TTL in seconds (null uses default)
Returns: Boolean - True if stored successfully
putAll
global abstract Boolean putAll(Map<String, Object> valuesMap)Stores multiple values in cache with default TTL
Parameters:
valuesMap(Map) - Map of Key -> Value to store
Returns: Boolean - True if operation was attempted
putAll
global abstract Boolean putAll(Map<String, Object> valuesMap, Integer ttlSeconds)Stores multiple values in cache with custom TTL
Parameters:
Returns: Boolean - True if operation was attempted
remove
global abstract Boolean remove(String key)Removes a value from cache
Parameters:
key(String) - The cache key
Returns: Boolean - True if removed successfully
removeAll
global abstract Boolean removeAll(Set<String> keys)Removes multiple keys from cache
Parameters:
keys(Set) - Set of keys to remove
Returns: Boolean - True if operation completed
withPartition
global abstract UTIL_Cache.Store withPartition(String partitionName)Sets the partition name (fluent API)
Parameters:
partitionName(String) - The fully qualified partition name (e.g., 'local.MyPartition')
Returns: UTIL_Cache.Store - This instance
withScope
global abstract UTIL_Cache.Store withScope(UTIL_Cache.Scope cacheType)Sets the cache type preference (fluent API)
Parameters:
cacheType(UTIL_Cache.Scope) - The cache type to prefer (SESSION, ORG, AUTO)
Returns: UTIL_Cache.Store - This instance
withUserScope
global abstract UTIL_Cache.Store withUserScope(Boolean userScoped)Enables or disables user-scoped keys (fluent API)
Parameters:
userScoped(Boolean) - Whether to scope keys by current user
Returns: UTIL_Cache.Store - This instance