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

org.zodiac.webui.config.WebUiExtensionCacheInfo Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.webui.config;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import org.springframework.boot.convert.DurationUnit;
import org.springframework.http.CacheControl;

public class WebUiExtensionCacheInfo {

    /**
     * include "max-age" directive in Cache-Control http header.
     */
    @Nullable
    @DurationUnit(ChronoUnit.SECONDS)
    private Duration maxAge = Duration.ofSeconds(3600);

    /**
     * include "no-cache" directive in Cache-Control http header.
     */
    private boolean noCache = false;

    /**
     * include "no-store" directive in Cache-Control http header.
     */
    private boolean noStore = false;

    public WebUiExtensionCacheInfo() {
    }

    public Duration getMaxAge() {
        return maxAge;
    }

    public WebUiExtensionCacheInfo setMaxAge(Duration maxAge) {
        this.maxAge = maxAge;
        return this;
    }

    public boolean isNoCache() {
        return noCache;
    }

    public WebUiExtensionCacheInfo setNoCache(boolean noCache) {
        this.noCache = noCache;
        return this;
    }

    public boolean isNoStore() {
        return noStore;
    }

    public WebUiExtensionCacheInfo setNoStore(boolean noStore) {
        this.noStore = noStore;
        return this;
    }

    public CacheControl toCacheControl() {
        if (Boolean.TRUE.equals(this.noStore)) {
            return CacheControl.noStore();
        }
        if (Boolean.TRUE.equals(this.noCache)) {
            return CacheControl.noCache();
        }
        if (this.maxAge != null) {
            return CacheControl.maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS);
        }
        return CacheControl.empty();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy