Skip to content

UTIL_Cache.Store

Class

apex
global interface UTIL_Cache.Store

Interface for Platform Cache operations


Methods

MethodDescription
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<String, Object> 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<String, Object> valuesMap, Integer 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)

contains

apex
global abstract Boolean contains(String key)

Checks if a key exists in cache

Parameters

ParameterTypeDescription
keyStringThe cache key

Returns Boolean — True if key exists in cache

get

apex
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

ParameterTypeDescription
keyStringThe cache key

Returns Object — The cached value or null if not found

getAll

apex
global abstract Map<String, Object> getAll(Set<String> keys)

Retrieves multiple values from cache

Parameters

ParameterTypeDescription
keysSetSet of keys to retrieve

Returns Object — Map of Key -> Value (found items only)

getLastOperationResult

apex
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

apex
global abstract Boolean isCacheAvailable()

Checks if Platform Cache is available for the configured partition

Returns Boolean — True if cache is available

put

apex
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

ParameterTypeDescription
keyStringThe cache key
valueObjectThe value to cache

Returns Boolean — True if stored successfully

apex
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

ParameterTypeDescription
keyStringThe cache key
valueObjectThe value to cache
ttlSecondsIntegerTTL in seconds (null uses default)

Returns Boolean — True if stored successfully

putAll

apex
global abstract Boolean putAll(Map<String, Object> valuesMap)

Stores multiple values in cache with default TTL

Parameters

ParameterTypeDescription
valuesMapMapMap of Key -> Value to store

Returns Boolean — True if operation was attempted

apex
global abstract Boolean putAll(Map<String, Object> valuesMap, Integer ttlSeconds)

Stores multiple values in cache with custom TTL

Parameters

ParameterTypeDescription
valuesMapMapMap of Key -> Value to store
ttlSecondsStringTTL in seconds

Returns Boolean — True if operation was attempted

remove

apex
global abstract Boolean remove(String key)

Removes a value from cache

Parameters

ParameterTypeDescription
keyStringThe cache key

Returns Boolean — True if removed successfully

removeAll

apex
global abstract Boolean removeAll(Set<String> keys)

Removes multiple keys from cache

Parameters

ParameterTypeDescription
keysSetSet of keys to remove

Returns Boolean — True if operation completed

withPartition

apex
global abstract UTIL_Cache.Store withPartition(String partitionName)

Sets the partition name (fluent API)

Parameters

ParameterTypeDescription
partitionNameStringThe fully qualified partition name (e.g., 'local.MyPartition')

Returns UTIL_Cache.Store — This instance

withScope

apex
global abstract UTIL_Cache.Store withScope(UTIL_Cache.Scope cacheType)

Sets the cache type preference (fluent API)

Parameters

ParameterTypeDescription
cacheTypeUTIL_Cache.ScopeThe cache type to prefer (SESSION, ORG, AUTO)

Returns UTIL_Cache.Store — This instance

withUserScope

apex
global abstract UTIL_Cache.Store withUserScope(Boolean userScoped)

Enables or disables user-scoped keys (fluent API)

Parameters

ParameterTypeDescription
userScopedBooleanWhether to scope keys by current user

Returns UTIL_Cache.Store — This instance