{"id":36236894,"url":"https://github.com/megamsys/cache-kit.rs","last_synced_at":"2026-01-11T06:02:03.440Z","repository":{"id":330455532,"uuid":"1121644068","full_name":"megamsys/cache-kit.rs","owner":"megamsys","description":"cache-kit is a production-ready, fully generic cache framework for Rust that decouples caching from specific frameworks, backends, and databases. https://cachekit.org","archived":false,"fork":false,"pushed_at":"2026-01-06T18:22:10.000Z","size":1262,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-06T22:27:15.883Z","etag":null,"topics":["actix-web","axum-server","cache","grpc","rest-api","rust"],"latest_commit_sha":null,"homepage":"https://cachekit.org/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/megamsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-12-23T10:12:49.000Z","updated_at":"2026-01-02T10:35:20.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/megamsys/cache-kit.rs","commit_stats":null,"previous_names":["megamsys/cache-kit.rs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/megamsys/cache-kit.rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megamsys%2Fcache-kit.rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megamsys%2Fcache-kit.rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megamsys%2Fcache-kit.rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megamsys%2Fcache-kit.rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/megamsys","download_url":"https://codeload.github.com/megamsys/cache-kit.rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megamsys%2Fcache-kit.rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28293188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T04:44:51.577Z","status":"ssl_error","status_checked_at":"2026-01-11T04:44:44.232Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["actix-web","axum-server","cache","grpc","rest-api","rust"],"created_at":"2026-01-11T06:02:02.724Z","updated_at":"2026-01-11T06:02:03.434Z","avatar_url":"https://github.com/megamsys.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cache-kit\n\n**A type-safe, generic caching framework for Rust.**\n\n[![Crates.io](https://img.shields.io/crates/v/cache-kit?style=flat-square)](https://crates.io/crates/cache-kit)\n[![Docs.rs](https://img.shields.io/docsrs/cache-kit?style=flat-square)](https://docs.rs/cache-kit)\n[![Documentation](https://img.shields.io/badge/guide-cachekit.org-blue?style=flat-square)](http://cachekit.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)\n[![Rust Version](https://img.shields.io/badge/rust-1.75%2B-blue?style=flat-square\u0026logo=rust)](https://www.rust-lang.org)\n[![CI](https://github.com/megamsys/cache-kit.rs/actions/workflows/ci.yml/badge.svg)](https://github.com/megamsys/cache-kit.rs/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/megamsys/cache-kit.rs/branch/main/graph/badge.svg)](https://codecov.io/gh/megamsys/cache-kit.rs)\n\nA trait-based caching framework that works with any Rust type, any backend (InMemory, Redis, Memcached), and any database (SQLx, Diesel, tokio-postgres).\n\n---\n\n## Features\n\n- **Generic** — Cache any type `T` that implements `CacheEntity`\n- **Backend Agnostic** — Switch between InMemory, Redis, Memcached without code changes\n- **Database Agnostic** — Works with any repository implementing `DataRepository`\n- **Type Safe** — Compile-time verified\n- **Thread Safe** — `Send + Sync` guarantees\n\n---\n\n## ⚠️ Requirements\n\n- Requires `tokio` runtime (async-only)\n- Use Redis/Memcached for production (InMemory is single-instance only)\n- Decimal types (`rust_decimal::Decimal`) require custom serialization\n\nFor production guidance, see the [documentation](http://cachekit.org/).\n\n## Quick Start\n\n### Add to Cargo.toml\n\n```toml\n[dependencies]\ncache-kit = { version = \"0.9\", features = [\"inmemory\"] }\nserde = { version = \"1.0\", features = [\"derive\"] }\ntokio = { version = \"1\", features = [\"full\"] }\n```\n\n### Basic Usage\n\n```rust\nuse cache_kit::{\n    CacheEntity, CacheFeed, DataRepository, CacheExpander,\n    backend::InMemoryBackend,\n    strategy::CacheStrategy,\n};\nuse serde::{Deserialize, Serialize};\n\n// 1. Define your entity\n#[derive(Clone, Serialize, Deserialize)]\nstruct User {\n    id: String,\n    name: String,\n}\n\n// 2. Implement CacheEntity\nimpl CacheEntity for User {\n    type Key = String;\n    fn cache_key(\u0026self) -\u003e Self::Key { self.id.clone() }\n    fn cache_prefix() -\u003e \u0026'static str { \"user\" }\n}\n\n// 3. Create a feeder\nstruct UserFeeder {\n    id: String,\n    user: Option\u003cUser\u003e,\n}\n\nimpl CacheFeed\u003cUser\u003e for UserFeeder {\n    fn entity_id(\u0026mut self) -\u003e String { self.id.clone() }\n    fn feed(\u0026mut self, entity: Option\u003cUser\u003e) { self.user = entity; }\n}\n\n// 4. Create a repository\nstruct UserRepository;\n\nimpl DataRepository\u003cUser\u003e for UserRepository {\n    async fn fetch_by_id(\u0026self, id: \u0026String) -\u003e cache_kit::Result\u003cOption\u003cUser\u003e\u003e {\n        // Fetch from your database\n        Ok(Some(User { id: id.clone(), name: \"Alice\".to_string() }))\n    }\n}\n\n// 5. Use the cache\n#[tokio::main]\nasync fn main() -\u003e cache_kit::Result\u003c()\u003e {\n    let backend = InMemoryBackend::new();\n    let expander = CacheExpander::new(backend);\n\n    let mut feeder = UserFeeder { id: \"user_001\".to_string(), user: None };\n    let repository = UserRepository;\n\n    expander.with(\u0026mut feeder, \u0026repository, CacheStrategy::Refresh).await?;\n\n    if let Some(user) = feeder.user {\n        println!(\"User: {}\", user.name);\n    }\n\n    Ok(())\n}\n```\n\n## Cache Strategies\n\n| Strategy              | Behavior                   | Use Case                     |\n| --------------------- | -------------------------- | ---------------------------- |\n| **Refresh** (default) | Try cache, fallback to DB  | Most common case             |\n| **Fresh**             | Cache only, no DB fallback | When data must be cached     |\n| **Invalidate**        | Clear cache, fetch from DB | After mutations              |\n| **Bypass**            | Skip cache, always use DB  | Testing or temporary disable |\n\n## Advanced Usage\n\nFor complex operations like custom TTL overrides, retry logic, and builder patterns, see the [documentation](http://cachekit.org/) for advanced features including metrics, TTL policies, and `CacheService` for service-oriented architectures.\n\n## Backends\n\n### In-Memory (Default)\n\n```rust\nuse cache_kit::backend::InMemoryBackend;\nlet backend = InMemoryBackend::new();\nlet expander = CacheExpander::new(backend);\n```\n\n### Redis\n\n```toml\n[dependencies]\ncache-kit = { version = \"0.9\", features = [\"redis\"] }\n```\n\n```rust\nuse cache_kit::backend::{RedisBackend, RedisConfig};\nlet backend = RedisBackend::new(RedisConfig::default())?;\nlet expander = CacheExpander::new(backend);\n```\n\n### Memcached\n\n```toml\n[dependencies]\ncache-kit = { version = \"0.9\", features = [\"memcached\"] }\n```\n\n```rust\nuse cache_kit::backend::{MemcachedBackend, MemcachedConfig};\nlet backend = MemcachedBackend::new(MemcachedConfig::default())?;\nlet expander = CacheExpander::new(backend);\n```\n\n## Observability\n\nThe framework supports logging (via `log` crate) and custom metrics:\n\n```rust\nuse cache_kit::observability::{CacheMetrics, TtlPolicy};\nuse std::time::Duration;\n\n// Custom metrics\nlet expander = CacheExpander::new(backend)\n    .with_metrics(Box::new(MyMetrics));\n\n// TTL policies\nlet expander = CacheExpander::new(backend)\n    .with_ttl_policy(TtlPolicy::Fixed(Duration::from_secs(300)));\n```\n\nSee the [documentation](http://cachekit.org/) for details on metrics and TTL policies.\n\n## Examples\n\n```bash\n# Basic usage\ncargo run --example basic_usage\n\n# Multiple backends\ncargo run --example multiple_backends --features redis,memcached\n\n# Advanced builder\ncargo run --example advanced_builder\n```\n\n## Testing\n\n```bash\nmake up\nmake test FEATURES=\"--all-features\"\n```\n\nFor more examples and guides, see the [documentation](http://cachekit.org/).\n\n## Publishing\n\n```bash\nmake up\nmake release\n```\n\nThis runs build, test, audit, and publish. For linting, use `make dev`.\n\n## Contributing\n\nContributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## License\n\nMIT License - Copyright (c) 2025 Kishore kumar Neelamegam\n\nSee [LICENSE](LICENSE) file for details.\n\n## Support\n\n**Maintainer:** Kishore kumar Neelamegam\n**Repository:** [github.com/megamsys/cache-kit.rs](https://github.com/megamsys/cache-kit.rs)\n**Issues:** [GitHub Issues](https://github.com/megamsys/cache-kit.rs/issues)\n**Crates.io:** [crates.io/crates/cache-kit](https://crates.io/crates/cache-kit)\n**Documentation:** [cachekit.org](https://cachekit.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegamsys%2Fcache-kit.rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmegamsys%2Fcache-kit.rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegamsys%2Fcache-kit.rs/lists"}