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

org.babyfish.jimmer.sql.cache.Cache Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.cache;

import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.SortedMap;

public interface Cache {

    @NotNull
    ImmutableType type();

    @Nullable ImmutableProp prop();

    @Nullable default V get(@NotNull K key, @NotNull CacheEnvironment env) {
        return getAll(Collections.singleton(key), env).get(key);
    }

    @NotNull Map getAll(@NotNull Collection keys, @NotNull CacheEnvironment env);

    default void delete(@NotNull K key) {
        deleteAll(Collections.singleton(key), null);
    }

    default void delete(@NotNull K key, Object reason) {
        deleteAll(Collections.singleton(key), reason);
    }

    default void deleteAll(@NotNull Collection keys) {
        deleteAll(keys, null);
    }

    void deleteAll(@NotNull Collection keys, @Nullable Object reason);

    interface Parameterized extends Cache {

        @Nullable
        default V get(
                @NotNull K key,
                @NotNull SortedMap parameterMap,
                @NotNull CacheEnvironment env
        ) {
            return getAll(Collections.singleton(key), parameterMap, env).get(key);
        }

        @NotNull
        Map getAll(
                @NotNull Collection keys,
                @NotNull SortedMap parameterMap,
                @NotNull CacheEnvironment env
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy