-
Notifications
You must be signed in to change notification settings - Fork 7
[NAE-2182] Clearing actions cache #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
dd58002
NAE-2182 - Implementation of an endpoint for clearing the action cache
dominikvozr 5b98ca4
NAE-2182 - Implementation of custom cache wrapper to use in cacheManager
dominikvozr e917f76
NAE-2182 - Implementation of generic map cache and created actuator c…
dominikvozr bd719b5
NAE-2182 - cache FunctionsNamespace and functions if not found
dominikvozr e976081
NAE-2182 - prevent multi thread unexpected behaviour and prevent cach…
dominikvozr 8323adb
NAE-2182 - Implementation of generic map cache and changed store for …
dominikvozr f9796d6
NAE-2182 - removal of unused methods, correction of several issues du…
dominikvozr d2227d0
NAE-2182 - optimized imports, added helper and refactor code
dominikvozr cb1505f
Merge remote-tracking branch 'origin/release/7.0.0-rev8' into NAE-2182
machacjozef c18561f
Merge branch 'NAE-2212' into NAE-2182
renczesstefan f7b61be
Refactor caching logic in FieldActionsCacheService and improve annota…
renczesstefan 75b903d
Merge branch 'NAE-2266' into NAE-2182
renczesstefan 749db25
Update function to use the default Petri net version
renczesstefan 94724c5
Merge branch 'NAE-2212' into NAE-2182
renczesstefan 0f7bb9b
Merge branch 'NAE-2212' into NAE-2182
renczesstefan ebaa5a9
Merge remote-tracking branch 'origin/NAE-2182' into NAE-2182
renczesstefan d573cf2
Refactor function caching property configuration
renczesstefan 4c1cf75
[NAE-2182] Refactor GenericMapCache to use ConcurrentHashMap.computeI…
dominikvozr 89164d5
Merge remote-tracking branch 'origin/release/7.0.0-rev9' into NAE-2182
machacjozef 376da58
- clarified error message in createCaseByIdentifier
renczesstefan dc1394b
- corrected properties error according to rabbit ai
renczesstefan 299c4f1
- removed trailing white space from functions.md
renczesstefan a54ea6d
- clarified documentation
renczesstefan 21b597f
- added check for existing petri net version
renczesstefan 03cb8ea
Refactor cache configuration and global functions handling.
renczesstefan 173592d
Refactor cache implementation and optimize method usage
renczesstefan 8604c85
Refactor caching mechanism for improved concurrency and logic.
renczesstefan 790b359
Handle null PetriNet in reloadCachedGlobalFunctions
renczesstefan b4aef9b
Rename cacheSize to initialCapacity in GenericMapCache
renczesstefan e297242
Handle null values in GenericMapCache.put method
renczesstefan 271c93f
Fix class cast check for List elements in GenericMapCache
renczesstefan 7a57310
Refactor cache implementation to support generic element types
renczesstefan b0f3476
Evict global functions cache during reload.
renczesstefan 07aa67f
Remove unused import from CacheConfiguration.java
renczesstefan 64e0c8b
Refactor method to optimize cache eviction sequence
renczesstefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
48 changes: 39 additions & 9 deletions
48
...engine/src/main/java/com/netgrif/application/engine/configuration/CacheConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ation-engine/src/main/java/com/netgrif/application/engine/configuration/CacheMapKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.netgrif.application.engine.configuration; | ||
|
|
||
| public final class CacheMapKeys { | ||
| private CacheMapKeys() {} | ||
| public static final String ACTIONS = "actions"; | ||
| public static final String FUNCTIONS = "functions"; | ||
| public static final String GLOBAL_FUNCTIONS = "globalFunctions"; | ||
| } |
124 changes: 124 additions & 0 deletions
124
...on-engine/src/main/java/com/netgrif/application/engine/configuration/GenericMapCache.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package com.netgrif.application.engine.configuration; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.springframework.cache.Cache; | ||
| import org.springframework.cache.support.SimpleValueWrapper; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| @Slf4j | ||
| public class GenericMapCache<V, E> implements Cache { | ||
| private final String name; | ||
| private final Class<V> valueType; | ||
| private final Class<E> elementType; | ||
| private final ConcurrentHashMap<String, V> map; | ||
|
|
||
| public GenericMapCache(String name, Class<V> valueType, Class<E> elementType, int initialCapacity) { | ||
| this.name = name; | ||
| this.valueType = valueType; | ||
| this.elementType = elementType; | ||
| this.map = new ConcurrentHashMap<>(initialCapacity); | ||
| } | ||
|
|
||
| @Override public @NotNull String getName() { return name; } | ||
|
|
||
| @Override public @NotNull Object getNativeCache() { return Map.copyOf(map); } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public <T> T get(Object key, Callable<T> loader) { | ||
| final String stringKey = String.valueOf(key); | ||
| try { | ||
| V value = map.computeIfAbsent(stringKey, cacheValue -> { | ||
| try { | ||
| T computed = loader.call(); | ||
| if (computed == null) return null; | ||
| return safeCast(computed); | ||
| } | ||
| catch (Exception e) { | ||
Retoocs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
| return (T) value; | ||
| } catch (RuntimeException e) { | ||
| Throwable cause = (e.getCause() != null) ? e.getCause() : e; | ||
| throw new Cache.ValueRetrievalException(stringKey, loader, cause); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public ValueWrapper get(Object key) { | ||
| String stringKey = String.valueOf(key); | ||
| Object valueObject = map.get(stringKey); | ||
| return valueObject != null ? new SimpleValueWrapper(valueObject) : null; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T get(Object key, Class<T> type) { | ||
| String stringKey = String.valueOf(key); | ||
| Object valueObject = map.get(stringKey); | ||
| return valueObject != null ? type.cast(valueObject) : null; | ||
| } | ||
|
|
||
| @Override | ||
| public void put(Object key, Object value) { | ||
| if (value == null) { | ||
| evict(key); | ||
| return; | ||
| } | ||
| map.put(String.valueOf(key), safeCast(value)); | ||
| } | ||
|
|
||
| @Override | ||
| public void evict(Object key) { | ||
| map.remove(String.valueOf(key)); | ||
| } | ||
|
|
||
| @Override | ||
| public void clear() { | ||
| map.clear(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private V safeCast(Object value) { | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
|
|
||
| if (valueType.isInstance(value)) { | ||
| return (V) value; | ||
| } | ||
|
|
||
| // Check if the value is a list and the cache type is List<Element> | ||
| if (value instanceof List && List.class.isAssignableFrom(valueType)) { | ||
| List<?> list = (List<?>) value; | ||
|
|
||
| // Check only if the list is non-empty | ||
| if (!list.isEmpty()) { | ||
| Object firstElement = list.getFirst(); | ||
|
|
||
| // Validate element type | ||
| if (elementType != null && !elementType.isInstance(firstElement)) { | ||
| throw new ClassCastException( | ||
| String.format("Cannot cast list element of type %s to %s", | ||
| firstElement.getClass().getName(), | ||
| elementType.getName() | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return (V) list; // Safe cast to desired list type | ||
| } | ||
|
|
||
| throw new ClassCastException( | ||
| String.format("Cannot cast value of type %s to %s", | ||
| value.getClass().getName(), | ||
| valueType.getName() | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...ain/java/com/netgrif/application/engine/petrinet/service/interfaces/IPetriNetService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.