public class ConnectorCache<K> extends Object
ConnectorContext.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{ private static final ConnectorCacheFactory MY_FACTORY = new ConnectorCacheFactory () { @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. See ExpiringConnectorCache
for a simple implementation of a ConnectorCache which expires after a certain amount of time.
Constructor and Description |
---|
ConnectorCache(K key) |
Modifier and Type | Method and 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> |
getCache(K key,
X context,
ConnectorCacheFactory<K,C,X> cacheFactory)
Returns an instance of ConnectorCache, either a previously created instance which was found in the
ConnectorContext.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()
Returns
true if this cache should be considered valid, false otherwise. |
public ConnectorCache(K key)
public K getKey()
public boolean isValid()
true
if this cache should be considered valid, false
otherwise. This method will be
called by getCache(K, X, com.boomi.connector.util.ConnectorCacheFactory<K, C, X>)
whenever a ConnectorCache is retrieved. If this method returns false
, the
retrieved ConnectorCache will be discarded and a new one created via the ConnectorCacheFactory provided.
Default implementation always returns true
.
public static <K,C extends ConnectorCache<K>,X extends ConnectorContext> C getCache(K key, X context, ConnectorCacheFactory<K,C,X> cacheFactory)
ConnectorContext.getConnectorCache()
and is still valid or a new instance created by the given
cacheFactory.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)public static void clearCache(Object key, ConnectorContext context)