{"id":18067634,"url":"https://github.com/alanclarke/cashcow","last_synced_at":"2025-04-05T15:22:36.254Z","repository":{"id":57194711,"uuid":"62824382","full_name":"alanclarke/cashcow","owner":"alanclarke","description":"cashcow is a smart cache fetcher that pools consumers and minimises memory usage","archived":false,"fork":false,"pushed_at":"2016-11-21T23:29:49.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-10T09:16:11.609Z","etag":null,"topics":["ceh","cmh","implement"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alanclarke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-07T17:07:49.000Z","updated_at":"2024-06-08T14:52:05.000Z","dependencies_parsed_at":"2022-09-16T05:14:09.242Z","dependency_job_id":null,"html_url":"https://github.com/alanclarke/cashcow","commit_stats":null,"previous_names":["qubitproducts/cashcow"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanclarke%2Fcashcow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanclarke%2Fcashcow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanclarke%2Fcashcow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanclarke%2Fcashcow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alanclarke","download_url":"https://codeload.github.com/alanclarke/cashcow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339154,"owners_count":20923014,"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":["ceh","cmh","implement"],"created_at":"2024-10-31T07:09:57.359Z","updated_at":"2025-04-05T15:22:36.229Z","avatar_url":"https://github.com/alanclarke.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![cashcow](https://cloud.githubusercontent.com/assets/640611/16708914/d14dee66-45f9-11e6-9334-a153eeb9144f.png)\n\nA smart cached value fetcher that...\n\n- pools consumers while fetching to avoid doing multiple trips\n- guarantees only one instance of resource is ever held in memory\n- satisfies consumers early if already fetching\n\ncashcow is not prescriptive about what cache your using, simply provide it with two functions:\n\n- get(key) a function that gets value from cache and returns a promise for that value\n- populate(key) optionally provide function that populates the cache and returns a promise for the value when complete\n\n## installation\n```\nnpm install cashcow\n```\n\n## usage\n```js\n\n// scenario 1: lazy population of individual cache keys\n\nvar cashcow = require('cashcow')\nvar cowFetch = cashcow(get, populate)\n\nfunction get (key) {\n  return myCache.get(key)\n}\n\nfunction populate (key) {\n  return fetchFromSource(key).then(function (val) {\n    return myCache.set(key, val)\n  })\n}\n\n// usage\ncowFetch(key) // populates cache then returns val from cache\ncowFetch(key) // combined with previous fetch\ncowFetch(key).then(function (val) {\n  // cache has been populated\n  cowFetch(key) // gets from cache\n  cowFetch(key) // combined with previous fetch\n  cowFetch(key).then(function (val) {\n    cowFetch(key) // requests again from cache\n  })\n})\n\n\n// scenario 2: lazy population of entire cache\n\nvar cashcow = require('cashcow')\nvar cowFetch = cashcow(populate)\n\nfunction get (key) {\n  return myCache.get(key).then(function (val) {\n    if (!val) return cowFetch().then(() =\u003e get(key))\n  })\n}\n\nfunction populate () {\n  return fetchAllFromSource().then(myCache.hydrateAll)\n}\n\n// usage\nget(key) // fetches from cache, calls populates to populate entire cache\nget(key) // call to populate combined with previous one\nget(key).then(function (val) {\n  // cache has been populated\n  get(key) // val fetched straight from cache\n})\n```\n\n## run tests\n```\nnpm test\n```\n\n## Want to work on this for your day job?\n\nThis project was created by the Engineering team at Qubit. As we use open source libraries, we make our projects public where possible.\n\nWe’re currently looking to grow our team, so if you’re a JavaScript engineer and keen on ES2016 React+Redux applications and Node micro services, why not get in touch? Work with like minded engineers in an environment that has fantastic perks, including an annual ski trip, yoga, a competitive foosball league, and copious amounts of yogurt.\n\nFind more details on our Engineering site. Don’t have an up to date CV? Just link us your Github profile! Better yet, send us a pull request that improves this project.`\nContact GitHub API Training Shop Blog About\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanclarke%2Fcashcow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falanclarke%2Fcashcow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanclarke%2Fcashcow/lists"}