PHPackages                             cachly-dev/sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. cachly-dev/sdk

ActiveLibrary[Caching](/categories/caching)

cachly-dev/sdk
==============

Official PHP SDK for cachly.dev – Managed Valkey/Redis cache with semantic AI caching

0.1.0-beta.1(1mo ago)11MITPHPPHP ^8.1

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/cachly-dev/sdk-php)[ Packagist](https://packagist.org/packages/cachly-dev/sdk)[ Docs](https://cachly.dev)[ RSS](/packages/cachly-dev-sdk/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

cachly PHP SDK
==============

[](#cachly-php-sdk)

Official PHP SDK for [cachly.dev](https://cachly.dev) – Managed Valkey/Redis cache.

**GDPR-compliant · German servers · Live in 30 seconds**

Installation
------------

[](#installation)

```
composer require cachly/sdk
```

> Requires PHP ≥ 8.1 and `predis/predis ^2.2`.

Quick Start
-----------

[](#quick-start)

```
use Cachly\CachlyClient;

$cache = new CachlyClient('redis://:your-password@my-instance.cachly.dev:6379');

// Set a value with TTL
$cache->set('user:42', ['name' => 'Alice', 'plan' => 'pro'], ttl: 300);

// Get a value
$user = $cache->get('user:42'); // ['name' => 'Alice', 'plan' => 'pro']

// Check existence
if ($cache->exists('user:42')) { ... }

// TTL refresh
$cache->expire('user:42', 600);

// Atomic counter
$count = $cache->incr('page:views');

// Delete
$cache->del('user:42');
```

Get-or-Set Pattern
------------------

[](#get-or-set-pattern)

```
$data = $cache->getOrSet(
    key: 'expensive:report',
    fn:  fn() => $db->runExpensiveReport(),
    ttl: 60,
);
```

Semantic AI Cache (Speed / Business tiers)
------------------------------------------

[](#semantic-ai-cache-speed--business-tiers)

Cache LLM responses by *meaning*, not just exact key. Cut OpenAI costs by 60%.

```
use Cachly\CachlyClient;

$cache  = new CachlyClient(getenv('CACHLY_URL'));
$openai = new OpenAI\Client(getenv('OPENAI_API_KEY'));

$embedFn = fn(string $text) => $openai
    ->embeddings()
    ->create(['model' => 'text-embedding-3-small', 'input' => $text])
    ->data[0]->embedding;

$result = $cache->semantic()->getOrSet(
    prompt:              $userQuestion,
    fn:                  fn() => $openai->chat($userQuestion),
    embedFn:             $embedFn,
    similarityThreshold: 0.90,
    ttl:                 3600,
);

echo $result->hit
    ? "⚡ Cache hit (similarity={$result->similarity})"
    : "🔄 Fresh from LLM";
echo $result->value;
```

Laravel Integration
-------------------

[](#laravel-integration)

```
// config/cachly.php
return ['url' => env('CACHLY_URL')];

// AppServiceProvider
$this->app->singleton(CachlyClient::class, fn() => new CachlyClient(config('cachly.url')));

// In a controller / service
public function __construct(private CachlyClient $cache) {}
```

API Reference
-------------

[](#api-reference)

MethodDescription`get(string $key)`Get a value (null if not found)`set(string $key, mixed $value, ?int $ttl)`Set a value`del(string ...$keys): int`Delete keys, returns count`exists(string $key): bool`Check existence`expire(string $key, int $seconds)`Update TTL`incr(string $key): int`Atomic increment`getOrSet(string $key, callable $fn, ?int $ttl)`Get-or-set pattern`semantic(): SemanticCache`Access semantic cache helper`raw(): PredisClient`Direct Predis accessBatch API — Multiple Ops in One Round-Trip
------------------------------------------

[](#batch-api--multiple-ops-in-one-round-trip)

Bundle GET/SET/DEL/EXISTS/TTL operations into **one** HTTP request or Predis pipeline.

```
use Cachly\CachlyClient;
use Cachly\BatchOp;

$cache = new CachlyClient(
    url: $_ENV['CACHLY_URL'],
    batchUrl: $_ENV['CACHLY_BATCH_URL'] ?? null, // optional
);

$results = $cache->batch([
    BatchOp::get('user:1'),
    BatchOp::get('config:app'),
    BatchOp::set('visits', '42', ttl: 86400),
    BatchOp::exists('session:xyz'),
    BatchOp::ttl('token:abc'),
]);

$user  = $results[0]->value;       // string|null
$ok    = $results[2]->ok;          // bool
$found = $results[3]->exists;      // bool
$secs  = $results[4]->ttlSeconds;  // int (-1 = no TTL, -2 = key missing)
```

Environment Variables
---------------------

[](#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](https://cachly.dev/instances).

AI Dev Brain — Persistent Memory for Your Coding Assistant
----------------------------------------------------------

[](#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.

```
npx @cachly-dev/init
```

`session_start(instance_id, focus)` returns a full briefing in one call: last session summary, relevant lessons, open failures, brain health.

→ Full docs: [cachly.dev/docs/ai-memory](https://cachly.dev/docs/ai-memory)

---

Links
-----

[](#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-php/issues)
- 📦 [Packagist](https://packagist.org/packages/cachly/sdk)

---

MIT © [cachly.dev](https://cachly.dev)

###  Health Score

32

—

LowBetter than 70% of packages

Maintenance89

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0f95fc2e094467506360a0fc361dee84fa4f8f567934ea8da2119cf58d5a3f6?d=identicon)[HeinrichNebula](/maintainers/HeinrichNebula)

---

Top Contributors

[![HeinrichNebula](https://avatars.githubusercontent.com/u/137402513?v=4)](https://github.com/HeinrichNebula "HeinrichNebula (1 commits)")

---

Tags

rediscachellmeudsgvovalkeycachlysemantic-cache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cachly-dev-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/cachly-dev-sdk/health.svg)](https://phpackages.com/packages/cachly-dev-sdk)
```

###  Alternatives

[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

242.6M13](/packages/cache-predis-adapter)[contributte/redis

Redis client integration into Nette framework

191.7M2](/packages/contributte-redis)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1418.0k](/packages/byerikas-cache-tags)[pstaender/silverstripe-redis-cache

Enables Redis cache for SilverStripe

11102.0k](/packages/pstaender-silverstripe-redis-cache)[abouvier/slim-redis-cache

Redis cache middleware for Slim framework

172.0k](/packages/abouvier-slim-redis-cache)[quick/cache

This is a cache system that uses Redis for rapid caching.

122.7k](/packages/quick-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
