{"id":17366201,"url":"https://github.com/letmutx/macgyver-lock-rs","last_synced_at":"2025-07-18T16:06:04.145Z","repository":{"id":57633737,"uuid":"227623667","full_name":"letmutx/macgyver-lock-rs","owner":"letmutx","description":"Implementation of ghetto lock","archived":false,"fork":false,"pushed_at":"2020-01-03T17:59:54.000Z","size":31,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T03:23:57.204Z","etag":null,"topics":["ghetto-lock","lock","memcached-lock","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/letmutx.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":"2019-12-12T14:18:44.000Z","updated_at":"2024-02-08T15:14:58.000Z","dependencies_parsed_at":"2022-09-26T20:11:55.212Z","dependency_job_id":null,"html_url":"https://github.com/letmutx/macgyver-lock-rs","commit_stats":null,"previous_names":["letmutx/ghetto-lock-rs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/letmutx/macgyver-lock-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letmutx%2Fmacgyver-lock-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letmutx%2Fmacgyver-lock-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letmutx%2Fmacgyver-lock-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letmutx%2Fmacgyver-lock-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letmutx","download_url":"https://codeload.github.com/letmutx/macgyver-lock-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letmutx%2Fmacgyver-lock-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264919726,"owners_count":23683654,"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":["ghetto-lock","lock","memcached-lock","rust"],"created_at":"2024-10-15T21:33:34.751Z","updated_at":"2025-07-18T16:06:04.124Z","avatar_url":"https://github.com/letmutx.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# macgyver-lock\n\n[![Build Status](https://api.travis-ci.org/letmutx/macgyver-lock-rs.svg?branch=master)](https://travis-ci.org/letmutx/macgyver-lock-rs.svg?branch=master)\n\nThis library implements the ghetto lock described [here](https://github.com/memcached/memcached/wiki/ProgrammingTricks#ghetto-central-locking). The lock isn't resistant to server failures and should be used only in situations where strong locking guarantees are not required.\n\n A popular use case for this lock is to avoid the [stampeding herd problem](https://en.wikipedia.org/wiki/Thundering_herd_problem) caused by a cache miss.\n \n ## Usage:\n Add to your `Cargo.toml`:\n ```\nmacgyver-lock = \"0.2.0\"\n```\n\n ## Example:\n\n ```rust\n use macgyver_lock::{LockOptions, LockError};\n use memcache::Client;\n use std::borrow::Cow;\n\n fn expensive_computation() -\u003e u64 {\n     2 * 2\n }\n\n fn main() {\n     let mut client = Client::connect(\"memcache://localhost:11211\").expect(\"error creating client\");\n     let mut lock = LockOptions::new(Cow::Borrowed(\"db-lock\"), Cow::Borrowed(\"owner-1\"))\n                     .with_expiry(1)\n                     .build()\n                     .expect(\"failed to build client\");\n     let value = client.get(\"key\").expect(\"failed to get key\");\n     let v = if value.is_none() {\n         lock.try_acquire()\n             .and_then(|_guard| {\n                 // compute and update cache for other instances to consume\n                 let v = expensive_computation();\n                 client.set(\"key\", v, 5).expect(\"failed to set key\");\n                 Ok(v)\n             })\n             .or_else(|_| loop {\n                 // poll cache key until it is updated.\n                 let v = client.get(\"key\").expect(\"failed to get key\");\n                 if v.is_none() {\n                     continue;\n                 }\n                 break Ok::\u003c_, LockError\u003e(v.unwrap());\n             }).unwrap()\n     } else { value.unwrap() };\n     assert_eq!(4, v);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmutx%2Fmacgyver-lock-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletmutx%2Fmacgyver-lock-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmutx%2Fmacgyver-lock-rs/lists"}