Skip to content

Commit

Permalink
fix: add example to fix readme generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nand4011 committed Jan 5, 2024
1 parent 642b661 commit b0e319a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit b0e319a

Please sign in to comment.