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

com.aliyuncs.utils.CacheTimeHelper Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 4.7.3
Show newest version
package com.aliyuncs.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CacheTimeHelper {
    
    private static long endPointCacheTime = 3600L; //Seconds
    private static Map lastClearTimeMap = new HashMap();
    
    public static boolean CheckEndPointCacheIsExpire(String product, String regionId)
    {
        String key = product + "_" + regionId;
        Date lastClearTime;
        if (null != lastClearTimeMap.get(key)) {
            lastClearTime = lastClearTimeMap.get(key);
        } else {
            lastClearTime = new Date();
            lastClearTimeMap.put(key, lastClearTime);
        }
        Date currentTime = new Date();
        long elapsedTime = (currentTime.getTime() - lastClearTime.getTime())/1000L;
        if (endPointCacheTime < elapsedTime)
        {
            return true;
        }

        return false;
    }
    
    public static void addLastClearTimePerProduct(String product, String regionId, Date date) {
        String key = product + "_" + regionId;
        lastClearTimeMap.put(key, date);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy