Skip to content

Commit 5858029

Browse files
authored
Alphanumeric Cache Key (#201) (#202)
* Alphanumeric Cache Key * Lib version --------- Signed-off-by: Piotr PG Gajek <[email protected]>
1 parent 05ea1fe commit 5858029

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

force-app/main/default/classes/main/cached-soql/SOQLCache.cls

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
* PMD False Positives:
88
* - ExcessivePublicCount: It is a library class and exposes all necessary methods to construct a query
@@ -312,10 +312,14 @@ public virtual inherited sharing class SOQLCache implements Cacheable {
312312

313313
private class CacheStorageProxy {
314314
private CacheManager.Cacheable storage = CacheManager.ApexTransaction;
315-
private String ofObject;
315+
private String cacheKey;
316316

317317
public CacheStorageProxy(String ofObject) {
318-
this.ofObject = ofObject;
318+
this.cacheKey = this.getAlphanumericKeyFromObjectApiName(ofObject);
319+
}
320+
321+
private String getAlphanumericKeyFromObjectApiName(String ofObject) {
322+
return Pattern.compile('[^a-zA-Z0-9]').matcher(ofObject).replaceAll('');
319323
}
320324

321325
public CacheStorageProxy apexTransaction() {
@@ -344,15 +348,15 @@ public virtual inherited sharing class SOQLCache implements Cacheable {
344348
}
345349

346350
public void putRecordsToCache(List<CacheItem> records) {
347-
this.storage.put(this.ofObject, records);
351+
this.storage.put(this.cacheKey, records);
348352
}
349353

350354
public Boolean hasCachedRecords() {
351-
return this.storage.contains(this.ofObject);
355+
return this.storage.contains(this.cacheKey);
352356
}
353357

354358
public List<CacheItem> getCachedRecords() {
355-
return (List<CacheItem>) (this.storage.get(this.ofObject) ?? new List<CacheItem>());
359+
return (List<CacheItem>) (this.storage.get(this.cacheKey) ?? new List<CacheItem>());
356360
}
357361

358362
public void addRecordsToCache(List<SObject> recordsToAdd) {

force-app/main/default/classes/main/cached-soql/SOQLCache_Test.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
* PMD False Positives:
88
* - CyclomaticComplexity: It is a library and we tried to put everything into ONE test class

force-app/main/default/classes/main/soql-evaluator/SOQLEvaluator.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
* PMD False Positives:
88
* - CognitiveComplexity: It is a library and we tried to put everything into ONE class

force-app/main/default/classes/main/soql-evaluator/SOQLEvaluator_Test.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
**/
88
@IsTest

force-app/main/default/classes/main/standard-soql/SOQL.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
* PMD False Positives:
88
* - ExcessivePublicCount: It is a library class and exposes all necessary methods to construct a query

force-app/main/default/classes/main/standard-soql/SOQL_Test.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev)
33
* Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/soql-lib/blob/main/LICENSE)
44
*
5-
* v6.0.1
5+
* v6.0.2
66
*
77
* PMD False Positives:
88
* - CyclomaticComplexity: It is a library and we tried to put everything into ONE test class

0 commit comments

Comments
 (0)