Skip to content

Commit

Permalink
Initial release + Joys of Apex article (#1)
Browse files Browse the repository at this point in the history
* Created new project based Nebula Logger's cache class as a standalone version, CacheManager

* Provided more developer controls for caching by adding several new methods to the interface CacheManager.Cacheable

* Provided more configuration options for caching via CacheConfiguration__mdt and CacheValue__mdt custom metadata types

* Created namespaced (`Nebula`) and no-namespace 2GP unlocked packages

* Added link to a new Joys of Apex article that walks through iteratively expanding upon the CacheManager class - https://www.jamessimone.net/blog/joys-of-apex/iteratively-building-a-flexible-caching-system/

---------

Co-authored-by: James Simone <[email protected]>
  • Loading branch information
jongpie and jamessimone authored Feb 16, 2023
1 parent e69549e commit fb14864
Show file tree
Hide file tree
Showing 43 changed files with 26,008 additions and 5,499 deletions.
5 changes: 4 additions & 1 deletion .forceignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ package.xml
**/.eslintrc.json

# LWC Jest
**/__tests__/**
**/__tests__/**

# Metadata
**.profile-meta.xml
19 changes: 19 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Set the default line return behavior, in case people don't have core.autocrlf set.
* text=auto eol=lf

# Common git file types
.gitattributes text eol=lf
.gitignore text eol=lf
*.md text eol=lf

# Salesforce-specfic file types
*.app text eol=lf
*.cls text eol=lf
*.cmp text eol=lf
*.component text eol=lf
*.css text eol=lf
*.html text eol=lf
*.js text eol=lf
*.page text eol=lf
*.trigger text eol=lf
*.xml text eol=lf
26 changes: 13 additions & 13 deletions .github/workflows/fetch-repo-stats.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Fetch Repo Stats

on:
schedule:
# Run this once per day, towards the end of the day for keeping the most
# recent data point most meaningful (hours are interpreted in UTC).
- cron: '0 23 * * *'
workflow_dispatch: # Allow for running this manually.
schedule:
# Run this once per day, towards the end of the day for keeping the most
# recent data point most meaningful (hours are interpreted in UTC).
- cron: '0 23 * * *'
workflow_dispatch: # Allow for running this manually.

jobs:
j1:
name: store-repo-stats
runs-on: ubuntu-latest
steps:
- name: run-ghrs
uses: jgehrcke/github-repo-stats@RELEASE
with:
ghtoken: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
j1:
name: store-repo-stats
runs-on: ubuntu-latest
steps:
- name: run-ghrs
uses: jgehrcke/github-repo-stats@RELEASE
with:
ghtoken: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ deploy-options.json
# LWC VSCode autocomplete
**/lwc/jsconfig.json

# LWC Jest coverage reports
coverage/
# Code coverage reports
test-coverage/

# Salesforce metadata
**/customMetadata/CacheValue.**.md-meta.xml
**.profile-meta.xml

# Logs
logs
Expand Down
11 changes: 6 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#

**/staticresources/**
.localdevserver
.sfdx
.vscode

coverage/
.localdevserver/
.sf/
.sfdx/
.husky/
coverage/
node_modules/
17 changes: 5 additions & 12 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"tabWidth": 2,
"arrowParens": "avoid",
"printWidth": 160,
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": { "parser": "lwc" }
},
{
"files": "*.{cmp,page,component}",
"options": { "parser": "html" }
}
]
}
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none"
}
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# Apex Cache Manager
# Nebula Cache Manager

A flexible cache management system for Salesforce Apex developers. Built to be scalable & configurable.

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/)

## Unlocked Package - `Nebula` Namespace - v1.0.0

[![Install Unlocked Package (Nebula namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n2AQAQ)
[![Install Unlocked Package (Nebula namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n2AQAQ)

## Unlocked Package - No Namespace - v1.0.0

[![Install Unlocked Package (no namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n25QAA)
[![Install Unlocked Package (no namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n25QAA)

---

## Cache Manager for Apex: Quick Start

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.

```java
// This will cache a Map<String, Group> that contains all queues in the current org (if the data has not been cached)
// or it will return the cached version of the data (if the data has previously been cached)
public static Map<String, Group> getQueues() {
String cacheKey = 'queues';
Map<String, Group> queueDeveloperNameToQueueGroup;
if (CacheManager.getOrganization().contains(cacheKey)) {
queueDeveloperNameToQueueGroup = (Map<String, Group>) CacheManager.getOrganization().get(cacheKey);
} else {
queueDeveloperNameToQueueGroup = new Map<String, Group>();
for (Group queueGroup : [SELECT Id, DeveloperName, Email, Name FROM Group WHERE Type = 'Queue']) {
queueDeveloperNameToQueueGroup.put(queueGroup.DeveloperName, queueGroup);
}
CacheManager.getOrganization().put(cacheKey, queueDeveloperNameToQueueGroup);
}
return queueDeveloperNameToQueueGroup;
}
```
25 changes: 25 additions & 0 deletions config/linters/pmd-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" ?>
<ruleset
name="Nebula Cache Manager Rules"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"
>
<description>
Nebula Cache Manager custom PMD ruleset
</description>
<rule ref="category/apex/bestpractices.xml">
</rule>
<rule ref="category/apex/codestyle.xml">
</rule>
<rule ref="category/apex/design.xml">
</rule>
<rule ref="category/apex/documentation.xml">
</rule>
<rule ref="category/apex/errorprone.xml">
</rule>
<rule ref="category/apex/performance.xml">
</rule>
<rule ref="category/apex/security.xml">
</rule>
</ruleset>
13 changes: 0 additions & 13 deletions config/project-scratch-def.json

This file was deleted.

18 changes: 18 additions & 0 deletions config/scratch-orgs/base-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"orgName": "Nebula Cache Manager - Base Scratch Org",
"edition": "Enterprise",
"hasSampleData": true,
"country": "US",
"language": "en_US",
"features": [],
"settings": {
"securitySettings": {
"enableAdminLoginAsAnyUser": false
},
"userManagementSettings": {
"enableEnhancedPermsetMgmt": true,
"enableEnhancedProfileMgmt": true,
"enableNewProfileUI": true
}
}
}
18 changes: 18 additions & 0 deletions config/scratch-orgs/platform-cache-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"orgName": "Nebula Cache Manager - Base Scratch Org",
"edition": "Enterprise",
"hasSampleData": true,
"country": "US",
"language": "en_US",
"features": ["PlatformCache"],
"settings": {
"securitySettings": {
"enableAdminLoginAsAnyUser": false
},
"userManagementSettings": {
"enableEnhancedPermsetMgmt": true,
"enableEnhancedProfileMgmt": true,
"enableNewProfileUI": true
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/btn-install-unlocked-package-sandbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<PlatformCachePartition xmlns="http://soap.sforce.com/2006/04/metadata">
<isDefaultPartition>false</isDefaultPartition>
<masterLabel>CacheManagerPartition</masterLabel>
<platformCachePartitionTypes>
<allocatedCapacity>0</allocatedCapacity>
<allocatedPartnerCapacity>0</allocatedPartnerCapacity>
<allocatedPurchasedCapacity>0</allocatedPurchasedCapacity>
<allocatedTrialCapacity>0</allocatedTrialCapacity>
<cacheType>Session</cacheType>
</platformCachePartitionTypes>
<platformCachePartitionTypes>
<allocatedCapacity>0</allocatedCapacity>
<allocatedPartnerCapacity>0</allocatedPartnerCapacity>
<allocatedPurchasedCapacity>0</allocatedPurchasedCapacity>
<allocatedTrialCapacity>0</allocatedTrialCapacity>
<cacheType>Organization</cacheType>
</platformCachePartitionTypes>
</PlatformCachePartition>
Loading

0 comments on commit fb14864

Please sign in to comment.