All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.elide.datastores.aggregation.cache.CaffeineCache Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020, Yahoo Inc.
 * Licensed under the Apache License, Version 2.0
 * See LICENSE file in project root for terms.
 */

package com.yahoo.elide.datastores.aggregation.cache;

import com.yahoo.elide.datastores.aggregation.query.QueryResult;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * A basic local-only cache.
 */
public class CaffeineCache implements Cache {
    public static final int DEFAULT_MAXIMUM_ENTRIES = 1024;

    private final com.github.benmanes.caffeine.cache.Cache cache;

    public CaffeineCache(int maximumSize, Duration expireAfterWrite) {
        cache = Caffeine.newBuilder()
                .maximumSize(maximumSize)
                .expireAfterWrite(expireAfterWrite.toMinutes(), TimeUnit.MINUTES)
                .recordStats()
                .build();
    }

    @Override
    public QueryResult get(Object key) {
        return cache.getIfPresent(key);
    }

    @Override
    public void put(Object key, QueryResult result) {
        cache.put(key, result);
    }

    public com.github.benmanes.caffeine.cache.Cache getImplementation() {
        return cache;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy