Skip to content
Tim Middleton edited this page Apr 17, 2023 · 24 revisions

What is the Coherence Go client?

The Coherence Go client allows Go applications to act as cache clients to a Coherence cluster using Google's gRPC framework for the network transport.

What versions of Go are supported?

The Coherence Go client supports Go version 1.19 and above.

Note: Version 1.18 of Go is not supported due to various generics bugs in Go itself.

What Coherence versions can I connect to?

The following Coherence versions are supported with a configured gRPCProxy.

  • Coherence CE versions 22.06.4+ and 23.03+
  • Coherence Commercial versions 14.1.1.2206.4+

Does the Coherence Go client support generics?

Yes, the Coherence Go client fully supports Go generics when accessing Coherence API's.

What Coherence API features are supported?

  • Familiar Map-like operations for manipulating cache entries such as:
    • Put, PutIfAbsent, PutAll, Get, GetAll, Remove, Clear, GetOrDefault, Replace, ReplaceMapping, Size, IsEmpty, ContainsKey, ContainsValue, ContainsEntry
  • Cluster-side querying, aggregation and filtering of map entries
  • Cluster-side manipulation of map entries using EntryProcessors
  • Registration of listeners to be notified of:
    • mutations such as insert, update and delete on Maps
    • map lifecycle events such as truncated, released or destroyed
    • session lifecycle events such as connected, disconnected, reconnected and closed
  • Support for storing Go structs as JSON as well as the ability to serialize to Java objects on the server for access from other Coherence language API's

How is data add via the Go client stored in Coherence?

By default, the Coherence Go Client serializes any keys and values to JSON and then stores them as JsonObjects in Coherence. This is usually sufficient for most applications where you are only accessing your data via the Go Client.

If you wish to access your data via other clients such as Java, JavaScript, C++, .NET or Python, you can use Java classes, known to Coherence server, representing the data model.

See the Documentation for more information.

What is the difference between a NamedMap and NamedCache?

NamedMap and NamedCache are identical except that NamedCache provides the PutWithExpiry function allowing you to expire cache entries. If you do not wish to expire entries, then just use NamedMap as entries will never expire.

Why do most functions return pointers to values rather than values?

The Coherence Go client return pointers to generic types, to allow for nil (or null equivalent in Java) values to be represented.

In Go, generic values cannot be nil and it is not correct assume a generic types' zero value represents nil as the zero value could represent a valid value. e.g. 0 for an int.

For example, the definition of Get() is shown below, in which if you try to get a value for a key which doesn't exist, it will return nil pointer.

type NamedMap[K comparable, V any] interface {
...
    // Get returns the value to which the specified key is mapped. V will be nil 
    // if there was no previous value.
    Get(ctx context.Context, key K) (*V, error)

We could use this example like below to test for a nil value or non-existence of a value for a key.

if value, err = namedCache.Get(ctx, 1); err != nil {
    panic(err)
    }

if value == nil {
   fmt.Println("Value for key 1 does not exist")
   return
}

// NOTE: we need to dereference the pointer otherwise we will get the pointer and not the value
fmt.Println("Value for key 1 is", *value) 

Where can I find code examples?

How can i report a problem?

If you would like to raise an issue please see here.

Please consult the security guide for our responsible security vulnerability disclosure process.

Where can I find more on Coherence?

What other clients/API's can I use to access Coherence?

Clone this wiki locally