-
Notifications
You must be signed in to change notification settings - Fork 478
/
DedicatedGatewayRequestOptions.cs
78 lines (71 loc) · 3.72 KB
/
DedicatedGatewayRequestOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Globalization;
using Microsoft.Azure.Documents;
/// <summary>
/// The Dedicated Gateway request options
/// </summary>
public class DedicatedGatewayRequestOptions
{
/// <summary>
/// Gets or sets the staleness value associated with the request in the Azure Cosmos DB service.
/// </summary>
/// <value>Default value is null.</value>
/// <remarks>
/// For requests where the <see cref="ConsistencyLevel"/> is <see cref="ConsistencyLevel.Eventual"/> or <see cref="ConsistencyLevel.Session"/>, responses from the integrated cache are guaranteed to be no staler than value indicated by this MaxIntegratedCacheStaleness.
/// Cache Staleness is supported in milliseconds granularity. Anything smaller than milliseconds will be ignored.
/// </remarks>
public TimeSpan? MaxIntegratedCacheStaleness { get; set; }
/// <summary>
/// Gets or sets if bypass the integrated cache or not associated with the request in the Azure Cosmos DB service.
/// When set this value to true, the request will not be served from the integrated cache, and the response will not be cached either.
/// </summary>
/// <value>Default value is false.</value>
/// <example>
/// <code language="c#">
/// <![CDATA[
/// DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions
/// {
/// BypassIntegratedCache = true
/// };
///
/// // For ItemRequestOptions
/// ItemRequestOptions requestOptions = new ItemRequestOptions
/// {
/// DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions
/// };
///
/// // For QueryRequestOptions
/// QueryRequestOptions requestOptions = new QueryRequestOptions
/// {
/// DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions
/// };
/// ]]>
/// </code>
/// </example>
public bool? BypassIntegratedCache { get; set; }
internal static void PopulateMaxIntegratedCacheStalenessOption(DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions, RequestMessage request)
{
if (dedicatedGatewayRequestOptions?.MaxIntegratedCacheStaleness != null)
{
double cacheStalenessInMilliseconds = (double)dedicatedGatewayRequestOptions.MaxIntegratedCacheStaleness.Value.TotalMilliseconds;
if (cacheStalenessInMilliseconds < 0)
{
throw new ArgumentOutOfRangeException(nameof(DedicatedGatewayRequestOptions.MaxIntegratedCacheStaleness), "MaxIntegratedCacheStaleness cannot be negative.");
}
request.Headers.Set(HttpConstants.HttpHeaders.DedicatedGatewayPerRequestCacheStaleness, cacheStalenessInMilliseconds.ToString(CultureInfo.InvariantCulture));
}
}
internal static void PopulateBypassIntegratedCacheOption(DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions, RequestMessage request)
{
if (dedicatedGatewayRequestOptions != null && dedicatedGatewayRequestOptions.BypassIntegratedCache.HasValue && dedicatedGatewayRequestOptions.BypassIntegratedCache.Value)
{
request.Headers.Set(HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache, true.ToString(CultureInfo.InvariantCulture));
}
}
}
}