Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

NameTypeUnitDescription
numCachedRecordGaugeRecordsThe number of records in cache.
numCachedBytesGaugeBytesThe number of bytes used by cache.
hitCountCounter
The number of cache hits
missCountCounter
The number of cache misses, which leads to loading operations
numBytesLoadedTotalCounterBytesThe number of bytes totally loaded to the cache
numRecordsLoadedTotalCounterRecordsThe number of records totally loaded to the cache
numLoadFailureCounter
The number of load failures
latestLoadTimeGaugemsThe time spent for the latest load operation

...

Code Block
languagejava
titleCache
/**
 * A semi-persistent mapping from keys to values. Cache entries are manually added using {@link
 * #put(Object, Object)}, and are stored in the cache until either evicted or manually invalidated.
 *
 * <p>Implementations of this interface are expected to be thread-safe, and can be safely accessed
 * by multiple concurrent threads.
 *
 * @param <K> key
 * @param <V> value
 */
public interface Cache<K, V> {

    /**
     * Returns the value associated with the key in the cache, or obtain the value by loader if the
     * key doesn't exist.
     *
     * @param key key - the key whose associated value is to be returned
     * @param loader - the loader for loading associated values from external system
     * @return The value associated with the key
     * @throws IOException if any exception was thrown while loading the value
     */
    V get(K key, Callable<? extends V> loader) throws IOException;

    /**
     * Associates the specified value with the specified key in the cache. If the cache previously
     * contained a value associated with the key, the old value is replaced by the specified value.
     *
     * @return the previous value associated with key, or null if there was no mapping for key.
     * @param key - key with which the specified value is to be associated
     * @param value – value to be associated with the specified key
     */
    V put(K key, V value);

    /**
     * Copies all the mappings from the specified map to the cache. The effect of this call is
     * equivalent to that of calling {@code put(k, v)} on this map once for each mapping from key
     * {@code k} to value {@code v} in the specified map. The behavior of this operation is
     * undefined if the specified map is modified while the operation is in progress.
     */
    void putAll(Map<? extends K, ? extends V> m);

    /** Delete all entries in the cache. */
    void clean();

    /** Returns the number of key-value mappings in the cache. */
    long size();
}

CacheMetricGroup

An interface defining all cache related metric:

Code Block
languagejava
titleCacheMetricGroup
/** Pre-defined metrics for {@code Cache}. */
public interface CacheMetricGroup {

    /** The number of cache hits. */
    Counter getHitCounter();

    /** The number of cache misses. */
    Counter getMissCounter();

    /** The number of records totally loaded to the cache. */
    Counter getNumRecordsLoadedTotalCounter();

    /** The number of bytes totally loaded to the cache. */
    Counter getNumBytesLoadedTotalCounter();

    /** The time spent for the latest load operation. */
    Gauge<Long> getLatestLoadTimeGauge();

    /** The number of load failures. */
    Counter getNumLoadFailureCounter();

    /** The number of records in cache. */
    void setNumCachedRecordsGauge(Gauge<Long> numCachedRecordsGauge);

    /** The number of bytes used by cache. */
    void setNumCachedBytesGauge(Gauge<Long> numCachedBytesGauge);
}

CacheConfig

Code Block
languagejava
titleCacheConfig
@PublicEvolving
/**
 * Configuration for building caches.
 */
public class CacheConfig {

	// Type of the cache
    private CacheType cacheType;

	// Time-to-live (TTL) of entries in cache
    private Duration ttl;

	// Maximum number of entries that the cache could contain
    private long maxSize;
	
	
    public enum CacheType {
        ALL,
        LRU,
        NONE
    }
}

CachingTableFunction

Code Block
languagejava
titleCachingTableFunction
@PublicEvolving
public class CachingTableFunction<T, K, V> extends TableFunction<T> {

    private Cache<K, V> cache;
    private final CacheConfig cacheConfig;

    public CachingTableFunction(CacheConfig cacheConfig) {
        this.cacheConfig = cacheConfig;
    }

    @Override
    public void open(FunctionContext context) throws Exception {
        // Initialize cache with metric group
    }

    protected Cache<K, V> getCache() {
        return cache;
    }
}


Proposed Changes

Describe the new thing you want to do in appropriate detail. This may be fairly extensive and have large subsections of its own. Or it may be a few sentences. Use judgement based on the scope of the change.

...