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

com.github.javaclub.sword.cache.LoadingCache Maven / Gradle / Ivy

The newest version!
/*
 * @(#)LoadingCache.java	2024-04-03 12:00:57
 *
 * Copyright (c) 2024 - 2099. All Rights Reserved.
 *
 */

package com.github.javaclub.sword.cache;

/**
 * LoadingCache
 *
 * @author Gerald Chen
 * @version $Id: LoadingCache.java 2024-04-03 12:00:57 Exp $
 */
public abstract class LoadingCache {
	
	private Long refreshTime = 0L;
	
	public Long getRefreshTime() {
		return refreshTime;
	}

	/**
     * 重置缓存刷新时间
     */
	public void setRefreshTime(Long refreshTime) {
		this.refreshTime = refreshTime;
	}

	/**
     * 缓存初始化设置
     */
	public abstract void init();

    /**
     * 获取缓存
     *
     * @param 
     * @return 缓存数据
     */
    public abstract  T get();

    /**
     * 清理缓存
     */
    public abstract void clear();
    
    /**
     * 预设缓存存活时间
     */
    public abstract long getTimeToLiveMillis();

    /**
     * 重新加载
     */
    public synchronized void reload() {
        clear();
        init();
        setRefreshTime(System.currentTimeMillis());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy