Skip to content

nand4011/client-sdk-dotnet

This branch is 116 commits behind momentohq/client-sdk-dotnet:main.

Folders and files

NameName
Last commit message
Last commit date
Sep 11, 2023
Oct 14, 2022
Sep 13, 2023
Sep 13, 2023
Sep 11, 2023
Jun 13, 2023
Aug 11, 2023
Feb 1, 2022
Jun 1, 2023
Mar 16, 2023
Apr 10, 2023
Jun 26, 2023
Jun 2, 2023
Jun 2, 2023

Repository files navigation

logo

project status project stability

Momento .NET Client Library

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.

Japanese: 日本語

Packages

The Momento Dotnet SDK package is available on nuget: momentohq/client-sdk-dotnet.

Usage

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.

Getting Started and Documentation

Documentation is available on the Momento Docs website.

Examples

Ready to dive right in? Just check out the examples directory for complete, working examples of how to use the SDK.

Developing

If you are interested in contributing to the SDK, please see the CONTRIBUTING docs.


For more info, visit our website at https://gomomento.com!

About

Official .NET SDK for Momento Serverless Cache

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Makefile 0.2%