Created
May 18, 2018 20:37
-
-
Save ptahchiev/6438a1137d48d3c427f0666dfcb287b4 to your computer and use it in GitHub Desktop.
cache-manager-delegate-toggle-region
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
@WriteOperation | |
public void toggleCache(@Selector String cache, @Nullable String cacheManager) { | |
NemesisCacheEntry entry = extractUniqueCacheEntry(cache, getCacheEntries((name) -> name.equals(cache), safeEqual(cacheManager))); | |
toggleCache(entry); | |
} | |
private NemesisCacheEntry extractUniqueCacheEntry(String cache, List<NemesisCacheEntry> entries) { | |
if (entries.size() > 1) { | |
throw new NonUniqueCacheException(cache, entries.stream().map(NemesisCacheEntry::getCacheManager).distinct().collect(Collectors.toList())); | |
} | |
return (entries.isEmpty() ? null : entries.get(0)); | |
} | |
private void toggleCache(NemesisCacheEntry entry) { | |
CacheManager cacheManager = this.cacheManagers.get(entry.getCacheManager()); | |
if (cacheManager instanceof PlatformCacheManager) { | |
if (entry.isEnabled()) { | |
((PlatformCacheManager) cacheManager).disableCache(entry.getName()); | |
} else { | |
((PlatformCacheManager) cacheManager).enableCache(entry.getName()); | |
} | |
return; | |
} | |
throw new IllegalArgumentException("CacheManager is not instance of PlatformCacheManager: " + cacheManager); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment