Skip to content

Commit 2762eba

Browse files
Add support for BypassIntegratedCache option (Azure#24772)
* Add support for BypassIntegratedCache option * Update CHANGELOG * Fix lint and add more tests * Update sdk/data/azcosmos/cosmos_item_request_options_test.go Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent a37c5e0 commit 2762eba

7 files changed

+48
-0
lines changed

sdk/data/azcosmos/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
* Added support for BypassIntegratedCache option See [PR 24772](https://github.com/Azure/azure-sdk-for-go/pull/24772)
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/data/azcosmos/cosmos_dedicated_gateway_request_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ type DedicatedGatewayRequestOptions struct {
1212
// responses from the integrated cache are guaranteed to be no staler than value indicated by this MaxIntegratedCacheStaleness.
1313
// Cache Staleness is supported in milliseconds granularity. Anything smaller than milliseconds will be ignored.
1414
MaxIntegratedCacheStaleness *time.Duration
15+
16+
// When set to true, the request will not be served from the integrated cache, and the response will not be cached either.
17+
BypassIntegratedCache bool
1518
}

sdk/data/azcosmos/cosmos_http_constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const (
8383
cosmosHeaderQueryExecutionInfo string = "x-ms-cosmos-query-execution-info"
8484
headerXmsItemCount string = "x-ms-item-count"
8585
headerDedicatedGatewayMaxAge string = "x-ms-dedicatedgateway-max-age"
86+
headerDedicatedGatewayBypassCache string = "x-ms-dedicatedgateway-bypass-cache"
8687
)
8788

8889
const (

sdk/data/azcosmos/cosmos_item_request_options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func (options *ItemOptions) toHeaders() *map[string]string {
7373
milliseconds := dedicatedGatewayRequestOptions.MaxIntegratedCacheStaleness.Milliseconds()
7474
headers[headerDedicatedGatewayMaxAge] = strconv.FormatInt(milliseconds, 10)
7575
}
76+
77+
if dedicatedGatewayRequestOptions.BypassIntegratedCache {
78+
headers[headerDedicatedGatewayBypassCache] = "true"
79+
}
7680
}
7781

7882
return &headers

sdk/data/azcosmos/cosmos_item_request_options_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestItemRequestOptionsToHeaders(t *testing.T) {
2525
options.DedicatedGatewayRequestOptions = &DedicatedGatewayRequestOptions{
2626
MaxIntegratedCacheStaleness: &maxIntegratedCacheStalenessDuration,
2727
}
28+
options.DedicatedGatewayRequestOptions.BypassIntegratedCache = true
2829
header := options.toHeaders()
2930
if header == nil {
3031
t.Fatal("toHeaders should return non-nil")
@@ -52,4 +53,20 @@ func TestItemRequestOptionsToHeaders(t *testing.T) {
5253
if headers[headerDedicatedGatewayMaxAge] != strconv.FormatInt(300000, 10) {
5354
t.Errorf("headerDedicatedGatewayMaxAge should be 300000 but got %v", headers[headerDedicatedGatewayMaxAge])
5455
}
56+
if headers[headerDedicatedGatewayBypassCache] != "true" {
57+
t.Errorf("headerDedicatedGatewayBypassCache should be true but got %v", headers[headerDedicatedGatewayBypassCache])
58+
}
59+
}
60+
61+
func TestItemRequestOptionsToHeaders_bypassIntegratedCacheNotSet(t *testing.T) {
62+
options := &ItemOptions{}
63+
header := options.toHeaders()
64+
if header == nil {
65+
t.Fatal("toHeaders should return non-nil")
66+
}
67+
68+
headers := *header
69+
if _, exists := headers[headerDedicatedGatewayBypassCache]; exists {
70+
t.Errorf("headerDedicatedGatewayBypassCache should not exist when BypassIntegratedCache is not set")
71+
}
5572
}

sdk/data/azcosmos/cosmos_query_request_options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (options *QueryOptions) toHeaders() *map[string]string {
8484
milliseconds := dedicatedGatewayRequestOptions.MaxIntegratedCacheStaleness.Milliseconds()
8585
headers[headerDedicatedGatewayMaxAge] = strconv.FormatInt(milliseconds, 10)
8686
}
87+
88+
if dedicatedGatewayRequestOptions.BypassIntegratedCache {
89+
headers[headerDedicatedGatewayBypassCache] = "true"
90+
}
8791
}
8892

8993
headers[cosmosHeaderPopulateQueryMetrics] = "true"

sdk/data/azcosmos/cosmos_query_request_options_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestQueryRequestOptionsToHeaders(t *testing.T) {
2424
options.DedicatedGatewayRequestOptions = &DedicatedGatewayRequestOptions{
2525
MaxIntegratedCacheStaleness: &maxIntegratedCacheStalenessDuration,
2626
}
27+
options.DedicatedGatewayRequestOptions.BypassIntegratedCache = true
2728
header := options.toHeaders()
2829
if header == nil {
2930
t.Fatal("toHeaders should return non-nil")
@@ -57,4 +58,20 @@ func TestQueryRequestOptionsToHeaders(t *testing.T) {
5758
if headers[headerDedicatedGatewayMaxAge] != strconv.FormatInt(300000, 10) {
5859
t.Errorf("headerDedicatedGatewayMaxAge should be 300000 but got %v", headers[headerDedicatedGatewayMaxAge])
5960
}
61+
if headers[headerDedicatedGatewayBypassCache] != "true" {
62+
t.Errorf("headerDedicatedGatewayBypassCache should be true but got %v", headers[headerDedicatedGatewayBypassCache])
63+
}
64+
}
65+
66+
func TestQueryRequestOptionsToHeaders_bypassIntegratedCacheNotSet(t *testing.T) {
67+
options := &QueryOptions{}
68+
header := options.toHeaders()
69+
if header == nil {
70+
t.Fatal("toHeaders should return non-nil")
71+
}
72+
73+
headers := *header
74+
if _, exists := headers[headerDedicatedGatewayBypassCache]; exists {
75+
t.Errorf("headerDedicatedGatewayBypassCache should not exist when BypassIntegratedCache is not set")
76+
}
6077
}

0 commit comments

Comments
 (0)