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

com.yandex.ydb.table.impl.QueryCache Maven / Gradle / Ivy

There is a newer version: 1.45.6
Show newest version
package com.yandex.ydb.table.impl;

import javax.annotation.Nullable;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;


/**
 * @author Sergey Polovko
 */
final class QueryCache {

    private final Cache cache;

    QueryCache(int maxSize) {
        this.cache = CacheBuilder.newBuilder()
            .maximumSize(maxSize)
            .build();
    }

    @Nullable
    DataQueryImpl find(String text) {
        String key = DataQueryImpl.makeHash(text);
        return cache.getIfPresent(key);
    }

    void put(DataQueryImpl query) {
        cache.put(query.getTextHash(), query);
    }

    void remove(DataQueryImpl query) {
        cache.invalidate(query.getTextHash());
    }

    void clear() {
        cache.asMap().clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy