Basic Cache Operations with the .NET Client

Tip
The source code for this tutorial is available on GitHub.

This tutorial demonstrates how to connect to an Infinispan server and perform basic cache operations using the .NET Hot Rod client.

Prerequisites

  • A running Infinispan server.

  • .NET 10 or later.

Running the Example

dotnet run --project cache

Code Walkthrough

Connecting to the Server

The example connects to the Infinispan server using a Hot Rod URI. You can override the default URI by setting the INFINISPAN_URI environment variable.

var client = InfinispanClient.FromUri("hotrod://admin:password@localhost:11222");

Creating the Cache

The example creates a cache using the administration API.

await admin.GetOrCreateCache("test");

Storing and Retrieving Entries

Use Put to store a key-value pair and Get to retrieve it.

await cache.Put("key", "value");
var result = await cache.Get("key");

Expected Output

Cache 'test' ready.
key = value
Cache removed.