{"id":23757545,"url":"https://github.com/scientanl/locking-cache","last_synced_at":"2025-09-05T04:32:17.134Z","repository":{"id":52907943,"uuid":"345604992","full_name":"ScientaNL/locking-cache","owner":"ScientaNL","description":"Locking Cache","archived":false,"fork":false,"pushed_at":"2023-05-16T07:57:30.000Z","size":71,"stargazers_count":5,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-04T02:48:13.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ScientaNL.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}},"created_at":"2021-03-08T09:45:16.000Z","updated_at":"2025-01-30T11:22:58.000Z","dependencies_parsed_at":"2024-06-21T12:58:05.990Z","dependency_job_id":"255eb379-6801-4957-9909-7c4d8fb83d0e","html_url":"https://github.com/ScientaNL/locking-cache","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ScientaNL/locking-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Flocking-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Flocking-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Flocking-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Flocking-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScientaNL","download_url":"https://codeload.github.com/ScientaNL/locking-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScientaNL%2Flocking-cache/sbom","scorecard":{"id":126730,"data":{"date":"2025-08-11","repo":{"name":"github.com/ScientaNL/locking-cache","commit":"8ded216131c2f0a0a7710290a9866bad117ff8de"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/17 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":4,"reason":"dependency not pinned by hash detected -- score normalized to 4","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr-check.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/ScientaNL/locking-cache/pr-check.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr-check.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ScientaNL/locking-cache/pr-check.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release-npm-version-publish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/ScientaNL/locking-cache/release-npm-version-publish.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release-npm-version-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ScientaNL/locking-cache/release-npm-version-publish.yml/main?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/pr-check.yml:1","Warn: no topLevel permission defined: .github/workflows/release-npm-version-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"16 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T04:06:31.067Z","repository_id":52907943,"created_at":"2025-08-16T04:06:31.067Z","updated_at":"2025-08-16T04:06:31.067Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273713291,"owners_count":25154607,"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","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"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":"2024-12-31T19:48:46.312Z","updated_at":"2025-09-05T04:32:12.119Z","avatar_url":"https://github.com/ScientaNL.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# locking-cache\nCache values and lock while resolving the value to cache.\nLots of caching libraries do not lock the process fetching the value to be cached.\nThat means that multiple resource-intensive processes, that you want 2 cache, can be running\ncomputing a value at the same time.\n\nThis library combines locking with caching and makes sure only one process computing\nthe same cacheable value will run at the same time.\n\n### Not opinionated\nThis library is in essence a wrapper for different cache-storage and locking mechanisms.\nIt does not force you to use a specific backend for storage, or a complex distributed locking library.\nIt does come with some ready-to-use storage and locking implementations.\n\n### Promise-based\nLocking and caching works with promises. In this way it is easy to use with async/await.\n\n## Quickstart\nThere are pre-made storage and locking implementations for single-threaded and multi-threaded caching.\n\n### Single-threaded in-memory locking and caching\n```ts\nimport { LockingCache } from \"@scienta/locking-cache\";\n\n// Expensive (async) function requesting an access token\nconst requestTokenMock = () =\u003e {\n  // Fetch api access token (async), cache for 10 minutes.\n  //\n  // Calling this multiple times in parallel will only run it once.\n  // the cache key is based on the function name and arguments.\n  return Promise.resolve({\n    value: 'fea80f2db003d4ebc4536023814aa885', //access token\n    expiresInSec: 60 * 10 //10 minutes\n  });\n}\nconst cache = new LockingCache\u003cstring\u003e();\ncache.getValue(clientId, requestTokenMock).then(result =\u003e {\n  // Use cached token for requesting resources\n});\n```\n\n### Multi-threaded distributed locking and caching with redis (async/await)\n```ts\nimport {IoRedisStorage, LockingCache, RedisLocker} from \"@scienta/locking-cache\";\nimport * as IORedis from \"ioredis\";\nimport * as Redlock from \"redlock\";\n\nconst ioRedis = new IORedis();\nconst cache = new LockingCache\u003cstring\u003e(\n  new IoRedisStorage(ioRedis, { namespace: 'cache' }), // cache storage in redis\n  new RedisLocker(new Redlock(ioRedis)) // distributed locking in redis\n);\n\nconst result = await cache.getValue(clientId, async () =\u003e {\n  return {\n    value: 'fea80f2db003d4ebc4536023814aa885', //access token\n    expiresInSec: 60 * 10 //10 minutes\n  };\n});\n```\n\n## Flow of execution\n1. returns value if cached\n2. acquires a lock, using the cacheKey\n3. returns cached value if it was computed while waiting for a lock\n4. compute and cache the value\n5. release the lock\n6. return the value\n\n## Errors\nThere are a number of errors that can come up when caching:\n\n```ts\nexport enum CacheErrorEvents {\n  resolveError = 'resolveError',\n  storeGetError = 'storeGetError',\n  storeSetError = 'storeSetError',\n  lockError = 'lockError',\n  unlockError = 'unlockError'\n}\n```\n\nIf an error occurs, most of the time it will result in a rejected promise from `getValue()`:\n\n```ts\nconst cache = new LockingCache\u003cstring\u003e();\ntry {\n  const result = await cache.getValue(clientId, requestTokenMock);\n} catch (error) {\n  // handle resolveError|storeGetError|storeSetError(|lockError)\n}\n```\n\nThe `unlockError` is an exception (it does not get thrown) and the `lockError` can be thrown optionally\nby setting `cacheOnLockError` of the `LockingCache` to `false`;\n\nStill there is a way to listen to errors, because the `LockingCache` also emits them:\n```ts\nconst cache = new LockingCache\u003cstring\u003e();\ncache.on('unlockError', (error) =\u003e {\n  //handle unlockError\n});\ncache.getValue(clientId, requestTokenMock).then(result =\u003e {\n  // Use cached token for requesting resources\n}).catch((error) =\u003e {\n  // handle resolveError|storeGetError|storeSetError(|lockError)\n});\n```\n\n## Contributing\nIf you want to contribute, please do so. A `docker-compose.yml` file is added to make development easy.\n\n### Developing with docker-compose\nTo start development within the defined container, just use docker-compose:\n```bash\ndocker-compose up -d\ndocker exec -ti locking-cache bash\n```\n\n### Testing and linting without docker-compose\nTo quickly run tests and linting from a docker container, you can also use docker directly:\n```bash\ndocker run -it -w=\"/app\" -v ${PWD}:/app node:14-slim /bin/bash -c \"npm install \u0026\u0026 npm run test \u0026\u0026 npm run lint\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientanl%2Flocking-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscientanl%2Flocking-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientanl%2Flocking-cache/lists"}