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 .NET client library.
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
- .NET SDK Documentation: https://docs.momentohq.com/develop/sdks/dotnet
- Discuss: Momento Discord
Japanese: 日本語
The Momento Dotnet SDK package is available on nuget: momentohq/client-sdk-dotnet.
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 EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN");
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}");
}
}
Note that the above code requires an environment variable named MOMENTO_AUTH_TOKEN which must be set to a valid Momento authentication token.
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!