Class StorageProviderCache

java.lang.Object
org.elasticsearch.xpack.esql.datasources.cache.StorageProviderCache
All Implemented Interfaces:
Closeable, AutoCloseable

public class StorageProviderCache extends Object implements Closeable
LRU cache for StorageProvider instances, keyed by (scheme, config).

When a query supplies a WITH clause (non-empty config), a cloud client (S3, GCS, Azure) is constructed per StorageProvider. Without this cache, consecutive calls to StorageProviderRegistry.createProvider() with the same config would each create a new client instance and its associated connection pool. This cache ensures that the same config reuses the same client across calls.

Entries expire after DEFAULT_TTL_MINUTES minutes of inactivity. On eviction, the removed provider is closed so that connection pools and cloud resources are released.

The cache is bounded at MAX_ENTRIES entries — large enough to serve typical workloads (a handful of distinct S3 credentials) while preventing unbounded growth when queries use many distinct configs.

Thread-safe: backed by Cache.computeIfAbsent(K, org.elasticsearch.common.cache.CacheLoader<K, V>).

  • Constructor Details

    • StorageProviderCache

      public StorageProviderCache()
  • Method Details

    • getOrCreate

      Returns a cached provider for the given key, or creates one via the factory on a cache miss. The factory is invoked at most once per key under concurrent access.
      Parameters:
      key - the cache key (scheme + config)
      factory - supplier to create the provider on a miss; may throw any exception
      Returns:
      the cached or newly created provider, paired with its consumed-key set
      Throws:
      Exception - if the factory throws during a cache miss
    • invalidateAll

      public void invalidateAll()
      Removes all entries and closes the associated providers.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable