|
1 | | -# Apex Cache Manager |
| 1 | +# Nebula Cache Manager |
| 2 | + |
| 3 | +A flexible cache management system for Salesforce Apex developers. Built to be scalable & configurable. |
| 4 | + |
| 5 | +Learn more about the history & implementation of this repo in [the Joys of Apex article 'Iteratively Building a Flexible Caching System for Apex'](https://www.jamessimone.net/blog/joys-of-apex/iteratively-building-a-flexible-caching-system/) |
| 6 | + |
| 7 | +## Unlocked Package - `Nebula` Namespace - v1.0.0 |
| 8 | + |
| 9 | +[](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n2AQAQ) |
| 10 | +[](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n2AQAQ) |
| 11 | + |
| 12 | +## Unlocked Package - No Namespace - v1.0.0 |
| 13 | + |
| 14 | +[](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n25QAA) |
| 15 | +[](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n25QAA) |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Cache Manager for Apex: Quick Start |
| 20 | + |
| 21 | +For Apex developers, the `CacheManager` class has several methods that can be used to cache data in 1 of the 3 supported cache types - transaction, organization platform cache, and session platform cache. Each cache type implements the interface `CacheManager.Cacheable` - regardless of which cache type you choose, the way you interact with each cache type is consistent. |
| 22 | + |
| 23 | +```java |
| 24 | +// This will cache a Map<String, Group> that contains all queues in the current org (if the data has not been cached) |
| 25 | +// or it will return the cached version of the data (if the data has previously been cached) |
| 26 | +public static Map<String, Group> getQueues() { |
| 27 | + String cacheKey = 'queues'; |
| 28 | + Map<String, Group> queueDeveloperNameToQueueGroup; |
| 29 | + if (CacheManager.getOrganization().contains(cacheKey)) { |
| 30 | + queueDeveloperNameToQueueGroup = (Map<String, Group>) CacheManager.getOrganization().get(cacheKey); |
| 31 | + } else { |
| 32 | + queueDeveloperNameToQueueGroup = new Map<String, Group>(); |
| 33 | + for (Group queueGroup : [SELECT Id, DeveloperName, Email, Name FROM Group WHERE Type = 'Queue']) { |
| 34 | + queueDeveloperNameToQueueGroup.put(queueGroup.DeveloperName, queueGroup); |
| 35 | + } |
| 36 | + CacheManager.getOrganization().put(cacheKey, queueDeveloperNameToQueueGroup); |
| 37 | + } |
| 38 | + return queueDeveloperNameToQueueGroup; |
| 39 | +} |
| 40 | +``` |
0 commit comments