{"id":17946577,"url":"https://github.com/omid/kash","last_synced_at":"2025-03-24T20:32:43.960Z","repository":{"id":257826021,"uuid":"841404032","full_name":"omid/kash","owner":"omid","description":"Function cache and memoization library for Rust","archived":false,"fork":false,"pushed_at":"2024-10-28T14:58:58.000Z","size":768,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T04:14:22.301Z","etag":null,"topics":["cache","caching","function","function-memoization","memoization","memoize","memoizer","rust","rust-caching","rust-lang","rustlang"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/kash","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/omid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2024-08-12T10:41:48.000Z","updated_at":"2025-02-13T06:26:42.000Z","dependencies_parsed_at":"2024-10-28T11:06:57.769Z","dependency_job_id":null,"html_url":"https://github.com/omid/kash","commit_stats":null,"previous_names":["omid/kash"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omid%2Fkash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omid%2Fkash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omid%2Fkash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omid%2Fkash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omid","download_url":"https://codeload.github.com/omid/kash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245348289,"owners_count":20600621,"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":["cache","caching","function","function-memoization","memoization","memoize","memoizer","rust","rust-caching","rust-lang","rustlang"],"created_at":"2024-10-29T07:06:28.140Z","updated_at":"2025-03-24T20:32:43.580Z","avatar_url":"https://github.com/omid.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kash\n\n[![crates.io version](https://img.shields.io/crates/v/kash.svg?style=flat-square)](https://crates.io/crates/kash)\n![build status](https://img.shields.io/github/actions/workflow/status/omid/kash/build.yml?style=flat-square)\n[![downloads](https://img.shields.io/crates/d/kash.svg?style=flat-square)](https://crates.io/crates/kash)\n[![docs.rs docs](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/kash)\n![MIT licensed](https://img.shields.io/crates/l/kash.svg?style=flat-square)\n[![dependency status](https://deps.rs/crate/kash/latest/status.svg?style=flat-square)](https://deps.rs/crate/kash)\n\nCaching structures and simplified function memoization, using [`#[kash]`](kash) macro.\n\n```rust\nuse kash::kash;\n\n/// Defines a function named `fib` that uses a cache implicitly named `FIB`.\n/// By default, the cache will be the function's name in all caps.\n#[kash]\nfn fib(n: u64) -\u003e u64 {\n    if n == 0 || n == 1 { return n }\n    fib(n-1) + fib(n-2)\n}\n```\n\nOr if you want to limit the size and time-to-live:\n\n```rust\nuse kash::kash;\n\nconst TTL: u64 = 1000;\n#[kash(size = \"100\", ttl = \"TTL\")]\nfn fib(n: u64) -\u003e u64 {\n    if n == 0 || n == 1 { return n }\n    fib(n-1) + fib(n-2)\n}\n```\n\n## Features\n\n- `default`: Includes `ahash` feature.\n- `ahash`: Enable `ahash` hasher as default hashing algorithm.\n- `async`: Include support for async functions.\n- `redis_store`: Include Redis cache store.\n- `redis_tokio`: Include async Redis support using `tokio` and `tokio` tls support, implies `redis_store` and `async`.\n- `redis_connection_manager`: Enable the optional `connection-manager` feature of `redis`. Any async redis caches created\n                              will use a connection manager instead of a `MultiplexedConnection`.\n- `redis_ahash`: Enable the optional `ahash` feature of `redis`.\n- `disk_store`: Include disk cache store.\n\n----\n\n```rust\nuse std::thread::sleep;\nuse std::time::Duration;\nuse kash::kash;\n\n/// Use an explicit cache-type with a custom creation block and custom cache-key generating block\n#[kash(\n    size = \"100\",\n    key(ty = \"String\", expr = r#\"{ format!(\"{}{}\", a, b) }\"#)\n)]\nfn keyed(a: \u0026str, b: \u0026str) -\u003e usize {\n    let size = a.len() + b.len();\n    sleep(Duration::new(size as u64, 0));\n    size\n}\n```\n\n----\n\n```rust\nuse kash::{kash, RedisCacheError};\nuse kash::AsyncRedisCache;\nuse thiserror::Error;\n\n#[derive(Error, Debug, PartialEq, Clone)]\nenum ExampleError {\n    #[error(\"error with redis cache `{0}`\")]\n    RedisError(String),\n}\n\nimpl From\u003cRedisCacheError\u003e for ExampleError {\n    fn from(e: RedisCacheError) -\u003e Self {\n        ExampleError::RedisError(format!(\"{:?}\", e))\n    }\n}\n\n/// Cache the results of an async function in redis. Cache\n/// keys will be prefixed with `cache_redis_prefix`.\n#[kash(redis)]\nasync fn async_kash_sleep_secs(secs: u64) -\u003e Result\u003cString, ExampleError\u003e {\n    std::thread::sleep(std::time::Duration::from_secs(secs));\n    Ok(secs.to_string())\n}\n```\n\n----\n\n```rust\nuse kash::{kash, DiskCacheError};\nuse kash::DiskCache;\nuse thiserror::Error;\n\n#[derive(Error, Debug, PartialEq, Clone)]\nenum ExampleError {\n    #[error(\"error with disk cache `{0}`\")]\n    DiskError(String),\n}\n\nimpl From\u003cDiskCacheError\u003e for ExampleError {\n    fn from(e: DiskCacheError) -\u003e Self {\n        ExampleError::DiskError(format!(\"{:?}\", e))\n    }\n}\n\n/// Cache the results of a function on disk.\n/// Cache files will be stored under the system cache dir\n/// unless otherwise specified with `dir` or the `create` argument.\n#[kash(disk)]\nfn kash_sleep_secs(secs: u64) -\u003e Result\u003cString, ExampleError\u003e {\n    std::thread::sleep(std::time::Duration::from_secs(secs));\n    Ok(secs.to_string())\n}\n```\n\nFunctions defined via macros will have their result, cached using the\nfunction's arguments as a key by default.\n\nWhen a macro-defined function is called, the function's cache is first checked for an already\ncomputed (and still valid) value before evaluating the function body.\n\nSee [`examples`](https://github.com/omid/kash/tree/master/examples) directory for more examples.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomid%2Fkash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomid%2Fkash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomid%2Fkash/lists"}