forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable cache store and load only if a remote store is used
Closes keycloak#10803 Closes keycloak#24766 Signed-off-by: Alexander Schwartz <[email protected]> Co-authored-by: daviddelannoy <[email protected]>
- Loading branch information
1 parent
62d5eb0
commit a45934a
Showing
4 changed files
with
33 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import org.infinispan.Cache; | ||
import org.infinispan.context.Flag; | ||
|
||
import static org.keycloak.connections.infinispan.InfinispanUtil.getRemoteStores; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Marek Posolda</a> | ||
*/ | ||
|
@@ -40,17 +42,31 @@ public static <K, V> AdvancedCache<K, V> localCache(Cache<K, V> cache) { | |
* @param cache | ||
* @return Cache with the flags applied. | ||
*/ | ||
public static <K, V> AdvancedCache<K, V> skipCacheLoaders(Cache<K, V> cache) { | ||
return cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD, Flag.SKIP_CACHE_STORE); | ||
public static <K, V> AdvancedCache<K, V> skipCacheLoadersIfRemoteStoreIsEnabled(Cache<K, V> cache) { | ||
if (!getRemoteStores(cache).isEmpty()) { | ||
// Disabling of the cache load and cache store is only needed when a remote store is used and handled separately. | ||
return cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD, Flag.SKIP_CACHE_STORE); | ||
} else { | ||
// If there is no remote store, use write through for all stores of the cache. | ||
// Mixing remote and non-remote caches is not supported. | ||
return cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD); | ||
} | ||
} | ||
|
||
/** | ||
* Adds {@link Flag#SKIP_CACHE_STORE} flag to the cache. | ||
* @param cache | ||
* @return Cache with the flags applied. | ||
*/ | ||
public static <K, V> AdvancedCache<K, V> skipCacheStore(Cache<K, V> cache) { | ||
return cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE); | ||
public static <K, V> AdvancedCache<K, V> skipCacheStoreIfRemoteCacheIsEnabled(Cache<K, V> cache) { | ||
if (!getRemoteStores(cache).isEmpty()) { | ||
// Disabling of the cache load and cache store is only needed when a remote store is used and handled separately. | ||
return cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE); | ||
} else { | ||
// If there is no remote store, use write through for all stores of the cache. | ||
// Mixing remote and non-remote caches is not supported. | ||
return cache.getAdvancedCache(); | ||
} | ||
} | ||
|
||
} |
This file contains 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 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 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