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

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

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

import org.babyfish.jimmer.sql.JSqlClient;

import java.util.Collection;

public interface CacheOperator {

    default void initialize(JSqlClient sqlClient) {}

    void delete(UsedCache cache, Object key, Object reason);

    void deleteAll(UsedCache cache, Collection keys, Object reason);

    static boolean isSuspending() {
        return Suspending.LOCAL.get() != null;
    }

    static void suspending(Runnable block) {
        if (Suspending.LOCAL.get() != null) {
            block.run();
        } else {
            Suspending.LOCAL.set(Suspending.INSTANCE);
            try {
                block.run();
            } finally {
                Suspending.LOCAL.remove();
            }
        }
    }
}

class Suspending {
    static final ThreadLocal LOCAL = new ThreadLocal<>();
    static final Suspending INSTANCE = new Suspending();
    private Suspending() {}
}