Unified Interface
One consistent API for all cache types - transaction, org, and session cache with the same methods.
A clean, unified interface for Salesforce Platform Cache - supporting transaction, org, and session caching with a consistent API
Salesforce Platform Cache is powerful but verbose. Cache Manager simplifies it with a clean, consistent API:
// Platform Cache - verbose and complex
Cache.Org orgCache = Cache.Org.getPartition('local.Default');
orgCache.put('userId', currentUser);
User cachedUser = (User) orgCache.get('userId');
// Different API for transaction cache
Map<String, Object> transactionCache = new Map<String, Object>();
transactionCache.put('userId', currentUser);
User user = (User) transactionCache.get('userId');// Cache Manager - simple and consistent
CacheManager.DefaultOrgCache.put('userId', currentUser);
User cachedUser = (User) CacheManager.DefaultOrgCache.get('userId');
// Same API for transaction cache
CacheManager.ApexTransaction.put('userId', currentUser);
User user = (User) CacheManager.ApexTransaction.get('userId');// Cache user data for the transaction
CacheManager.ApexTransaction.put(
UserInfo.getUserId(),
[SELECT Id, Name, Email FROM User WHERE Id = :UserInfo.getUserId()]
);
// Retrieve from cache (no SOQL query)
User currentUser = (User) CacheManager.ApexTransaction.get(UserInfo.getUserId());
// Check if key exists
if (CacheManager.ApexTransaction.contains(UserInfo.getUserId())) {
// Use cached data
}
// Remove from cache
CacheManager.ApexTransaction.remove(UserInfo.getUserId());Cache Manager supports three types of caching:
In-memory cache that lasts for the duration of a single transaction.
CacheManager.ApexTransaction.put('key', value);Persistent cache shared across the entire org.
CacheManager.DefaultOrgCache.put('key', value);Persistent cache scoped to a single user session.
CacheManager.DefaultSessionCache.put('key', value);put, get, contains, remove, getKeysinterface Cacheable {
void put(String key, Object value); // Store value
Object get(String key); // Retrieve value
Boolean contains(String key); // Check if key exists
void remove(String key); // Remove key
Set<String> getKeys(); // Get all keys
}Cache Manager is part of Apex Fluently, a suite of production-ready Salesforce libraries by Beyond the Cloud.
Ready to simplify your caching? Get started →