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

com.alachisoft.ncache.client.internal.caching.ExpirationUtil Maven / Gradle / Ivy

package com.alachisoft.ncache.client.internal.caching;

import com.alachisoft.ncache.runtime.caching.expiration.Expiration;
import com.alachisoft.ncache.runtime.caching.expiration.ExpirationConstants;
import com.alachisoft.ncache.runtime.caching.expiration.ExpirationType;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import com.alachisoft.ncache.runtime.util.TimeSpan;

import java.text.ParseException;
import java.util.Date;


class ExpirationUtil {

    public static Expiration getExpiration(Date absoluteExpiration, TimeSpan slidingExpiration) throws ParseException {
        Expiration modernSlidingExpiration = new Expiration(ExpirationType.None);
        Expiration modernAbsoluteExpiration = new Expiration(ExpirationType.None);

        if(absoluteExpiration != null && slidingExpiration != null) {

            if (slidingExpiration.equals(ExpirationConstants.SlidingDefaultExpiration)) {
                 modernSlidingExpiration = new Expiration(ExpirationType.DefaultSliding);
            } else if (slidingExpiration.equals( ExpirationConstants.SlidingDefaultLongerExpiration)) {
                modernSlidingExpiration = new Expiration(ExpirationType.DefaultSlidingLonger);
            } else if (!(slidingExpiration.equals(ExpirationConstants.SlidingNoneExpiration))) {
                modernSlidingExpiration = new Expiration(ExpirationType.Sliding, slidingExpiration);
            }


            if (NCDateTime.getUTCDate(absoluteExpiration).equals(NCDateTime.getUTCDate(ExpirationConstants.AbsoluteDefaultExpiration))) {
                modernAbsoluteExpiration = new Expiration(ExpirationType.DefaultAbsolute);
            } else if (NCDateTime.getUTCDate(absoluteExpiration).equals(NCDateTime.getUTCDate(ExpirationConstants.AbsoluteDefaultLongerExpiration))) {
                modernAbsoluteExpiration = new Expiration(ExpirationType.DefaultAbsoluteLonger);
            } else if (!(NCDateTime.getUTCDate(absoluteExpiration).equals(NCDateTime.getUTCDate(ExpirationConstants.AbsoluteNoneExpiration)))) {

                try {
                    modernAbsoluteExpiration = new Expiration(ExpirationType.Absolute, TimeSpan.subtract(absoluteExpiration, new NCDateTime(new Date()).getLocalizedDate()));
                } catch (IllegalArgumentException ignored) {
                }
            }
        }


        return modernAbsoluteExpiration.getExpirationType() == ExpirationType.None ? modernSlidingExpiration : modernAbsoluteExpiration;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy