|  | 
|  | 1 | +--- | 
|  | 2 | +type: docs | 
|  | 3 | +title: "Coherence" | 
|  | 4 | +linkTitle: "Coherence" | 
|  | 5 | +description: Detailed information on the Coherence state store component | 
|  | 6 | +aliases: | 
|  | 7 | +  - "/operations/components/setup-state-store/supported-state-stores/setup-coherence/" | 
|  | 8 | +--- | 
|  | 9 | + | 
|  | 10 | +## Component format | 
|  | 11 | + | 
|  | 12 | +To setup Coherence state store, create a component of type `state.coherence`. See [this guide]({{< ref "howto-get-save-state.md#step-1-setup-a-state-store" >}}) on how to create and apply a state store configuration. | 
|  | 13 | + | 
|  | 14 | +```yaml | 
|  | 15 | +apiVersion: dapr.io/v1alpha1 | 
|  | 16 | +kind: Component | 
|  | 17 | +metadata: | 
|  | 18 | +  name: <NAME> | 
|  | 19 | +spec: | 
|  | 20 | +  type: state.coherence | 
|  | 21 | +  version: v1 | 
|  | 22 | +  metadata: | 
|  | 23 | +  - name: serverAddress | 
|  | 24 | +    value: <REPLACE-WITH-GRPC-PROXY-HOST-AND-PORT> # Required. Example: "my-cluster-grpc:1408" | 
|  | 25 | +  - name: tlsEnabled | 
|  | 26 | +    value: <REPLACE-WITH-BOOLEAN> # Optional | 
|  | 27 | +  - name: tlsClientCertPath | 
|  | 28 | +    value: <REPLACE-WITH-PATH> # Optional | 
|  | 29 | +  - name: tlsClientKey | 
|  | 30 | +    value: <REPLACE-WITH-PATH> # Optional | 
|  | 31 | +  - name: tlsCertsPath | 
|  | 32 | +    value: <REPLACE-WITH-PATH> # Optional | 
|  | 33 | +  - name: ignoreInvalidCerts | 
|  | 34 | +    value: <REPLACE-WITH-BOOLEAN> # Optional | 
|  | 35 | +  - name: scopeName | 
|  | 36 | +    value: <REPLACE-WITH-SCOPE> # Optional | 
|  | 37 | +  - name: requestTimeout | 
|  | 38 | +    value: <REPLACE-WITH-REQUEST-TIMEOUT> # Optional | 
|  | 39 | +  - name: nearCacheTTL | 
|  | 40 | +    value: <REPLACE-WITH-NEAR-CACHE-TTL> # Optional | 
|  | 41 | +  - name: nearCacheUnits | 
|  | 42 | +    value: <REPLACE-WITH-NEAR-CACHE-UNITS> # Optional | 
|  | 43 | +  - name: nearCacheMemory | 
|  | 44 | +    value: <REPLACE-WITH-NEAR-CACHE-MEMORY> # Optional | 
|  | 45 | +``` | 
|  | 46 | +
 | 
|  | 47 | +{{% alert title="Warning" color="warning" %}} | 
|  | 48 | +The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here]({{< ref component-secrets.md >}}). | 
|  | 49 | +{{% /alert %}} | 
|  | 50 | +
 | 
|  | 51 | +## Spec metadata fields | 
|  | 52 | +
 | 
|  | 53 | +| Field              | Required | Details                                                                                                                                     | Example                                       | | 
|  | 54 | +|--------------------|:--------:|---------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| | 
|  | 55 | +| serverAddress      |    Y     | Comma delimited endpoints                                                                                                                   | `"my-cluster-grpc:1408"`                      | | 
|  | 56 | +| tlsEnabled         |    N     | Indicates if TLS should be enabled. Defaults to false                                                                                       | `"true"`                                      | | 
|  | 57 | +| tlsClientCertPath  |    N     | Client certificate path for Coherence. Defaults to "". Can be `secretKeyRef` to use a [secret reference]({{< ref component-secrets.md >}}). | `"-----BEGIN CERTIFICATE-----\nMIIC9TCCA..."` | | 
|  | 58 | +| tlsClientKey       |    N     | Client key for Coherence. Defaults to "". Can be `secretKeyRef` to use a [secret reference]({{< ref component-secrets.md >}}).              | `"-----BEGIN CERTIFICATE-----\nMIIC9TCCA..."` | | 
|  | 59 | +| tlsCertsPath       |    N     | Additional certificates for Coherence. Defaults to "". Can be `secretKeyRef` to use a [secret reference]({{< ref component-secrets.md >}}). | `"-----BEGIN CERTIFICATE-----\nMIIC9TCCA..."` | | 
|  | 60 | +| ignoreInvalidCerts |    N     | Indicates if to ignore self-signed certificates for testing only, not to be used in production. Defaults to false                           | `"false"`                                     | | 
|  | 61 | +| scopeName          |    N     | A scope name to use for the internal cache. Defaults to ""                                                                                  | `"my-scope"`                                  | | 
|  | 62 | +| requestTimeout     |    N     | ATimeout for calls to the cluster Defaults to "30s"                                                                                         | `"15s"`                                       | | 
|  | 63 | +| nearCacheTTL       |    N     | If non-zero a near cache is used and the TTL of the near cache is this value. Defaults to 0s                                                | `"60s"`                                       | | 
|  | 64 | +| nearCacheUnits     |    N     | If non-zero a near cache is used and the maximum size of the near cache is this value in units. Defaults to 0                               | `"1000"`                                      | | 
|  | 65 | +| nearCacheMemory    |    N     | If non-zero a near cache is used and the maximum size of the near cache is this value in bytes. Defaults to 0                               | `"4096"`                                      | | 
|  | 66 | + | 
|  | 67 | +### About Using Near Cache TTL | 
|  | 68 | + | 
|  | 69 | +The Coherence state store allows you to specify a near cache to cache frequently accessed data when using the DAPR client. | 
|  | 70 | +When you access data using `Get(ctx context.Context, req *GetRequest)`, returned entries are stored in the near cache and  | 
|  | 71 | +subsequent data access for keys in the near cache is almost instant, where without a near cache each `Get()` operation results in a network call. | 
|  | 72 | + | 
|  | 73 | +When using the near cache option, Coherence automatically adds a MapListener to the internal cache which listens on all cache events and updates or invalidates entries in the near cache that have been changed or removed on the server. | 
|  | 74 | + | 
|  | 75 | +To manage the amount of memory used by the near cache, the following options are supported when creating one: | 
|  | 76 | + | 
|  | 77 | +- nearCacheTTL – objects expired after time in near cache, for example 5 minutes | 
|  | 78 | +- nearCacheUnits – maximum number of cache entries in the near cache | 
|  | 79 | +- nearCacheMemory – maximum amount of memory used by cache entries | 
|  | 80 | + | 
|  | 81 | +You can specify either High-Units or Memory and in either case, optionally, a TTL. | 
|  | 82 | + | 
|  | 83 | +The minimum expiry time for a near cache entry is 1/4 second. This is to ensure that expiry of elements is as  | 
|  | 84 | +efficient as possible. You will receive an error if you try to set the TTL to a lower value. | 
|  | 85 | + | 
|  | 86 | +## Setup Coherence | 
|  | 87 | + | 
|  | 88 | +{{< tabs "Self-Hosted" "Kubernetes" >}} | 
|  | 89 | + | 
|  | 90 | +{{% codetab %}} | 
|  | 91 | +Run Coherence locally using Docker: | 
|  | 92 | + | 
|  | 93 | +``` | 
|  | 94 | +docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:25.03.1 | 
|  | 95 | +``` | 
|  | 96 | + | 
|  | 97 | +You can then interact with the server using `localhost:1408`. | 
|  | 98 | +{{% /codetab %}} | 
|  | 99 | + | 
|  | 100 | +{{% codetab %}} | 
|  | 101 | +The easiest way to install Coherence on Kubernetes is by using the [Coherence Operator](https://docs.coherence.community/coherence-operator/docs/latest/docs/about/03_quickstart): | 
|  | 102 | + | 
|  | 103 | +**Install the Operator:** | 
|  | 104 | + | 
|  | 105 | +``` | 
|  | 106 | +kubectl apply -f https://github.com/oracle/coherence-operator/releases/download/v3.5.2/coherence-operator.yaml | 
|  | 107 | +``` | 
|  | 108 | +
 | 
|  | 109 | +> Note: Change v3.5.2 to the latest release. | 
|  | 110 | +
 | 
|  | 111 | +This installs the Coherence operator into the `coherence` namespace. | 
|  | 112 | +
 | 
|  | 113 | +**Create a Coherence Cluster yaml my-cluster.yaml** | 
|  | 114 | +
 | 
|  | 115 | +```yaml | 
|  | 116 | +apiVersion: coherence.oracle.com/v1 | 
|  | 117 | +kind: Coherence | 
|  | 118 | +metadata: | 
|  | 119 | +  name: my-cluster | 
|  | 120 | +spec: | 
|  | 121 | +  coherence: | 
|  | 122 | +    management: | 
|  | 123 | +      enabled: true | 
|  | 124 | +  ports: | 
|  | 125 | +    - name: management | 
|  | 126 | +    - name: grpc | 
|  | 127 | +      port: 1408 | 
|  | 128 | +``` | 
|  | 129 | + | 
|  | 130 | +**Apply the yaml** | 
|  | 131 | + | 
|  | 132 | +```bash | 
|  | 133 | +kubectl apply -f my-cluster.yaml | 
|  | 134 | +``` | 
|  | 135 | + | 
|  | 136 | +To interact with Coherence, find the service with: `kubectl get svc` and look for service named '*grpc'. | 
|  | 137 | + | 
|  | 138 | +```bash | 
|  | 139 | +NAME                    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                                               AGE | 
|  | 140 | +kubernetes              ClusterIP   10.96.0.1      <none>        443/TCP                                               9m | 
|  | 141 | +my-cluster-grpc         ClusterIP   10.96.225.43   <none>        1408/TCP                                              7m3s | 
|  | 142 | +my-cluster-management   ClusterIP   10.96.41.6     <none>        30000/TCP                                             7m3s | 
|  | 143 | +my-cluster-sts          ClusterIP   None           <none>        7/TCP,7575/TCP,7574/TCP,6676/TCP,30000/TCP,1408/TCP   7m3s | 
|  | 144 | +my-cluster-wka          ClusterIP   None           <none>        7/TCP,7575/TCP,7574/TCP,6676/TCP                      7m3s | 
|  | 145 | +``` | 
|  | 146 | + | 
|  | 147 | +For example, if installing using the example above, the Coherence host address would be: | 
|  | 148 | + | 
|  | 149 | +`my-cluster-grpc` | 
|  | 150 | +{{% /codetab %}} | 
|  | 151 | + | 
|  | 152 | +{{< /tabs >}} | 
|  | 153 | + | 
|  | 154 | +## Related links | 
|  | 155 | +- [Basic schema for a Dapr component]({{< ref component-schema >}}) | 
|  | 156 | +- Read [this guide]({{< ref "howto-get-save-state.md#step-2-save-and-retrieve-a-single-state" >}}) for instructions on configuring state store components | 
|  | 157 | +- [State management building block]({{< ref state-management >}}) | 
|  | 158 | +- [Coherence CE on GitHub](https://github.com/oracle/coherence) | 
|  | 159 | +- [Coherence Community - All things Coherence](https://coherence.community/) | 
0 commit comments