Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents c774753 + 710db87 commit 3ddf538
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 70 deletions.
14 changes: 7 additions & 7 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src="https://docs.momentohq.com/img/logo.svg" alt="logo" width="400"/>

[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-beta.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-stable.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)

# Momento .NET Client Library

Expand All @@ -24,7 +24,7 @@ Momento Serverless Cache の .NET クライアント SDK:従来のキャッシ

### Momento レスポンスタイプ

Momento の`SimpleCacheClient`クラスの戻り値は IDE が容易にエラーを含む、有り得るレスポンスを予測できる様にデザインしてあります。[パターンマッチング](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)を使用し、様々なレスポンスタイプを区別します。そうすることで、それらの API を使用する時、ランタイムでバグを発見するよりも、コンパイル時での安全性があります。
Momento の`CacheClient`クラスの戻り値は IDE が容易にエラーを含む、有り得るレスポンスを予測できる様にデザインしてあります。[パターンマッチング](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)を使用し、様々なレスポンスタイプを区別します。そうすることで、それらの API を使用する時、ランタイムでバグを発見するよりも、コンパイル時での安全性があります。

以下が使用例です:

Expand Down Expand Up @@ -70,7 +70,7 @@ const string KEY = "MyKey";
const string VALUE = "MyData";
TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL))
using (CacheClient client = new CacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError)
Expand Down Expand Up @@ -105,9 +105,9 @@ using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.La

### エラーの処理法

