diff options
author | Steve Smokowski <ss835w@att.com> | 2020-11-30 14:49:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-11-30 14:49:48 +0000 |
commit | 0fb130d77336e7476bbc09cc453efabf6fa1b16e (patch) | |
tree | bc26a41332365895dd4c9949ff229fbd49f46a15 /graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java | |
parent | aec0236281f227a0a68b38ca7b0e56e50ffa95b7 (diff) | |
parent | a16231657fe29334a589c98290ac8b6b2710a144 (diff) |
Merge "add caching to graph inventory client"
Diffstat (limited to 'graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java')
-rw-r--r-- | graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java new file mode 100644 index 0000000000..0f290ff620 --- /dev/null +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/FlushCache.java @@ -0,0 +1,41 @@ +package org.onap.aaiclient.client; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.cache.CacheManager; +import javax.cache.Caching; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientResponseContext; +import javax.ws.rs.client.ClientResponseFilter; +import org.apache.cxf.jaxrs.client.cache.Key; +import org.onap.so.client.CacheProperties; + +public class FlushCache implements ClientResponseFilter { + + private static final Set<String> modifyMethods = + new HashSet<>(Arrays.asList(HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.PUT, HttpMethod.POST)); + + private final CacheProperties props; + + public FlushCache(CacheProperties props) { + this.props = props; + } + + @Override + public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { + + if (responseContext.getStatus() >= 200 && responseContext.getStatus() <= 299) { + if (FlushCache.modifyMethods.contains(requestContext.getMethod())) { + + CacheManager cacheManager = Caching.getCachingProvider().getCacheManager( + Caching.getCachingProvider().getDefaultURI(), Thread.currentThread().getContextClassLoader()); + cacheManager.getCache(props.getCacheName()).remove( + new Key(requestContext.getUri(), requestContext.getAcceptableMediaTypes().get(0).toString())); + } + } + } + +} |