Class 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 (uses 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<String> {
         private static final ConnectorCacheFactory<String, MyCache> MY_FACTORY =
                 new ConnectorCacheFactory<String, MyCache>() {
                     &#64;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 Detail

      • ConnectorCache

        public ConnectorCache​(K key)
    • Method Detail

      • getKey

        public K getKey()
        Returns the key which for this ConnectorCache.
      • isValid

        public boolean isValid()
        Returns 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.

      • 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 the ConnectorContext.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 cache
        context - 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.