diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a91d25d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,45 @@ +{ + "trailingComma": "none", + "arrowParens": "avoid", + "singleQuote": true, + "plugins": ["prettier-plugin-apex", "@prettier/plugin-xml"], + "overrides": [ + { + "files": "**/lwc/**/*.html", + "options": { + "parser": "lwc", + "printWidth": 180 + } + }, + { + "files": "**/aura/**/*.cmp", + "options": { + "parser": "html", + "printWidth": 180, + "tabWidth": 4 + } + }, + { + "files": "*.{page,component}", + "options": { + "parser": "html", + "printWidth": 180 + } + }, + { + "files": "*.{cls,trigger,apex}", + "options": { + "parser": "apex", + "printWidth": 180, + "tabWidth": 4 + } + }, + { + "files": "*.{html,js,css}", + "options": { + "printWidth": 180, + "tabWidth": 4 + } + } + ] + } \ No newline at end of file diff --git a/force-app/main/default/classes/CacheManager.cls b/force-app/main/default/classes/CacheManager.cls index 3bc6993..fbae51b 100644 --- a/force-app/main/default/classes/CacheManager.cls +++ b/force-app/main/default/classes/CacheManager.cls @@ -2,6 +2,8 @@ * Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev) * Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/cache-manager/blob/main/LICENSE) * + * v1.1.0 + * * PMD False Positives: * - CognitiveComplexity: It is a library and we tried to put everything into ONE class * - PropertyNamingConventions: It was intentional to make the lib more fluent and readable @@ -84,6 +86,7 @@ public with sharing class CacheManager { private abstract class PlatformCache implements Cacheable { private Cache.Partition platformCachePartition; + private Cacheable fallback = new ApexTransactionCache(); public PlatformCache(String partitionName) { this.platformCachePartition = getPartition(partitionName); @@ -92,24 +95,39 @@ public with sharing class CacheManager { protected abstract Cache.Partition getPartition(String partitionName); public Boolean contains(String key) { - return this.platformCachePartition.contains(key); + return this.isAvailable() ? this.platformCachePartition.contains(key) : this.fallback.contains(key); } public Set getKeys() { - return this.platformCachePartition.getKeys(); + return this.isAvailable() ? this.platformCachePartition.getKeys() : this.fallback.getKeys(); } public Object get(String key) { - return this.platformCachePartition.get(key); + return this.isAvailable() ? this.platformCachePartition.get(key) : this.fallback.get(key); } public void remove(String key) { - this.platformCachePartition.remove(key); + if (this.isAvailable()) { + this.platformCachePartition.remove(key); + return; + } + + this.fallback.remove(key); } public void put(String key, Object value) { validateKey(key); - this.platformCachePartition.put(key, value); + + if (this.isAvailable()) { + this.platformCachePartition.put(key, value); + return; + } + + this.fallback.put(key, value); + } + + private Boolean isAvailable() { + return this.platformCachePartition != null; } } @@ -119,7 +137,11 @@ public with sharing class CacheManager { } public override Cache.Partition getPartition(String partitionName) { - return Cache.Org.getPartition(partitionName); + try { + return Cache.Org.getPartition(partitionName); + } catch (Cache.Org.OrgCacheException e) { + return null; + } } } @@ -129,7 +151,14 @@ public with sharing class CacheManager { } public override Cache.Partition getPartition(String partitionName) { - return Cache.Session.getPartition(partitionName); + if (!Cache.Session.isAvailable()) { + return null; + } + try { + return Cache.Session.getPartition(partitionName); + } catch (Cache.Session.SessionCacheException e) { + return null; + } } } } diff --git a/force-app/main/default/classes/CacheManager.cls-meta.xml b/force-app/main/default/classes/CacheManager.cls-meta.xml index 998805a..cad713d 100644 --- a/force-app/main/default/classes/CacheManager.cls-meta.xml +++ b/force-app/main/default/classes/CacheManager.cls-meta.xml @@ -1,5 +1,5 @@ - 62.0 + 66.0 Active diff --git a/force-app/main/default/classes/CacheManagerTest.cls b/force-app/main/default/classes/CacheManagerTest.cls index b7ee93d..94a7ab7 100644 --- a/force-app/main/default/classes/CacheManagerTest.cls +++ b/force-app/main/default/classes/CacheManagerTest.cls @@ -1,7 +1,10 @@ /** * Copyright (c) 2025 Beyond The Cloud Sp. z o.o. (BeyondTheCloud.Dev) * Licensed under the MIT License (https://github.com/beyond-the-cloud-dev/cache-manager/blob/main/LICENSE) -**/ + * + * v1.1.0 + * + **/ @IsTest private class CacheManagerTest { @IsTest diff --git a/force-app/main/default/classes/CacheManagerTest.cls-meta.xml b/force-app/main/default/classes/CacheManagerTest.cls-meta.xml index 998805a..cad713d 100644 --- a/force-app/main/default/classes/CacheManagerTest.cls-meta.xml +++ b/force-app/main/default/classes/CacheManagerTest.cls-meta.xml @@ -1,5 +1,5 @@ - 62.0 + 66.0 Active