diff --git a/README.template.md b/README.template.md index b252a97..d77ca0c 100644 --- a/README.template.md +++ b/README.template.md @@ -34,7 +34,9 @@ dependencies { ## Usage -Examples coming soon. +```kotlin +{% include "./examples/src/main/kotlin/software/momento/example/doc_examples/ReadmeExample.kt" %} +``` ## Getting Started and Documentation diff --git a/examples/src/main/kotlin/software/momento/example/doc_examples/ReadmeExample.kt b/examples/src/main/kotlin/software/momento/example/doc_examples/ReadmeExample.kt new file mode 100644 index 0000000..f45c51e --- /dev/null +++ b/examples/src/main/kotlin/software/momento/example/doc_examples/ReadmeExample.kt @@ -0,0 +1,28 @@ +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 + } + } +}