Momento Cache is a fast, simple, pay-as-you-go caching solution without any of the operational overhead required by traditional caching solutions. This repo contains the source code for the Momento client library for .NET.
To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.
- Website: https://www.gomomento.com/
- Momento Documentation: https://docs.momentohq.com/
- Getting Started: https://docs.momentohq.com/getting-started
- Momento SDK Documentation for .NET: https://docs.momentohq.com/sdks/dotnet
- Discuss: Momento Discord
Japanese: 日本語
The Momento Dotnet SDK package is available on nuget: momentohq/client-sdk-dotnet.
dotnet6.0 or higher is required- A Momento API key is required. You can generate one using the Momento Console.
- A Momento service endpoint is required. Choose the one for the region you'll be using, e.g.
cell-1-ap-southeast-1-1.prod.a.momentohq.comfor ap-southeast-1
Here is a quickstart you can use in your own project:
using System;
using Momento.Sdk;
using Momento.Sdk.Auth;
using Momento.Sdk.Config;
using Momento.Sdk.Responses;
ICredentialProvider authProvider = new EnvMomentoV2TokenProvider();
const string CACHE_NAME = "cache";
const string KEY = "MyKey";
const string VALUE = "MyData";
TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60);
using (ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authProvider, DEFAULT_TTL))
{
var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME);
if (createCacheResponse is CreateCacheResponse.Error createError)
{
Console.WriteLine($"Error creating cache: {createError.Message}. Exiting.");
Environment.Exit(1);
}
Console.WriteLine($"Setting key: {KEY} with value: {VALUE}");
var setResponse = await client.SetAsync(CACHE_NAME, KEY, VALUE);
if (setResponse is CacheSetResponse.Error setError)
{
Console.WriteLine($"Error setting value: {setError.Message}. Exiting.");
Environment.Exit(1);
}
Console.WriteLine($"Get value for key: {KEY}");
CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY);
if (getResponse is CacheGetResponse.Hit hitResponse)
{
Console.WriteLine($"Looked up value: {hitResponse.ValueString}, Stored value: {VALUE}");
}
else if (getResponse is CacheGetResponse.Error getError)
{
Console.WriteLine($"Error getting value: {getError.Message}");
}
}Documentation is available on the Momento Docs website.
Ready to dive right in? Just check out the examples directory for complete, working examples of how to use the SDK.
If you are interested in contributing to the SDK, please see the CONTRIBUTING docs.
For more info, visit our website at https://gomomento.com!