Cache Encodings with the Go Client
|
Tip
|
The source code for this tutorial is available on GitHub. |
This tutorial demonstrates how to use different cache encodings with the Go Hot Rod client.
Prerequisites
-
A running Infinispan server.
-
Go 1.25 or later.
Running the Example
go run ./encoding
Code Walkthrough
Text Cache
Create a cache with text/plain encoding and use PutRaw and GetRaw with the appropriate media type.
textCache.PutRaw(ctx, []byte("greeting"), []byte("Hello, Infinispan!"), codec.MediaIDTextPlain)
val, found, err := textCache.GetRaw(ctx, []byte("greeting"), codec.MediaIDTextPlain)
JSON Cache
Create a cache with application/json encoding and store JSON documents.
jsonCache.PutRaw(ctx, []byte(`"name"`), []byte(`{"project": "infinispan"}`), codec.MediaIDJSON)
Expected Output
Caches ready.
== Cache with text/plain encoding ==
textCache[greeting] = Hello, Infinispan!
== Cache with application/json encoding ==
jsonCache[name] = {"project": "infinispan"}
Caches removed.


