Official Java SDK for cachly.dev —
Managed Valkey/Redis cache built for AI apps. GDPR-compliant · German servers · Live in 30 seconds.
Maven:
<dependency>
<groupId>dev.cachly</groupId>
<artifactId>cachly-java</artifactId>
<version>0.1.1</version>
</dependency>Gradle:
implementation 'dev.cachly:cachly-java:0.1.1'Requires Java 17+. Uses Jedis 5 and Jackson.
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");
}Report report = cache.getOrSet(
"report:monthly",
() -> db.runExpensiveReport(),
Report.class,
60 // TTL seconds
);import dev.cachly.CachlyClient;
import dev.cachly.SemanticResult;
try (CachlyClient cache = CachlyClient.connect(System.getenv("CACHLY_URL"))) {
SemanticResult<String> 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());
}@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);
}
}| Method | Description |
|---|---|
connect(url) |
Create client from Redis URL |
get(key, Class<T>) |
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<T>, ttl) |
Get-or-set pattern |
semantic() |
SemanticCache helper |
raw() |
Direct UnifiedJedis access |
Bundle GET/SET/DEL/EXISTS/TTL operations into one HTTP request or Jedis pipeline.
CachlyClient cache = CachlyClient.builder()
.url(System.getenv("CACHLY_URL"))
.batchUrl(System.getenv("CACHLY_BATCH_URL")) // optional
.build();
List<BatchOpResult> 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 missingcachly 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.
npx @cachly-dev/initOr configure manually in your editor (~/.vscode/mcp.json / .cursor/mcp.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
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-tokenFind both values in your cachly.dev dashboard.
MIT © cachly.dev