従来の例外処理とは異なり、SimpleCacheClient のメソッドを呼び出した際に起こるエラーは戻り値として浮上します。こうすることで、エラーの可視化を行い、必要なエラーのみを処理する際に IDE が更に役立つ様になります。(もっと例外についての私達の哲学を知りたい方はこちらの[例外はバグだ](https://www.gomomento.com/blog/exceptions-are-bugs)をぜひお読みください。またフィードバックもお待ちしております!)
従来の例外処理とは異なり、CacheClient のメソッドを呼び出した際に起こるエラーは戻り値として浮上します。こうすることで、エラーの可視化を行い、必要なエラーのみを処理する際に IDE が更に役立つ様になります。(もっと例外についての私達の哲学を知りたい方はこちらの[例外はバグだ](https://www.gomomento.com/blog/exceptions-are-bugs)をぜひお読みください。またフィードバックもお待ちしております!)

SimpleCacheClient メソッドからの戻り値の好ましい対応の仕方は[パターンマッチング](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)を使用する方法です。こちらが簡単な例です:
CacheClient メソッドからの戻り値の好ましい対応の仕方は[パターンマッチング](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)を使用する方法です。こちらが簡単な例です:

```csharp
CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY);
Expand Down Expand Up @@ -136,8 +136,8 @@ if (getResponse is CacheGetResponse.Error errorResponse)
}
```

SimpleCacheClient の戻り値以外では例外が起こる可能性があり、それらは通常通り処理する必要があるのでご注意ください。
例えば、SimpleCacheClient のインスタンスを生成する際、無効なオーセンティケーショントークンは IllegalArgumentException の発生原因になります。
CacheClient の戻り値以外では例外が起こる可能性があり、それらは通常通り処理する必要があるのでご注意ください。
例えば、CacheClient のインスタンスを生成する際、無効なオーセンティケーショントークンは IllegalArgumentException の発生原因になります。

### チューニング

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ how to use the SDK.

### Momento Response Types

The return values of the methods on the Momento `SimpleCacheClient` class are designed to allow you to use your
The return values of the methods on the Momento `CacheClient` class are designed to allow you to use your
IDE to help you easily discover all the possible responses, including errors. We use [pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching) to distinguish between different types of responses,
which means that you can get compile-time safety when interacting with the API, rather than having bugs sneak in at runtime.

Expand Down Expand Up @@ -79,7 +79,7 @@ const string KEY = "MyKey";
const string VALUE = "MyData";
TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL))
using (ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError)
Expand Down Expand Up @@ -115,13 +115,13 @@ be set to a valid [Momento authentication token](https://docs.momentohq.com/docs

### Error Handling

Error that occur in calls to SimpleCacheClient methods are surfaced to developers as part of the return values of
Error that occur in calls to CacheClient methods are surfaced to developers as part of the return values of
the calls, as opposed to by throwing exceptions. This makes them more visible, and allows your IDE to be more
helpful in ensuring that you've handled the ones you care about. (For more on our philosophy about this, see our
blog post on why [Exceptions are bugs](https://www.gomomento.com/blog/exceptions-are-bugs). And send us any
feedback you have!)

The preferred way of interpreting the return values from SimpleCacheClient methods is using [Pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching). Here's a quick example:
The preferred way of interpreting the return values from CacheClient methods is using [Pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching). Here's a quick example:

```csharp
CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY);
Expand Down Expand Up @@ -152,8 +152,8 @@ if (getResponse is CacheGetResponse.Error errorResponse)
}
```

Note that, outside of SimpleCacheClient responses, exceptions can occur and should be handled as usual. For example, trying
to instantiate a SimpleCacheClient with an invalid authentication token will result in an IllegalArgumentException being thrown.
Note that, outside of CacheClient responses, exceptions can occur and should be handled as usual. For example, trying
to instantiate a CacheClient with an invalid authentication token will result in an IllegalArgumentException being thrown.

### Tuning

Expand Down
10 changes: 5 additions & 5 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ how to use the SDK.

### Momento Response Types

The return values of the methods on the Momento `SimpleCacheClient` class are designed to allow you to use your
The return values of the methods on the Momento `CacheClient` class are designed to allow you to use your
IDE to help you easily discover all the possible responses, including errors. We use [pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching) to distinguish between different types of responses,
which means that you can get compile-time safety when interacting with the API, rather than having bugs sneak in at runtime.

Expand Down Expand Up @@ -61,13 +61,13 @@ be set to a valid [Momento authentication token](https://docs.momentohq.com/docs

### Error Handling

Error that occur in calls to SimpleCacheClient methods are surfaced to developers as part of the return values of
Error that occur in calls to CacheClient methods are surfaced to developers as part of the return values of
the calls, as opposed to by throwing exceptions. This makes them more visible, and allows your IDE to be more
helpful in ensuring that you've handled the ones you care about. (For more on our philosophy about this, see our
blog post on why [Exceptions are bugs](https://www.gomomento.com/blog/exceptions-are-bugs). And send us any
feedback you have!)

The preferred way of interpreting the return values from SimpleCacheClient methods is using [Pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching). Here's a quick example:
The preferred way of interpreting the return values from CacheClient methods is using [Pattern matching](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching). Here's a quick example:

```csharp
CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY);
Expand Down Expand Up @@ -98,8 +98,8 @@ if (getResponse is CacheGetResponse.Error errorResponse)
}
```

Note that, outside of SimpleCacheClient responses, exceptions can occur and should be handled as usual. For example, trying
to instantiate a SimpleCacheClient with an invalid authentication token will result in an IllegalArgumentException being thrown.
Note that, outside of CacheClient responses, exceptions can occur and should be handled as usual. For example, trying
to instantiate a CacheClient with an invalid authentication token will result in an IllegalArgumentException being thrown.

### Tuning

Expand Down
5 changes: 1 addition & 4 deletions examples/DictionaryExample/DictionaryExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Momento.Sdk" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<None Remove="Momento.Sdk" />
<PackageReference Include="Momento.Sdk" Version="1.8.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions examples/DictionaryExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async static Task Main()
var cacheName = ReadCacheName();

// Set up the client
using var client = new SimpleCacheClient(Configurations.Laptop.V1(), authToken, TimeSpan.FromSeconds(60));
using ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authToken, TimeSpan.FromSeconds(60));
await EnsureCacheExistsAsync(client, cacheName);

// Set a value
Expand Down Expand Up @@ -205,7 +205,7 @@ private static string ReadCacheName()
return "default-cache";
}

private static async Task EnsureCacheExistsAsync(ISimpleCacheClient client, string cacheName)
private static async Task EnsureCacheExistsAsync(ICacheClient client, string cacheName)
{
_logger.LogInformation($"Creating cache {cacheName} if it doesn't already exist.");
var createCacheResponse = await client.CreateCacheAsync(cacheName);
Expand Down
4 changes: 3 additions & 1 deletion examples/MomentoApplication/MomentoApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="1.6.0" />
<PackageReference Include="Momento.Sdk" Version="1.8.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Microsoft.Extensions.Logging.Console" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions examples/MomentoApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL))
using (ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL))
{
await AdvancedExamples.CreateCacheExample(client);
await AdvancedExamples.ListCachesExample(client);
Expand All @@ -29,7 +29,7 @@ public class AdvancedExamples {
const string KEY = "MyKey";
const string VALUE = "MyData";

public static async Task CreateCacheExample(ISimpleCacheClient client)
public static async Task CreateCacheExample(ICacheClient client)
{

Console.WriteLine($"Creating cache {CACHE_NAME}");
Expand All @@ -55,7 +55,7 @@ public static async Task CreateCacheExample(ISimpleCacheClient client)
}
}

public static async Task ListCachesExample(ISimpleCacheClient client) {
public static async Task ListCachesExample(ICacheClient client) {
Console.WriteLine("\nListing caches:");
ListCachesResponse listCachesResponse = await client.ListCachesAsync();
if (listCachesResponse is ListCachesResponse.Success listCachesSuccess)
Expand All @@ -72,7 +72,7 @@ public static async Task ListCachesExample(ISimpleCacheClient client) {
}
}

public static async Task SetGetDeleteExample(ISimpleCacheClient client) {
public static async Task SetGetDeleteExample(ICacheClient client) {
Console.WriteLine($"\nSetting key: {KEY} with value: {VALUE}");
var setResponse = await client.SetAsync(CACHE_NAME, KEY, VALUE);
if (setResponse is CacheSetResponse.Error setError)
Expand Down Expand Up @@ -108,7 +108,7 @@ public static async Task SetGetDeleteExample(ISimpleCacheClient client) {
}
}

public static async Task DeleteCacheExample(ISimpleCacheClient client) {
public static async Task DeleteCacheExample(ICacheClient client) {

Console.WriteLine($"\nDeleting cache {CACHE_NAME}");
var deleteCacheResponse = await client.DeleteCacheAsync(CACHE_NAME);
Expand All @@ -133,7 +133,7 @@ public static void EagerConnectionExample()
var config = Configurations.Laptop.V1();
var eagerConnectionConfig = config.WithTransportStrategy(config.TransportStrategy.WithEagerConnectionTimeout(TimeSpan.FromSeconds(10)));
Console.WriteLine("Creating a momento client with eager connection");
using (SimpleCacheClient client = new SimpleCacheClient(eagerConnectionConfig, authProvider, defaultTtl)) {
using (CacheClient client = new CacheClient(eagerConnectionConfig, authProvider, defaultTtl)) {
Console.WriteLine("Successfully created a momento client with eager connection");
}

Expand Down
6 changes: 6 additions & 0 deletions examples/MomentoExamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MomentoUsage", "MomentoUsag
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DictionaryExample", "DictionaryExample\DictionaryExample.csproj", "{61F79DA8-BA7F-4F6E-B4EA-29DACF9C7571}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Momento.Sdk", "..\src\Momento.Sdk\Momento.Sdk.csproj", "{ABDFBF7A-9639-4449-91E3-4558C366D297}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{61F79DA8-BA7F-4F6E-B4EA-29DACF9C7571}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61F79DA8-BA7F-4F6E-B4EA-29DACF9C7571}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61F79DA8-BA7F-4F6E-B4EA-29DACF9C7571}.Release|Any CPU.Build.0 = Release|Any CPU
{ABDFBF7A-9639-4449-91E3-4558C366D297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ABDFBF7A-9639-4449-91E3-4558C366D297}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ABDFBF7A-9639-4449-91E3-4558C366D297}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABDFBF7A-9639-4449-91E3-4558C366D297}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="1.6.0">
<GeneratePathProperty></GeneratePathProperty>
</PackageReference>
<ProjectReference Include="..\..\src\Momento.Sdk\Momento.Sdk.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/MomentoFSharpApplication/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")

let exerciseCache() = (
printfn "Howdy"
using(new SimpleCacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL)) (fun client ->
using(new CacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL)) (fun client ->
let createCacheResult = client.CreateCacheAsync(CACHE_NAME) |> Async.AwaitTask

printfn("Listing caches:")
Expand Down
2 changes: 1 addition & 1 deletion examples/MomentoLoadGen/MomentoLoadGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Momento.Sdk" Version="1.6.0" />
<PackageReference Include="HdrHistogram" Version="2.5.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Momento.Sdk" Version="1.8.0" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions examples/MomentoLoadGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task Run()
{
var authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");

using (var momento = new SimpleCacheClient(
using (ICacheClient momento = new CacheClient(
_momentoClientConfig,
authProvider,
TimeSpan.FromSeconds(CACHE_ITEM_TTL_SECONDS)
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task Run()


private async Task LaunchAndRunWorkers(
SimpleCacheClient client,
ICacheClient client,
CsharpLoadGeneratorContext context,
int workerId,
int delayMillisBetweenRequests,
Expand Down Expand Up @@ -201,7 +201,7 @@ private void PrintStats(LongHistogram setsAccumulatingHistogram, LongHistogram g
_logger.LogInformation($"Load gen data point:\t{_options.numberOfConcurrentRequests}\t{Tps(context, context.GlobalRequestCount)}\t{getsAccumulatingHistogram.GetValueAtPercentile(50)}\t{getsAccumulatingHistogram.GetValueAtPercentile(99.9)}");
}

private async Task IssueAsyncSetGet(SimpleCacheClient client, CsharpLoadGeneratorContext context, int workerId, int operationId, int delayMillisBetweenRequests)
private async Task IssueAsyncSetGet(ICacheClient client, CsharpLoadGeneratorContext context, int workerId, int operationId, int delayMillisBetweenRequests)
{
var cacheKey = $"worker{workerId}operation{operationId}";

Expand Down Expand Up @@ -247,7 +247,7 @@ Func<Task<Tuple<AsyncSetGetResult, TResult>>> block
return result.Item2;
}

private async Task<Tuple<AsyncSetGetResult, CacheGetResponse?>> IssueGetRequest(SimpleCacheClient client, String cacheKey)
private async Task<Tuple<AsyncSetGetResult, CacheGetResponse?>> IssueGetRequest(ICacheClient client, String cacheKey)
{
var getResponse = await client.GetAsync(CACHE_NAME, cacheKey);
if (getResponse is CacheGetResponse.Hit hit)
Expand All @@ -268,7 +268,7 @@ Func<Task<Tuple<AsyncSetGetResult, TResult>>> block
}
}

private async Task<Tuple<AsyncSetGetResult, CacheSetResponse?>> IssueSetRequest(SimpleCacheClient client, String cacheKey, String cacheValue)
private async Task<Tuple<AsyncSetGetResult, CacheSetResponse?>> IssueSetRequest(ICacheClient client, String cacheKey, String cacheValue)
{
var setResponse = await client.SetAsync(CACHE_NAME, cacheKey, cacheValue);
if (setResponse is CacheSetResponse.Success success)
Expand Down
Loading

0 comments on commit 3ddf538

Please sign in to comment.