{"id":19270306,"url":"https://github.com/rambler-digital-solutions/actix-cache","last_synced_at":"2025-04-21T20:33:39.074Z","repository":{"id":53077355,"uuid":"234098882","full_name":"rambler-digital-solutions/actix-cache","owner":"rambler-digital-solutions","description":"Actix cache is a proxy actor and infrastructure for asynchronous and clear cache interaction for Actix actor and Actix-web frameworks.","archived":false,"fork":false,"pushed_at":"2021-05-31T12:25:21.000Z","size":169,"stargazers_count":9,"open_issues_count":5,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T16:07:46.425Z","etag":null,"topics":["actix","actix-cache","cache","hacktoberfest","rust"],"latest_commit_sha":null,"homepage":"","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/rambler-digital-solutions.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}},"created_at":"2020-01-15T14:31:47.000Z","updated_at":"2022-01-21T05:04:20.000Z","dependencies_parsed_at":"2022-09-10T04:23:17.192Z","dependency_job_id":null,"html_url":"https://github.com/rambler-digital-solutions/actix-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rambler-digital-solutions%2Factix-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rambler-digital-solutions%2Factix-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rambler-digital-solutions%2Factix-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rambler-digital-solutions%2Factix-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rambler-digital-solutions","download_url":"https://codeload.github.com/rambler-digital-solutions/actix-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250128488,"owners_count":21379522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","actix-cache","cache","hacktoberfest","rust"],"created_at":"2024-11-09T20:24:12.795Z","updated_at":"2025-04-21T20:33:38.820Z","avatar_url":"https://github.com/rambler-digital-solutions.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# actix-cache\n\n[![Build Status](https://travis-ci.org/rambler-digital-solutions/actix-cache.svg?branch=master)](https://travis-ci.org/rambler-digital-solutions/actix-cache)\n[![Coverage Status](https://coveralls.io/repos/github/rambler-digital-solutions/actix-cache/badge.svg?branch=master)](https://coveralls.io/github/rambler-digital-solutions/actix-cache?branch=master)\n\n**Actix-Cache framework development moved to the [Hitbox](https://github.com/hit-box/hitbox) repository.\nActix-Cache is not supported now.**\n\nActix cache is a proxy actor and infrastructure for asynchronous and clear cache interaction for Actix actor and Actix-web frameworks.\n\n## Features\n* Async/Sync cache backend support.\n* [Dogpile] effect prevention.\n* Stale cache mechanics.\n* Automatic cache key generation.\n* Detailed Prometheus metrics out of the box.\n\n## Backend implementations\n\nAt this time supported or planned next cache backend implementation:\n- [x] Redis backend (actix-cache-redis)\n- [ ] In-memory backend\n\n## Feature flags\n* redis - Enabled by default. Add support for redis backend.\n* derive - Support for [Cacheable] trait derive macros.\n* metrics - Support for Prometheus metrics.\n\n## Example\n\nDependencies:\n\n```toml\n[dependencies]\nactix-cache = \"0.2\"\n```\n\nCode:\n\nFirst of all, you should derive [Cacheable] trait for your actix Message:\n\n\u003e **_NOTE:_** Default cache key implementation based on serde_qs crate\n\u003e and have some [restrictions](https://docs.rs/serde_qs/latest/serde_qs/#supported-types).\n\n\n```rust\nuse actix::prelude::*;\nuse actix_cache::Cacheable; // With features=[\"derive\"]\nuse actix_derive::Message;\nuse serde::{Deserialize, Serialize};\nstruct Pong;\n\n#[derive(Message, Cacheable, Serialize)]\n#[rtype(result = \"Result\u003cPong, ()\u003e\")]\nstruct Ping {\n    id: i32,\n}\n```\nOr implement that trait manually:\n\n```rust\nuse actix_cache::{Cacheable, CacheError};\n\nstruct Ping { id: i32 }\n\nimpl Cacheable for Ping {\n    fn cache_message_key(\u0026self) -\u003e Result\u003cString, CacheError\u003e {\n        Ok(format!(\"{}::{}\", self.cache_key_prefix(), self.id))\n    }\n    fn cache_key_prefix(\u0026self) -\u003e String { \"Ping\".to_owned() }\n}\n```\nNext step is to instantiate [CacheActor] with default backend:\n\n```rust\nuse actix::prelude::*;\nuse actix_cache::{CacheError, Cache};\n\n#[actix_rt::main]\nasync fn main() -\u003e Result\u003c(), CacheError\u003e {\n    let cache = Cache::new()\n        .await?\n        .start();\n   Ok(())\n}\n```\n\nAnd the last step is using cache in your code (actix-web handler for example).\nThis full example and other examples you can see on [github.com](https://github.com/rambler-digital-solutions/actix-cache/blob/master/examples/actix_web.rs)\n\n```rust\nuse actix::prelude::*;\nuse actix_web::{web, App, HttpResponse, HttpServer, Responder};\nuse actix_cache::{Cache, Cacheable};\nuse serde::Serialize;\n\nstruct FibonacciActor;\n\nimpl Actor for FibonacciActor { type Context = Context\u003cSelf\u003e; }\n\n#[derive(Message, Cacheable, Serialize)]\n#[rtype(result = \"u64\")]\nstruct GetNumber {\n    number: u8\n}\n\nimpl Handler\u003cGetNumber\u003e for FibonacciActor {\n    type Result = \u003cGetNumber as Message\u003e::Result;\n\n    fn handle(\u0026mut self, msg: GetNumber, _ctx: \u0026mut Self::Context) -\u003e Self::Result {\n        42\n    }\n}\n\nasync fn index(\n    fib: web::Data\u003cAddr\u003cFibonacciActor\u003e\u003e,\n    cache: web::Data\u003cAddr\u003cCache\u003e\u003e\n) -\u003e impl Responder {\n    let query = GetNumber { number: 40 };\n    let number = cache\n        .send(query.into_cache(\u0026fib))\n        .await\n        .unwrap()\n        .unwrap();\n    HttpResponse::Ok().body(format!(\"Generate Fibonacci number {}\", number))\n}\n```\n\n\n[Dogpile]: https://www.sobstel.org/blog/preventing-dogpile-effect/\n[Cacheable]: https://docs.rs/actix-cache/latest/actix-cache/cache/trait.Cacheable.html\n[CacheActor]: https://docs.rs/actix-cache/latest/actix-cache/actor/struct.CacheActor.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frambler-digital-solutions%2Factix-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frambler-digital-solutions%2Factix-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frambler-digital-solutions%2Factix-cache/lists"}