Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 1591990 + 5581006 commit 6e91382
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 221 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ jobs:
pushd examples
dotnet build MomentoApplication
dotnet run --project MomentoApplication
dotnet build MomentoApplicationPresignedUrl
popd
shell: bash

Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To create a new .NET project and add the Momento client library as a dependency:
```bash
mkdir my-momento-dotnet-project
cd my-momento-dotnet-project
dotnet new console
dotnet new console
dotnet add package Momento.Sdk
```

Expand All @@ -47,19 +47,17 @@ Here is a quickstart you can use in your own project:
```csharp
using System;
using Momento.Sdk;
using Momento.Sdk.Auth;
using Momento.Sdk.Config;
using Momento.Sdk.Responses;

string? MOMENTO_AUTH_TOKEN = Environment.GetEnvironmentVariable("MOMENTO_AUTH_TOKEN");
if (MOMENTO_AUTH_TOKEN == null) {
throw new Exception("Please set your 'MOMENTO_AUTH_TOKEN' environment variable.");
}
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
const string CACHE_NAME = "cache";
const string KEY = "MyKey";
const string VALUE = "MyData";
const uint DEFAULT_TTL_SECONDS = 60;

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, MOMENTO_AUTH_TOKEN, DEFAULT_TTL_SECONDS))
using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, authProvider, DEFAULT_TTL_SECONDS))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError) {
Expand All @@ -86,20 +84,24 @@ using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.La

```

Note that the above code requires an environment variable named MOMENTO_AUTH_TOKEN which must
be set to a valid [Momento authentication token](https://docs.momentohq.com/docs/getting-started#obtain-an-auth-token).

### Error Handling

Error cases in Momento are surfaced to developers as part of the return values of the method 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!)
Error that occur in calls to SimpleCacheClient 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 the Momento .NET 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 SimpleCacheClient 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);
if (getResponse is CacheGetResponse.Hit hitResponse)
{
Console.WriteLine($"\nLookedup 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 All @@ -124,6 +126,9 @@ 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.

### Tuning

Momento client-libraries provide pre-built configuration bundles out-of-the-box. We want to do the hard work of
Expand Down
21 changes: 14 additions & 7 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To create a new .NET project and add the Momento client library as a dependency:
```bash
mkdir my-momento-dotnet-project
cd my-momento-dotnet-project
dotnet new console
dotnet new console
dotnet add package Momento.Sdk
```

Expand All @@ -32,20 +32,24 @@ Here is a quickstart you can use in your own project:
{{ usageExampleCode }}
```

Note that the above code requires an environment variable named MOMENTO_AUTH_TOKEN which must
be set to a valid [Momento authentication token](https://docs.momentohq.com/docs/getting-started#obtain-an-auth-token).

### Error Handling

Error cases in Momento are surfaced to developers as part of the return values of the method 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!)
Error that occur in calls to SimpleCacheClient 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 the Momento .NET 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 SimpleCacheClient 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);
if (getResponse is CacheGetResponse.Hit hitResponse)
{
Console.WriteLine($"\nLookedup 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 All @@ -70,6 +74,9 @@ 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.

### Tuning

Momento client-libraries provide pre-built configuration bundles out-of-the-box. We want to do the hard work of
Expand Down
2 changes: 1 addition & 1 deletion examples/MomentoApplication/MomentoApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="0.32.1" />
<PackageReference Include="Momento.Sdk" Version="0.33.0" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.Extensions.Logging.Console" />
Expand Down
8 changes: 3 additions & 5 deletions examples/MomentoApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Momento.Sdk;
using Momento.Sdk.Auth;
using Momento.Sdk.Config;
using Momento.Sdk.Exceptions;
using Momento.Sdk.Responses;

string? MOMENTO_AUTH_TOKEN = Environment.GetEnvironmentVariable("MOMENTO_AUTH_TOKEN");
if (MOMENTO_AUTH_TOKEN == null) {
throw new System.Exception("Please set your 'MOMENTO_AUTH_TOKEN' environment variable.");
}
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
const string CACHE_NAME = "momento-example";
const string KEY = "MyKey";
const string VALUE = "MyData";
const uint DEFAULT_TTL_SECONDS = 60;

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, MOMENTO_AUTH_TOKEN, DEFAULT_TTL_SECONDS))
using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, authProvider, DEFAULT_TTL_SECONDS))
{
Console.WriteLine($"Creating cache {CACHE_NAME}");
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
Expand Down

This file was deleted.

75 changes: 0 additions & 75 deletions examples/MomentoApplicationPresignedUrl/Program.cs

This file was deleted.

74 changes: 0 additions & 74 deletions examples/MomentoApplicationPresignedUrlNet45/Program.cs

This file was deleted.

15 changes: 0 additions & 15 deletions examples/MomentoApplicationPresignedUrlNet45/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/MomentoUsage/MomentoUsage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<None Remove="Momento.Sdk" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="0.32.1" />
<PackageReference Include="Momento.Sdk" Version="0.33.0" />
</ItemGroup>
</Project>
8 changes: 3 additions & 5 deletions examples/MomentoUsage/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System;
using Momento.Sdk;
using Momento.Sdk.Auth;
using Momento.Sdk.Config;
using Momento.Sdk.Responses;

string? MOMENTO_AUTH_TOKEN = Environment.GetEnvironmentVariable("MOMENTO_AUTH_TOKEN");
if (MOMENTO_AUTH_TOKEN == null) {
throw new Exception("Please set your 'MOMENTO_AUTH_TOKEN' environment variable.");
}
ICredentialProvider authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
const string CACHE_NAME = "cache";
const string KEY = "MyKey";
const string VALUE = "MyData";
const uint DEFAULT_TTL_SECONDS = 60;

using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, MOMENTO_AUTH_TOKEN, DEFAULT_TTL_SECONDS))
using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest, authProvider, DEFAULT_TTL_SECONDS))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError) {
Expand Down
Loading

0 comments on commit 6e91382

Please sign in to comment.