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

com.hecloud.runtime.database.cache.DeleteCache Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.hecloud.runtime.database.cache;

import java.util.LinkedHashMap;
import java.util.Optional;

/**
 * 删除SQL语句缓存
 *
 * @author LoveinBJ
 */
public class DeleteCache extends LinkedHashMap {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private int capacity = 16;

    public DeleteCache(int capacity) {
        super(16, 0.75f, true);
        if (capacity > 0) {
            this.capacity = capacity;
        }
    }

    @Override
    protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
        return super.size() > capacity;
    }

    public synchronized void putCache(String key, String value) {
        this.put(key, value);
    }

    public synchronized String getCache(String key) {
        String value = this.get(key);
        Optional.ofNullable(value).ifPresent(data -> this.put(key, data));
        return value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy