...
Code Block |
---|
language | java |
---|
title | DefaultPartialCache |
---|
|
/** Default implementation of {@link LookupCache}. */
@PublicEvolving
public class DefaultLookupCache implements LookupCache {
private final Duration expireAfterAccessDuration;
private final Duration expireAfterWriteDuration;
private final Long maximumSize;
private final boolean cacheMissingKey;
private DefaultLookupCache(
Duration expireAfterAccessDuration,
Duration expireAfterWriteDuration,
Long maximumSize,
boolean CacheMissingKey) {
this.expireAfterAccessDuration = expireAfterAccessDuration;
this.expireAfterWriteDuration = expireAfterWriteDuration;
this.initialCapacity = initialCapacity;
this.maximumSize = maximumSize;
this.cacheMissingKey = cacheMissingKeyl
}
public static Builder newBuilder() {
return new Builder();
}
public static class Builder {
private Duration expireAfterAccessDuration;
private Duration expireAfterWriteDuration;
private Long maximumSize;
private Boolean cacheMissingKey;
public DefaultLookupCache.Builder expireAfterAccess(Duration duration) {
expireAfterAccessDuration = duration;
return this;
}
public DefaultLookupCache.Builder expireAfterWrite(Duration duration) {
expireAfterWriteDuration = duration;
return this;
}
public DefaultLookupCache.Builder maximumSize(long maximumSize) {
this.maximumSize = maximumSize;
return this;
}
public DefaultLookupCacheBuilder buildcacheMissingKey(boolean cacheMissingKey) {
returnthis.cacheMissingKey new= DefaultLookupCache(cacheMissingKey;
return this;
expireAfterAccessDuration,
}
public DefaultLookupCache build() {
return new DefaultLookupCache(
expireAfterAccessDuration,
expireAfterWriteDuration,
maximumSize,
cacheMissingKey);
}
}
} |
CacheMetricGroup
An interface defining all cache related metric:
...
Code Block |
---|
language | java |
---|
title | LookupFunctionProvider |
---|
|
//**
* Provider for creating {@link LookupFunction} and {@link LookupCache} if caching should be enabled
* for the lookup table.
*/
@PublicEvolving
public interface PartialCachingLookupProvider extends LookupTableSource.LookupRuntimeProvider {
/** Creates a builder of {@link PartialCachingLookupProvider}. */
static Builder newBuilder() {
return new Builder();
}
/** Creates an {@link LookupFunction} instance. */
LookupFunction createLookupFunction();
/**
* Gets the instance of {@link LookupCache}.
*
* <p>This cache will be initialized by {@link LookupCache#open} during runtime execution and
* used for optimizing the access to external lookup table.
*
* @return an {@link Optional} of {@link LookupCache}, or an empty {@link Optional} if caching
* shouldn't be applies to the lookup table.
*/
Optional<LookupCache> getCache();
/**
Builder class for {@link PartialCachingLookupProvider}. */
Whether the missing keyclass (key fields without any matching value rows) should be stored in theBuilder {
private LookupFunction lookupFunction;
* cache.
private LookupCache *cache;
* <p>Please note thatprivate this option is required if {@link #getCache} returns a non-empty
* instance. If the cache factory is empty, the return value of this function will be ignored.
Boolean cacheMissingKey;
/** Sets lookup function. */
public Builder withLookupFunction(LookupFunction lookupFunction) {
*
this.lookupFunction = *lookupFunction;
@return true if a null or empty value should bereturn storedthis;
in the cache.
*/}
Optional<Boolean> cacheMissingKey();
/** Enables Buildercaching and classsets forthe {@linkcache PartialCachingLookupProvider}factory. */
class Builder {
public Builder withCache(LookupCache cache, boolean private LookupFunction lookupFunction;
cacheMissingKey) {
privatethis.cache LookupCache= cache;
private Boolean this.cacheMissingKey = cacheMissingKey;
/** Sets lookup function. */return this;
public Builder withLookupFunction(LookupFunction lookupFunction) {}
public PartialCachingLookupProvider this.lookupFunction = lookupFunction;build() {
return this;...
}
/** Enables caching and sets the cache factory. */
public Builder withCache(LookupCache cache, boolean cacheMissingKey) {
this.cache = cache;
this.cacheMissingKey = cacheMissingKey;
return this;
}
public PartialCachingLookupProvider build() {
...
}
}
} |
AsyncPartialCachingLookupProvider
AsyncPartialCachingLookupProvider
Code Block |
---|
language | java |
---|
title | AsyncLookupFunctionProvider |
---|
|
/**
* Provider for creating {@link AsyncLookupFunction} and {@link LookupCache} if caching should be
* enabled for the lookup table.
*/
@PublicEvolving
public interface AsyncPartialCachingLookupProvider extends LookupTableSource.LookupRuntimeProvider {
/** Creates a builder of {@link AsyncPartialCachingLookupProvider}. */
static AsyncPartialCachingLookupProvider.Builder newBuilder() {
return new AsyncPartialCachingLookupProvider.Builder();
}
/** Creates an {@link AsyncLookupFunction} instance. |
Code Block |
---|
language | java |
---|
title | AsyncLookupFunctionProvider |
---|
|
/**
* Provider for creating {@link AsyncLookupFunction} and {@link LookupCache} if caching should be
* enabled for the lookup table.
*/
@PublicEvolving
public interface AsyncPartialCachingLookupProvider extends LookupTableSource.LookupRuntimeProvider {
/** Creates a builder of {@link AsyncPartialCachingLookupProvider}. */
static AsyncPartialCachingLookupProvider.Builder newBuilder() {
return new AsyncPartialCachingLookupProvider.Builder();
}
/** Creates an {@link AsyncLookupFunction} instance. */
AsyncLookupFunction createAsyncLookupFunction();
/**
* Gets the {@link LookupCache} for creating lookup cache.
*
* <p>This factory will be used for creating an instance of cache during runtime execution for
* optimizing the access to external lookup table.
*
* @return an {@link Optional} of {@link LookupCache}, or an empty {@link Optional} if caching
* shouldn't be applies to the lookup table.
*/
Optional<LookupCache>AsyncLookupFunction getCachecreateAsyncLookupFunction();
/**
* WhetherGets the missing{@link keyLookupCache} (keyfor fieldscreating withoutlookup anycache.
matching value rows) should be*
stored in the
* <p>This factory *will cache.
be used for creating an *
instance of cache during runtime *execution <p>Pleasefor
note that this option is* requiredoptimizing ifthe {@linkaccess #getCache}to returnsexternal a non-emptylookup table.
*
instance. If the cache factory* is@return empty,an the return value{@link Optional} of this function will be ignored.
*{@link LookupCache}, or an empty {@link Optional} if caching
* @return true if a null or empty value should be stored in the cache shouldn't be applies to the lookup table.
*/
Optional<Boolean>Optional<LookupCache> cacheMissingKeygetCache();
/** Builder class for {@link AsyncPartialCachingLookupProvider}. */
class Builder {
private AsyncLookupFunction asyncLookupFunction;
private LookupCache cache;
private Boolean cacheMissingKey;
/** Sets lookup function. */
public AsyncPartialCachingLookupProvider.Builder withLookupFunction(
AsyncLookupFunction asyncLookupFunction) {
this.asyncLookupFunction = asyncLookupFunction;
return this;
}
/** Enables caching and sets the cache factory. */
public AsyncPartialCachingLookupProvider.Builder withCache(
LookupCache cache, boolean cacheMissingKey) {
this.cache = cache;
this.cacheMissingKey = cacheMissingKey;
return this;
}
public AsyncPartialCachingLookupProvider build() {
...
}
}
} |
...