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

com.azure.resourcemanager.frontdoor.models.CacheConfiguration Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.frontdoor.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.time.Duration;

/**
 * Caching settings for a caching-type route. To disable caching, do not provide a cacheConfiguration object.
 */
@Fluent
public final class CacheConfiguration implements JsonSerializable {
    /*
     * Treatment of URL query terms when forming the cache key.
     */
    private FrontDoorQuery queryParameterStripDirective;

    /*
     * query parameters to include or exclude (comma separated).
     */
    private String queryParameters;

    /*
     * Whether to use dynamic compression for cached content
     */
    private DynamicCompressionEnabled dynamicCompression;

    /*
     * The duration for which the content needs to be cached. Allowed format is in ISO 8601 format
     * (http://en.wikipedia.org/wiki/ISO_8601#Durations). HTTP requires the value to be no more than a year
     */
    private Duration cacheDuration;

    /**
     * Creates an instance of CacheConfiguration class.
     */
    public CacheConfiguration() {
    }

    /**
     * Get the queryParameterStripDirective property: Treatment of URL query terms when forming the cache key.
     * 
     * @return the queryParameterStripDirective value.
     */
    public FrontDoorQuery queryParameterStripDirective() {
        return this.queryParameterStripDirective;
    }

    /**
     * Set the queryParameterStripDirective property: Treatment of URL query terms when forming the cache key.
     * 
     * @param queryParameterStripDirective the queryParameterStripDirective value to set.
     * @return the CacheConfiguration object itself.
     */
    public CacheConfiguration withQueryParameterStripDirective(FrontDoorQuery queryParameterStripDirective) {
        this.queryParameterStripDirective = queryParameterStripDirective;
        return this;
    }

    /**
     * Get the queryParameters property: query parameters to include or exclude (comma separated).
     * 
     * @return the queryParameters value.
     */
    public String queryParameters() {
        return this.queryParameters;
    }

    /**
     * Set the queryParameters property: query parameters to include or exclude (comma separated).
     * 
     * @param queryParameters the queryParameters value to set.
     * @return the CacheConfiguration object itself.
     */
    public CacheConfiguration withQueryParameters(String queryParameters) {
        this.queryParameters = queryParameters;
        return this;
    }

    /**
     * Get the dynamicCompression property: Whether to use dynamic compression for cached content.
     * 
     * @return the dynamicCompression value.
     */
    public DynamicCompressionEnabled dynamicCompression() {
        return this.dynamicCompression;
    }

    /**
     * Set the dynamicCompression property: Whether to use dynamic compression for cached content.
     * 
     * @param dynamicCompression the dynamicCompression value to set.
     * @return the CacheConfiguration object itself.
     */
    public CacheConfiguration withDynamicCompression(DynamicCompressionEnabled dynamicCompression) {
        this.dynamicCompression = dynamicCompression;
        return this;
    }

    /**
     * Get the cacheDuration property: The duration for which the content needs to be cached. Allowed format is in ISO
     * 8601 format (http://en.wikipedia.org/wiki/ISO_8601#Durations). HTTP requires the value to be no more than a year.
     * 
     * @return the cacheDuration value.
     */
    public Duration cacheDuration() {
        return this.cacheDuration;
    }

    /**
     * Set the cacheDuration property: The duration for which the content needs to be cached. Allowed format is in ISO
     * 8601 format (http://en.wikipedia.org/wiki/ISO_8601#Durations). HTTP requires the value to be no more than a year.
     * 
     * @param cacheDuration the cacheDuration value to set.
     * @return the CacheConfiguration object itself.
     */
    public CacheConfiguration withCacheDuration(Duration cacheDuration) {
        this.cacheDuration = cacheDuration;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("queryParameterStripDirective",
            this.queryParameterStripDirective == null ? null : this.queryParameterStripDirective.toString());
        jsonWriter.writeStringField("queryParameters", this.queryParameters);
        jsonWriter.writeStringField("dynamicCompression",
            this.dynamicCompression == null ? null : this.dynamicCompression.toString());
        jsonWriter.writeStringField("cacheDuration", CoreUtils.durationToStringWithDays(this.cacheDuration));
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of CacheConfiguration from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of CacheConfiguration if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IOException If an error occurs while reading the CacheConfiguration.
     */
    public static CacheConfiguration fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            CacheConfiguration deserializedCacheConfiguration = new CacheConfiguration();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("queryParameterStripDirective".equals(fieldName)) {
                    deserializedCacheConfiguration.queryParameterStripDirective
                        = FrontDoorQuery.fromString(reader.getString());
                } else if ("queryParameters".equals(fieldName)) {
                    deserializedCacheConfiguration.queryParameters = reader.getString();
                } else if ("dynamicCompression".equals(fieldName)) {
                    deserializedCacheConfiguration.dynamicCompression
                        = DynamicCompressionEnabled.fromString(reader.getString());
                } else if ("cacheDuration".equals(fieldName)) {
                    deserializedCacheConfiguration.cacheDuration
                        = reader.getNullable(nonNullReader -> Duration.parse(nonNullReader.getString()));
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedCacheConfiguration;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy