{"id":50879034,"url":"https://github.com/cachly-dev/cachly-swift","last_synced_at":"2026-06-15T12:03:38.772Z","repository":{"id":351888254,"uuid":"1212925943","full_name":"cachly-dev/cachly-swift","owner":"cachly-dev","description":"Official Cachly sdk-swift SDK","archived":false,"fork":false,"pushed_at":"2026-04-17T02:21:11.000Z","size":30,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-29T00:28:31.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cachly-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-16T21:45:53.000Z","updated_at":"2026-04-20T10:28:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cachly-dev/cachly-swift","commit_stats":null,"previous_names":["cachly-dev/sdk-swift","cachly-dev/cachly-swift"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cachly-dev/cachly-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachly-dev%2Fcachly-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachly-dev%2Fcachly-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachly-dev%2Fcachly-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachly-dev%2Fcachly-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cachly-dev","download_url":"https://codeload.github.com/cachly-dev/cachly-swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cachly-dev%2Fcachly-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34361404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-15T12:03:36.061Z","updated_at":"2026-06-15T12:03:38.766Z","avatar_url":"https://github.com/cachly-dev.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cachly Swift SDK\n\nOfficial Swift SDK for [cachly.dev](https://cachly.dev) – Managed Valkey/Redis cache.\n\n**GDPR-compliant · German servers · Live in 30 seconds**  \n**iOS 17+ · macOS 14+ · Server-side Swift (Vapor) · async/await native**\n\n## Installation\n\n```swift\n// Package.swift\n.package(url: \"https://github.com/cachly-dev/sdk-swift.git\", from: \"0.1.0-beta.1\"),\n// target dependencies:\n.product(name: \"Cachly\", package: \"sdk-swift\"),\n```\n\nOr in Xcode: **File → Add Package Dependencies** → paste URL above.\n\n## Quick Start\n\n```swift\nimport Cachly\n\nlet cache = try await CachlyClient.connect(url: ProcessInfo.processInfo.environment[\"CACHLY_URL\"]!)\n\n// Set with TTL\ntry await cache.set(\"user:42\", value: User(name: \"Alice\", plan: \"pro\"), ttl: .seconds(300))\n\n// Get\nlet user: User? = try await cache.get(\"user:42\")\n\n// Get-or-set\nlet report: Report = try await cache.getOrSet(\"report:monthly\", ttl: .seconds(60)) {\n    try await db.heavyQuery()\n}\n\n// Atomic counter\nlet count = try await cache.incr(\"page:views\")\n\n// Delete\ntry await cache.del(\"user:42\")\n```\n\n## Semantic AI Cache (Speed / Business tiers)\n\nCache LLM responses by *meaning*, not just exact key. Cut OpenAI costs by 60%.\n\n```swift\nimport Cachly\n\nlet result: SemanticResult\u003cString\u003e = try await cache.semantic.getOrSet(\n    userQuestion,\n    fn: { try await openAI.ask(userQuestion) },\n    embedFn: { text in try await openAI.embed(text) },\n    options: SemanticOptions(\n        similarityThreshold: 0.92,\n        ttl: .hours(1)\n    )\n)\n\nif result.hit {\n    print(\"⚡ Cache hit – similarity: \\(result.similarity!)\")\n} else {\n    print(\"🔄 Fresh from LLM\")\n}\nprint(result.value)\n```\n\n## Vapor Integration\n\n```swift\nimport Vapor\nimport Cachly\n\n// configure.swift\npublic func configure(_ app: Application) async throws {\n    let cache = try await CachlyClient.connect(\n        url: Environment.get(\"CACHLY_URL\")!)\n    app.storage[CachlyKey.self] = cache\n}\n\nstruct CachlyKey: StorageKey { typealias Value = CachlyClient }\n\nextension Request {\n    var cachly: CachlyClient { application.storage[CachlyKey.self]! }\n}\n\n// In a route handler:\napp.get(\"user\", \":id\") { req async throws -\u003e User in\n    let id = req.parameters.get(\"id\")!\n    return try await req.cachly.getOrSet(\"user:\\(id)\", ttl: .seconds(300)) {\n        try await User.find(id, on: req.db).unwrap(or: Abort(.notFound))\n    }\n}\n```\n\n## iOS Usage\n\n```swift\n// Works great in SwiftUI with `@MainActor` / `Task { }`:\nstruct ContentView: View {\n    @State private var answer = \"\"\n\n    var body: some View {\n        Button(\"Ask AI\") {\n            Task {\n                let result: SemanticResult\u003cString\u003e = try await cache.semantic.getOrSet(\n                    question,\n                    fn: { try await openAI.ask(question) },\n                    embedFn: { try await openAI.embed($0) }\n                )\n                answer = result.value\n            }\n        }\n        Text(answer)\n    }\n}\n```\n\n## API Reference\n\n| Method | Description |\n|---|---|\n| `connect(url:)` | Async factory – connect to cachly instance |\n| `get\u003cT\u003e(_ key)` | Async – get Codable value (`nil` if not found) |\n| `set(_ key, value:, ttl:)` | Async – set Codable value |\n| `del(_ keys...)` | Async – delete keys, returns count |\n| `exists(_ key)` | Async – check existence |\n| `expire(_ key, ttl:)` | Async – update TTL |\n| `incr(_ key)` | Async – atomic increment |\n| `getOrSet(_ key, ttl:, fn:)` | Async – get-or-set pattern |\n| `semantic.getOrSet(...)` | Async – semantic AI cache |\n| `semantic.flush(namespace:)` | Async – flush namespace |\n| `semantic.size(namespace:)` | Async – entry count |\n\n## Batch API — Multiple Ops in One Round-Trip\n\nBundle GET/SET/DEL/EXISTS/TTL operations into **one** HTTP request or RediStack pipeline.\n\n```swift\nlet cache = try await CachlyClient(\n    url: ProcessInfo.processInfo.environment[\"CACHLY_URL\"]!,\n    batchURL: ProcessInfo.processInfo.environment[\"CACHLY_BATCH_URL\"]  // optional\n)\n\nlet results = try await cache.batch([\n    .get(\"user:1\"),\n    .get(\"config:app\"),\n    .set(\"visits\", value: \"42\", ttl: 86400),\n    .exists(\"session:xyz\"),\n    .ttl(\"token:abc\"),\n])\n\nlet user : String? = results[0].value        // nil on miss\nlet ok   : Bool    = results[2].ok\nlet found: Bool    = results[3].exists\nlet secs : Int64   = results[4].ttlSeconds   // -1 = no TTL, -2 = key missing\n```\n\n## Environment Variables\n\n```bash\nCACHLY_URL=redis://:your-password@my-app.cachly.dev:30101\nCACHLY_BATCH_URL=https://api.cachly.dev/v1/cache/YOUR_TOKEN   # optional\n# Speed / Business tier – Semantic AI Cache:\nCACHLY_VECTOR_URL=https://api.cachly.dev/v1/sem/your-vector-token\n```\n\nFind both values in your [cachly.dev dashboard](https://cachly.dev/instances).\n\n## Quality Gates\n\n```bash\nswift build    # Build complete\nswift test     # All tests green (requires Xcode 16+ for @Test macro discovery)\n```\n\n\u003e Note: `@Test` macro discovery requires Xcode.app, not just CommandLineTools. Tests compile and link correctly in both environments.\n\n---\n\n## AI Dev Brain — Persistent Memory for Your Coding Assistant\n\ncachly 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.\n\n```bash\nnpx @cachly-dev/init\n```\n\n`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.\n\n→ Full docs: [cachly.dev/docs/ai-memory](https://cachly.dev/docs/ai-memory)\n\n---\n\n## Links\n\n- 📖 [cachly.dev docs](https://cachly.dev/docs)\n- 🧠 [AI Memory / MCP Server](https://cachly.dev/docs/ai-memory)\n- 🐛 [Issues](https://github.com/cachly-dev/sdk-swift/issues)\n\n---\n\nMIT © [cachly.dev](https://cachly.dev)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcachly-dev%2Fcachly-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcachly-dev%2Fcachly-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcachly-dev%2Fcachly-swift/lists"}