Class StorageProviderCache
- All Implemented Interfaces:
Closeable,AutoCloseable
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>).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCache key that combines the URI scheme with the config map.static interfaceSupplier invoked on cache miss; returns the provider plus the keys it consumed from config. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Returns a cached provider for the given key, or creates one via the factory on a cache miss.voidRemoves all entries and closes the associated providers.
-
Constructor Details
-
StorageProviderCache
public StorageProviderCache()
-
-
Method Details
-
getOrCreate
public Configured<StorageProvider> getOrCreate(StorageProviderCache.CacheKey key, StorageProviderCache.ProviderFactory factory) throws Exception 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-