{"id":26319333,"url":"https://github.com/francescorivola/rabbit-lru-cache","last_synced_at":"2025-08-08T05:33:35.868Z","repository":{"id":36972565,"uuid":"254638267","full_name":"francescorivola/rabbit-lru-cache","owner":"francescorivola","description":"A lib to invalidate lru cache keys in distributed systems powered by rabbitmq.","archived":false,"fork":false,"pushed_at":"2025-05-21T05:59:29.000Z","size":1871,"stargazers_count":6,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T16:05:46.661Z","etag":null,"topics":["distributed","invalidation","lru-cache","rabbitmq"],"latest_commit_sha":null,"homepage":"","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/francescorivola.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}},"created_at":"2020-04-10T13:13:33.000Z","updated_at":"2025-02-21T05:04:19.000Z","dependencies_parsed_at":"2023-02-19T04:30:30.453Z","dependency_job_id":"45d3f2bf-977a-47fe-8021-6387b43abe58","html_url":"https://github.com/francescorivola/rabbit-lru-cache","commit_stats":{"total_commits":763,"total_committers":6,"mean_commits":"127.16666666666667","dds":0.5085190039318479,"last_synced_commit":"e177d896500bc2645a191a70444831691d4ed1fe"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/francescorivola/rabbit-lru-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescorivola%2Frabbit-lru-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescorivola%2Frabbit-lru-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescorivola%2Frabbit-lru-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescorivola%2Frabbit-lru-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/francescorivola","download_url":"https://codeload.github.com/francescorivola/rabbit-lru-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescorivola%2Frabbit-lru-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269371213,"owners_count":24406265,"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-08-08T02:00:09.200Z","response_time":72,"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":["distributed","invalidation","lru-cache","rabbitmq"],"created_at":"2025-03-15T15:18:30.877Z","updated_at":"2025-08-08T05:33:35.552Z","avatar_url":"https://github.com/francescorivola.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rabbit-lru-cache\n\nA lib to invalidate lru cache keys in distributed systems powered by rabbitmq.\n\n[ ![Npm Version](https://badge.fury.io/js/rabbit-lru-cache.svg)](https://www.npmjs.com/package/rabbit-lru-cache)\n[![Actions Status](https://github.com/francescorivola/rabbit-lru-cache/workflows/Node%20CI/badge.svg)](https://github.com/francescorivola/rabbit-lru-cache/actions)\n[![CodeFactor](https://www.codefactor.io/repository/github/francescorivola/rabbit-lru-cache/badge)](https://www.codefactor.io/repository/github/francescorivola/rabbit-lru-cache)\n[![codecov](https://codecov.io/gh/francescorivola/rabbit-lru-cache/branch/master/graph/badge.svg)](https://codecov.io/gh/francescorivola/rabbit-lru-cache)\n[![Dependabot](https://badgen.net/badge/Dependabot/enabled/green?icon=dependabot)](https://dependabot.com/)\n\n## Installation\n\n`npm install --save rabbit-lru-cache`\n\n## Getting Started\n\nThis library is powered by lru-cache and amqplib (both dependencies).\n\n```js\nconst createRabbitLRUCache = require(\"rabbit-lru-cache\").default;\n\nconst cache = await createRabbitLRUCache({\n    name: \"example\",\n    LRUCacheOptions: {\n        ttl: 120000,\n        max: 10000\n    },\n    amqpConnectOptions: {\n        hostname: \"localhost\",\n        username: \"guest\",\n        password: \"guest\"\n    }\n});\ncache.addInvalidationMessageReceivedListener((content, publisherCacheId) =\u003e {\n    console.log(\n        \"Cache Message\",\n        \"publisherCacheId\",\n        publisherCacheId,\n        \"content\",\n        content\n    );\n});\ncache.addReconnectingListener((error, attempt, retryInterval) =\u003e {\n    console.log(\n        \"Reconnecting\",\n        error.message,\n        \"attempt\",\n        attempt,\n        \"retryInterval\",\n        retryInterval\n    );\n});\ncache.addReconnectedListener((error, attempt, retryInterval) =\u003e {\n    console.log(\n        \"Reconnected\",\n        error.message,\n        \"attempt\",\n        attempt,\n        \"retryInterval\",\n        retryInterval\n    );\n});\n\nawait cache.getOrLoad(\"key\", () =\u003e Promise.resolve(5));\ncache.delete(\"key\");\n\nawait cache.close(); // gracefully shutdown RabbitMq connection\n```\n\nEvery time the lru-cache **delete** or **clear** function is called a message is published in a fan out exchange and each cache subscribers consume the message to invalidate the corresponding key or the entire cache.\n\nThe **getOrLoad** function forces you to set item in cache only after loading it, avoiding a wrong usage of the library as, for instance, set in cache an item after modifying it. Finally, this function comes with concurrency mechanism to avoid stale data and [Thundering herd problem](https://en.wikipedia.org/wiki/Thundering_herd_problem) by use the same promise for concurrent requests of the same cache key while the corresponding item is not loaded in cache yet.\n\nThe lib handles RabbitMq connection errors and it reconnects automatically if the connection with the broker got lost. During reconnection the local cache get resetted and cache is disabled to ensure it does not store stale data.\n\n## Examples\n\nExamples of the usage of this lib can be found in test folder or [examples](./examples) folder.\n\n## Test\n\nRun test suite with the following command:\n\n```sh\nnpm test\n```\n\nTest suite requires a RabbitMq server listening at port 5672.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescorivola%2Frabbit-lru-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrancescorivola%2Frabbit-lru-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescorivola%2Frabbit-lru-cache/lists"}