---
title: "JCache Integration"
description: "Learn how to trace cache operations using the Sentry JCache (JSR-107) integration."
url: https://docs.sentry.io/platforms/java/integrations/jcache/
---

# JCache Integration | Sentry for Java

Sentry's [JCache (JSR-107)](https://www.jcp.org/en/jsr/detail?id=107) integration automatically creates spans for cache operations like `get`, `put`, `remove`, and `clear`. It works with any JCache provider (Caffeine, Ehcache, Hazelcast, etc.).

Cache spans appear in Sentry's [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/).

## [Install](https://docs.sentry.io/platforms/java/integrations/jcache.md#install)

```groovy
implementation 'io.sentry:sentry-jcache:8.36.0'
```

For other dependency managers, check out the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-jcache).

## [Set Up](https://docs.sentry.io/platforms/java/integrations/jcache.md#set-up)

Enable cache tracing in your Sentry configuration:

```java
Sentry.init(options -> {
    options.setDsn("___DSN___");
    options.setTracesSampleRate(1.0);
    options.setEnableCacheTracing(true);
});
```

Wrap your `javax.cache.Cache` instance with `SentryJCacheWrapper`:

```java
import io.sentry.jcache.SentryJCacheWrapper;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.spi.CachingProvider;

CachingProvider provider = Caching.getCachingProvider();
CacheManager manager = provider.getCacheManager();

Cache<String, String> cache = manager.getCache("myCache");
Cache<String, String> sentryCache = new SentryJCacheWrapper<>(cache);

// Use sentryCache — all operations produce Sentry spans
sentryCache.put("key", "value");       // cache.put span
String val = sentryCache.get("key");   // cache.get span (cache.hit = true)
sentryCache.remove("key");             // cache.remove span
sentryCache.clear();                   // cache.clear span
```

## [Traced Operations](https://docs.sentry.io/platforms/java/integrations/jcache.md#traced-operations)

All JCache operations are traced. Each method creates a span with the operation `cache.<methodName>` (e.g. `cache.get`, `cache.putIfAbsent`, `cache.removeAll`).

## [Span Data](https://docs.sentry.io/platforms/java/integrations/jcache.md#span-data)

| Key               | Type            | Description                                                                                                                                                                                                                                         |
| ----------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cache.hit`       | boolean         | Whether the cache lookup returned a value (read spans only)                                                                                                                                                                                         |
| `cache.key`       | list of strings | The cache key(s) involved in the operation                                                                                                                                                                                                          |
| `cache.operation` | string          | The JCache method name (e.g. `get`, `putIfAbsent`, `removeAll`)                                                                                                                                                                                     |
| `cache.write`     | boolean         | Whether the operation modified the cache. Always `true` for unconditional writes (`put`, `putAll`, `remove`, `clear`); reflects the actual outcome for conditional operations (`putIfAbsent`, `replace`, `getAndReplace`) and value-matched removes |

Bulk operations (`getAll`, `putAll`, `removeAll`) create a single span with all keys listed in `cache.key`.

## [Verify](https://docs.sentry.io/platforms/java/integrations/jcache.md#verify)

To verify, trigger a cache operation within an active transaction and check the [Caches dashboard](https://sentry.io/orgredirect/organizations/:orgslug/insights/backend/caches/) or the trace view in Sentry.

```java
import io.sentry.ISentryLifecycleToken;
import io.sentry.ITransaction;
import io.sentry.Sentry;

ITransaction tx = Sentry.startTransaction("test-cache", "task");
try (ISentryLifecycleToken ignored = tx.makeCurrent()) {
    sentryCache.put("greeting", "hello");
    String value = sentryCache.get("greeting");
} finally {
    tx.finish();
}
```
