-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
266 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,3 +406,4 @@ ASALocalRun/ | |
|
||
# VS Code | ||
.vscode | ||
/exportToHTML/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
using System; | ||
using Momento.Protos.CacheClient; | ||
using Momento.Sdk.Exceptions; | ||
|
||
/// <summary> | ||
/// Parent response type for a cache item get ttl request. The | ||
/// response object is resolved to a type-safe object of one of | ||
/// the following subtypes: | ||
/// <list type="bullet"> | ||
/// <item><description>CacheItemGetTtlResponse.Hit</description></item> | ||
/// <item><description>CacheItemGetTtlResponse.Miss</description></item> | ||
/// <item><description>CacheItemGetTtlResponse.Error</description></item> | ||
/// </list> | ||
/// Pattern matching can be used to operate on the appropriate subtype. | ||
/// For example: | ||
/// <code> | ||
/// if (response is CacheItemGetTtlResponse.Hit hitResponse) | ||
/// { | ||
/// // handle ttl value as appropriate | ||
/// } | ||
/// else if (response is CacheItemGetTtlResponse.Miss missResponse) | ||
/// { | ||
/// // handle key was not found as appropriate | ||
/// } | ||
/// else if (response is CacheItemGetTtlResponse.Error errorResponse) | ||
/// { | ||
/// // handle error as appropriate | ||
/// } | ||
/// else | ||
/// { | ||
/// // handle unexpected response | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
public abstract class CacheItemGetTtlResponse | ||
{ | ||
/// <summary> | ||
/// Indicates the key was found in the cache and the ttl was returned. | ||
/// </summary> | ||
public class Hit : CacheItemGetTtlResponse { | ||
/// <summary> | ||
/// The value of the ttl. | ||
/// </summary> | ||
protected readonly ulong value; | ||
|
||
/// <include file="../docs.xml" path='docs/class[@name="Hit"]/description/*' /> | ||
public Hit(_ItemGetTtlResponse response) | ||
{ | ||
value = response.Found.RemainingTtlMillis; | ||
} | ||
|
||
/// <summary> | ||
/// The value of the ttl. | ||
/// </summary> | ||
public TimeSpan Value | ||
{ | ||
get => TimeSpan.FromMilliseconds(value); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}: Value: {Value}"; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Indicates the key was not found in the cache, hence the ttl was not returned. | ||
/// </summary> | ||
public class Miss : CacheItemGetTtlResponse { } | ||
|
||
/// <include file = "../docs.xml" path='docs/class[@name="Error"]/description/*' /> | ||
public class Error : CacheItemGetTtlResponse, IError | ||
{ | ||
private readonly SdkException _error; | ||
|
||
/// <include file = "../docs.xml" path='docs/class[@name="Error"]/constructor/*' /> | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SdkException InnerException | ||
{ | ||
get => _error; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Message | ||
{ | ||
get => _error.Message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.