Package com.boomi.connector.util
Class ConnectorCache<K>
- java.lang.Object
-
- com.boomi.connector.util.ConnectorCache<K>
-
- Direct Known Subclasses:
BootstrapConnector.ClassLoaderCache
,CachedCredentials
,ExpiringConnectorCache
,WSCache
public class ConnectorCache<K> extends Object
Utility base class for caching per-user information across multiple connector invocations (usesConnectorContext.getConnectorCache()
to store this object). Users should subclass this class and implement thread-safe methods which generate the data to be cached on demand (no work should be done in the constructor of this object).Example:
public class MyCache extends ConnectorCache<String> { private static final ConnectorCacheFactory<String, MyCache> MY_FACTORY = new ConnectorCacheFactory<String, MyCache>() { @Override public MyCache createCache(String key, BrowseContext context) { return new MyCache(key); } }; private MyParsedWsdl _parsedWsdl; public MyCache(String url) { super(url); } public synchronized MyParsedWsdl getParsedWsdl() { if (_parsedWsdl == null) { String url = getKey(); // ... parse wsdl from url ... } return _parsedWsdl; } public static MyCache getCache(String url, BrowseContext context) { return getCache(url, context, MY_FACTORY); } }
Additionally, this cache support the ability for cache items to be invalidated (lazily). Subclasses can provide override the
isValid()
method to control when a cache should be discarded. SeeExpiringConnectorCache
for a simple implementation of a ConnectorCache which expires after a certain amount of time.
-
-
Constructor Summary
Constructors Constructor Description ConnectorCache(K key)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearCache(Object key, ConnectorContext context)
Removes the object referred to by the provided key from the cache.static <K,C extends ConnectorCache<K>,X extends ConnectorContext>
CgetCache(K key, X context, ConnectorCacheFactory<K,C,X> cacheFactory)
Returns an instance of ConnectorCache, either a previously created instance which was found in theConnectorContext.getConnectorCache()
and is still valid or a new instance created by the given cacheFactory.K
getKey()
Returns the key which for this ConnectorCache.boolean
isValid()
Returnstrue
if this cache should be considered valid,false
otherwise.
-
-
-
Constructor Detail
-
ConnectorCache
public ConnectorCache(K key)
-
-
Method Detail
-
getKey
public K getKey()
Returns the key which for this ConnectorCache.
-
isValid
public boolean isValid()
Returnstrue
if this cache should be considered valid,false
otherwise. This method will be called bygetCache(K, X, com.boomi.connector.util.ConnectorCacheFactory<K, C, X>)
whenever a ConnectorCache is retrieved. If this method returnsfalse
, the retrieved ConnectorCache will be discarded and a new one created via the ConnectorCacheFactory provided.Default implementation always returns
true
.
-
getCache
public static <K,C extends ConnectorCache<K>,X extends ConnectorContext> C getCache(K key, X context, ConnectorCacheFactory<K,C,X> cacheFactory)
Returns an instance of ConnectorCache, either a previously created instance which was found in theConnectorContext.getConnectorCache()
and is still valid or a new instance created by the given cacheFactory.- Parameters:
key
- the key by which this ConnectorCache should be cached in the connector cachecontext
- the current connector context. Note, this context should not be held by the ConnectorCache instance, but may be used to retrieve connection properties.cacheFactory
- factory which will be used to create a new ConnectorCache instance if none currently exists (or the current instance is no longer valid)- Returns:
- a valid ConnectorCache instance
-
clearCache
public static void clearCache(Object key, ConnectorContext context)
Removes the object referred to by the provided key from the cache.
-
-