Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cachly Java SDK

Official Java SDK for cachly.dev
Managed Valkey/Redis cache built for AI apps. GDPR-compliant · German servers · Live in 30 seconds.

Maven Central Java 17+ License: MIT GDPR: EU-only

Installation

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.

Quick Start

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

Report report = cache.getOrSet(
    "report:monthly",
    () -> db.runExpensiveReport(),
    Report.class,
    60  // TTL seconds
);

Semantic AI Cache (Speed / Business tiers)

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());
}

Spring Boot Integration

@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<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

Batch API — Multiple Ops in One Round-Trip

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 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.

npx @cachly-dev/init

Or 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


Environment Variables

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.

Links


MIT © cachly.dev

About

Official Cachly sdk-java SDK

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages