-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rathnapandi
committed
Mar 12, 2024
1 parent
0a03578
commit 9deb6a6
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
modules/apim-adapter/src/main/java/com/axway/apim/lib/APIMCLICache.java
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.axway.apim.lib; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.ehcache.Cache; | ||
import org.ehcache.config.CacheRuntimeConfiguration; | ||
import org.ehcache.spi.loaderwriter.BulkCacheLoadingException; | ||
import org.ehcache.spi.loaderwriter.BulkCacheWritingException; | ||
import org.ehcache.spi.loaderwriter.CacheLoadingException; | ||
import org.ehcache.spi.loaderwriter.CacheWritingException; | ||
|
||
public class APIMCLICache<K, V> implements Cache<K, V> { | ||
|
||
private final Cache<K, V> cache; | ||
private final String prefix; | ||
|
||
public APIMCLICache(Cache<K, V> cache, String prefix) { | ||
super(); | ||
this.cache = cache; | ||
this.prefix = prefix; | ||
} | ||
|
||
@Override | ||
public boolean containsKey(K key) { | ||
return this.cache.containsKey(getPrefixedKey(key)); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
this.cache.clear(); | ||
} | ||
|
||
@Override | ||
public V get(K key) throws CacheLoadingException { | ||
return this.cache.get(getPrefixedKey(key)); | ||
} | ||
|
||
@Override | ||
public Map<K, V> getAll(Set<? extends K> arg0) throws BulkCacheLoadingException { | ||
throw new UnsupportedOperationException("Method getAll is not implemented for the APIMCLICache"); | ||
} | ||
|
||
@Override | ||
public CacheRuntimeConfiguration<K, V> getRuntimeConfiguration() { | ||
return this.cache.getRuntimeConfiguration(); | ||
} | ||
|
||
@Override | ||
public Iterator<Entry<K, V>> iterator() { | ||
return this.cache.iterator(); | ||
} | ||
|
||
@Override | ||
public void put(K key, V value) throws CacheWritingException { | ||
this.cache.put(getPrefixedKey(key), value); | ||
} | ||
|
||
@Override | ||
public void putAll(Map<? extends K, ? extends V> arg0) throws BulkCacheWritingException { | ||
throw new UnsupportedOperationException("Method putAll is not implemented for the APIMCLICache"); | ||
} | ||
|
||
@Override | ||
public V putIfAbsent(K key, V value) throws CacheLoadingException, CacheWritingException { | ||
return this.cache.putIfAbsent(getPrefixedKey(key), value); | ||
} | ||
|
||
@Override | ||
public void remove(K key) throws CacheWritingException { | ||
this.cache.remove(getPrefixedKey(key)); | ||
} | ||
|
||
@Override | ||
public boolean remove(K key, V value) throws CacheWritingException { | ||
return this.cache.remove(getPrefixedKey(key), value); | ||
} | ||
|
||
@Override | ||
public void removeAll(Set<? extends K> arg0) throws BulkCacheWritingException { | ||
throw new UnsupportedOperationException("Method removeAll is not implemented for the APIMCLICache"); | ||
} | ||
|
||
@Override | ||
public V replace(K key, V value) throws CacheLoadingException, CacheWritingException { | ||
return this.cache.replace(getPrefixedKey(key), value); | ||
} | ||
|
||
@Override | ||
public boolean replace(K key, V value1, V value2) throws CacheLoadingException, CacheWritingException { | ||
return this.cache.replace(getPrefixedKey(key), value1, value2); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private K getPrefixedKey(K key) { | ||
return (K) (prefix+key); | ||
} | ||
} |
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
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