Skip to content

momentohq/client-sdk-kotlin

Repository files navigation

logo

project status project stability

Momento Client Library for Kotlin

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 Kotlin.

To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.

Packages

The Kotlin SDK is available on Maven Central:

Gradle

dependencies {
    implementation("software.momento.kotlin:sdk:0.1.3")
}

Maven

<dependency>
    <groupId>software.momento.kotlin</groupId>
    <artifactId>sdk</artifactId>
    <version>0.1.3</version>
</dependency>

Usage

package software.momento.example.doc_examples

import kotlinx.coroutines.runBlocking
import software.momento.kotlin.sdk.CacheClient
import software.momento.kotlin.sdk.auth.CredentialProvider
import software.momento.kotlin.sdk.config.Configurations
import software.momento.kotlin.sdk.responses.cache.GetResponse
import kotlin.time.Duration.Companion.seconds

fun main() = runBlocking {
    CacheClient(
        CredentialProvider.fromEnvVar("MOMENTO_API_KEY"),
        Configurations.Laptop.latest,
        60.seconds
    ).use { client ->
        val cacheName = "cache"

        client.createCache(cacheName)

        client.set(cacheName, "key", "value")

        when (val response = client.get(cacheName, "key")) {
            is GetResponse.Hit -> println("Hit: ${response.value}")
            is GetResponse.Miss -> println("Miss")
            is GetResponse.Error -> throw response
        }
    }
}

Getting Started and Documentation

Documentation is available on the Momento Docs website.

Examples

Working example projects, with all required build configuration files, are available in the examples subdirectory.

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!