Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename cache hit string value field #272

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The preferred way of interpreting the return values from SimpleCacheClient metho
CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY);
if (getResponse is CacheGetResponse.Hit hitResponse)
{
Console.WriteLine($"\nLooked up value: {hitResponse.String()}, Stored value: {VALUE}");
Console.WriteLine($"\nLooked up value: {hitResponse.ValueString}, Stored value: {VALUE}");
} else {
// you can handle other cases via pattern matching in `else if` blocks, or a default case
// via the `else` block. For each return value your IDE should be able to give you code
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/ISimpleCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public interface ISimpleCacheClient : IDisposable
/// <code>
/// if (response is CacheGetResponse.Hit hitResponse)
/// {
/// return hitResponse.String();
/// return hitResponse.ValueString;
/// } else if (response is CacheGetResponse.Error errorResponse)
/// {
/// // handle error as appropriate
Expand Down
11 changes: 7 additions & 4 deletions src/Momento.Sdk/Responses/CacheGetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Momento.Sdk.Responses;
/// <code>
/// if (response is CacheGetResponse.Hit hitResponse)
/// {
/// return hitResponse.String();
/// return hitResponse.ValueString;
/// } else if (response is CacheGetResponse.Error errorResponse)
/// {
/// // handle error as appropriate
Expand All @@ -41,19 +41,22 @@ public Hit(_GetResponse response)
/// <summary>
/// Value from the cache as a byte array.
/// </summary>
public byte[] ByteArray
public byte[] ValueByteArray
{
get => value.ToByteArray();
}

/// <summary>
/// Value from the cache as a string.
/// </summary>
public string String() => value.ToStringUtf8();
public string ValueString
{
get => value.ToStringUtf8();
}

public override string ToString()
{
return $"{base.ToString()}: {this.String()}";
return $"{base.ToString()}: {this.ValueString}";
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/Momento.Sdk.Tests/SimpleCacheDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task SetAsync_KeyIsByteArrayValueIsByteArray_HappyPath()
CacheGetResponse response = await client.GetAsync(cacheName, key);
Assert.True(response is CacheGetResponse.Hit);
var goodResponse = (CacheGetResponse.Hit)response;
byte[]? setValue = goodResponse.ByteArray;
byte[] setValue = goodResponse.ValueByteArray;
Assert.Equal(value, setValue);

key = Utils.NewGuidByteArray();
Expand All @@ -55,7 +55,7 @@ public async Task SetAsync_KeyIsByteArrayValueIsByteArray_HappyPath()
response = await client.GetAsync(cacheName, key);
Assert.True(response is CacheGetResponse.Hit);
goodResponse = (CacheGetResponse.Hit)response;
setValue = goodResponse.ByteArray;
setValue = goodResponse.ValueByteArray;
Assert.Equal(value, setValue);
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task SetAsync_KeyIsStringValueIsString_HappyPath()
CacheGetResponse response = await client.GetAsync(cacheName, key);
Assert.True(response is CacheGetResponse.Hit);
var goodResponse = (CacheGetResponse.Hit)response;
string? setValue = goodResponse.String();
string setValue = goodResponse.ValueString;
Assert.Equal(value, setValue);

// Set with TTL
Expand All @@ -109,7 +109,7 @@ public async Task SetAsync_KeyIsStringValueIsString_HappyPath()
response = await client.GetAsync(cacheName, key);
Assert.True(response is CacheGetResponse.Hit);
goodResponse = (CacheGetResponse.Hit)response;
setValue = goodResponse.String();
setValue = goodResponse.ValueString;
Assert.Equal(value, setValue);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task SetAsync_KeyIsStringValueIsByteArray_HappyPath()

CacheGetResponse response = await client.GetAsync(cacheName, key);
var goodResponse = (CacheGetResponse.Hit)response;
byte[]? setValue = goodResponse.ByteArray;
byte[] setValue = goodResponse.ValueByteArray;
Assert.Equal(value, setValue);

// Set with TTL
Expand All @@ -161,7 +161,7 @@ public async Task SetAsync_KeyIsStringValueIsByteArray_HappyPath()

response = await client.GetAsync(cacheName, key);
var anotherGoodResponse = (CacheGetResponse.Hit)response;
byte[]? anotherSetValue = anotherGoodResponse.ByteArray;
byte[] anotherSetValue = anotherGoodResponse.ValueByteArray;
Assert.Equal(value, anotherSetValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public void CorrectResultMapping()
ByteString body = ByteString.CopyFromUtf8(cacheBody);
_GetResponse serverResponseHit = new _GetResponse() { CacheBody = body, Result = ECacheResult.Hit };
CacheGetResponse.Hit responseHit = new CacheGetResponse.Hit(serverResponseHit);
Assert.Equal(cacheBody, responseHit.String());
Assert.Equal(cacheBody, responseHit.ValueString);
}
}