https://github.com/cachly-dev/sdk-java
Official Cachly sdk-java SDK
https://github.com/cachly-dev/sdk-java
Last synced: about 15 hours ago
JSON representation
Official Cachly sdk-java SDK
- Host: GitHub
- URL: https://github.com/cachly-dev/sdk-java
- Owner: cachly-dev
- Created: 2026-04-16T21:45:49.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-16T22:16:51.000Z (2 months ago)
- Last Synced: 2026-04-16T23:38:39.025Z (2 months ago)
- Language: Java
- Size: 64.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# cachly Java SDK
> Official Java SDK for [cachly.dev](https://cachly.dev) โ
> Managed Valkey/Redis cache built for AI apps. **GDPR-compliant ยท German servers ยท Live in 30 seconds.**
[](https://central.sonatype.com/artifact/dev.cachly/cachly-java)
[](https://central.sonatype.com/artifact/dev.cachly/cachly-java)
[](../../LICENSE)
[](https://cachly.dev/legal)
## Installation
**Maven:**
```xml
dev.cachly
cachly-java
0.1.1
```
**Gradle:**
```groovy
implementation 'dev.cachly:cachly-java:0.1.1'
```
> Requires Java 17+. Uses Jedis 5 and Jackson.
## Quick Start
```java
import dev.cachly.CachlyClient;
try (CachlyClient cache = CachlyClient.connect(System.getenv("CACHLY_URL"))) {
// Set with TTL
cache.set("user:42", Map.of("name", "Alice", "plan", "pro"), 300);
// Get
Map, ?> user = cache.get("user:42", Map.class);
// Exists / delete
cache.exists("user:42");
cache.del("user:42");
// Atomic counter
long count = cache.incr("page:views");
}
```
## Get-or-Set Pattern
```java
Report report = cache.getOrSet(
"report:monthly",
() -> db.runExpensiveReport(),
Report.class,
60 // TTL seconds
);
```
## Semantic AI Cache (Speed / Business tiers)
```java
import dev.cachly.CachlyClient;
import dev.cachly.SemanticResult;
try (CachlyClient cache = CachlyClient.connect(System.getenv("CACHLY_URL"))) {
SemanticResult result = cache.semantic().getOrSet(
userQuestion,
() -> openAI.ask(userQuestion), // expensive call on cache miss
text -> openAI.embed(text), // embedding function
0.92, // similarity threshold
3600, // TTL seconds
"cachly:sem" // namespace
);
System.out.printf("%s %s%n",
result.isHit() ? "โก hit (sim=" + result.getSimilarity() + ")" : "๐ miss",
result.getValue());
}
```
## Spring Boot Integration
```java
@Configuration
public class CachlyConfig {
@Value("${cachly.url}") private String url;
@Bean(destroyMethod = "close")
public CachlyClient cachlyClient() {
return CachlyClient.connect(url);
}
}
// In a service:
@Service
public class UserService {
private final CachlyClient cache;
public UserService(CachlyClient cache) {
this.cache = cache;
}
public User getUser(String id) {
return cache.getOrSet("user:" + id, () -> userRepo.findById(id), User.class, 300);
}
}
```
## API Reference
| Method | Description |
|---|---|
| `connect(url)` | Create client from Redis URL |
| `get(key, Class)` | Get value (null if not found) |
| `set(key, value, ttlSeconds)` | Set value |
| `del(String... keys): long` | Delete keys |
| `exists(key): boolean` | Check existence |
| `expire(key, seconds)` | Update TTL |
| `incr(key): long` | Atomic increment |
| `getOrSet(key, fn, Class, ttl)` | Get-or-set pattern |
| `semantic()` | `SemanticCache` helper |
| `raw()` | Direct `UnifiedJedis` access |
## Batch API โ Multiple Ops in One Round-Trip
Bundle GET/SET/DEL/EXISTS/TTL operations into **one** HTTP request or Jedis pipeline.
```java
CachlyClient cache = CachlyClient.builder()
.url(System.getenv("CACHLY_URL"))
.batchUrl(System.getenv("CACHLY_BATCH_URL")) // optional
.build();
List results = cache.batch(List.of(
BatchOp.get("user:1"),
BatchOp.get("config:app"),
BatchOp.set("visits", "42", 86400),
BatchOp.exists("session:xyz"),
BatchOp.ttl("token:abc")
));
String user = results.get(0).getValue(); // null on miss
boolean ok = results.get(2).isOk();
boolean found = results.get(3).isExists();
long secs = results.get(4).getTtlSeconds(); // -1 = no TTL, -2 = key missing
```
---
## AI Dev Brain โ Persistent Memory for Your Coding Assistant
cachly ships a **30-tool MCP server** that gives Claude Code, Cursor, GitHub Copilot, and Windsurf a persistent memory across sessions โ so they never forget your architecture, lessons learned, or last session context.
```bash
npx @cachly-dev/init
```
Or configure manually in your editor (`~/.vscode/mcp.json` / `.cursor/mcp.json`):
```json
{
"servers": {
"cachly": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cachly-dev/mcp-server"],
"env": { "CACHLY_JWT": "your-jwt-token" }
}
}
}
```
`session_start(instance_id, focus)` returns a full briefing in one call: last session summary, relevant lessons, open failures, brain health. 60 % fewer file reads, instant context, zero re-discovery.
โ Full docs: [cachly.dev/docs/ai-memory](https://cachly.dev/docs/ai-memory)
---
## Environment Variables
```bash
CACHLY_URL=redis://:your-password@my-app.cachly.dev:30101
CACHLY_BATCH_URL=https://api.cachly.dev/v1/cache/YOUR_TOKEN # optional
# Speed / Business tier โ Semantic AI Cache:
CACHLY_VECTOR_URL=https://api.cachly.dev/v1/sem/your-vector-token
```
Find both values in your [cachly.dev dashboard](https://cachly.dev/instances).
## Links
- ๐ [cachly.dev docs](https://cachly.dev/docs)
- ๐ง [AI Memory / MCP Server](https://cachly.dev/docs/ai-memory)
- ๐ [Issues](https://github.com/cachly-dev/sdk-java/issues)
- ๐ฆ [Maven Central](https://central.sonatype.com/artifact/dev.cachly/cachly-java)
---
MIT ยฉ [cachly.dev](https://cachly.dev)