{"id":15364699,"url":"https://github.com/bencode/yield-cache","last_synced_at":"2025-03-27T22:33:49.501Z","repository":{"id":33833490,"uuid":"37533374","full_name":"bencode/yield-cache","owner":"bencode","description":"Cache utility for generator","archived":false,"fork":false,"pushed_at":"2016-04-09T05:47:08.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-19T16:18:15.192Z","etag":null,"topics":[],"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/bencode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-06-16T13:56:37.000Z","updated_at":"2016-02-03T10:18:07.000Z","dependencies_parsed_at":"2022-08-17T20:35:10.117Z","dependency_job_id":null,"html_url":"https://github.com/bencode/yield-cache","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fyield-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fyield-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fyield-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencode%2Fyield-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bencode","download_url":"https://codeload.github.com/bencode/yield-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222322398,"owners_count":16966440,"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":[],"created_at":"2024-10-01T13:13:05.470Z","updated_at":"2024-10-30T23:15:56.624Z","avatar_url":"https://github.com/bencode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yield-cache\n\n[![Build Status](https://travis-ci.org/bencode/yield-cache.svg?branch=master)](https://travis-ci.org/bencode/yield-cache)\n[![Coverage Status](https://coveralls.io/repos/bencode/yield-cache/badge.svg)](https://coveralls.io/r/bencode/yield-cache)\n\n\nCache utility for generator\n\n\nplover \\ node | 5.x | 4.x | 0.12.x\n---           | --- | --- | ----\n0.x.x         | √   | √   | √\n1.x.x         | √   | √   | X\n\n\n```shell\n$ npm install yield-cache\n```\n\n\n## API\n\n### yieldCache()\n\ncreate cache instance\n\n```\nconst cache = yieldCache();\n```\n\n### cache(key, obj)\n\ntry get item from cache or yeild from obj\n\n### cache.remove(key)\n\nremove cache item for key\n\n\n## Useage\n\n1\\. Create an instance for cache a group of generator\n\n```js\nconst cache = yieldCache();\n```\n\n2\\. Use cache instance\n\n\n```js\n// it should used in generator function\nfunction* () {\n  // call with cackeKey and yieldable object\n  const item = yield* cache(cacheKey, Generator or GeneratorFunction or Functin that return Promise);\n}\n```\n\n\n## Example\n\n```js\nconst yieldCache = require('yield-cache');\n\n\n// create an instance\nconst renderCache = yieldCache();\n\n\n// use\nfunction* getRender(path) {\n  const render = yield* renderCache(path, function* () {\n    const tpl = yield fs.readFile(path, 'utf-8');\n    return compiler.complie(tpl);\n  });\n\n  return render;\n}\n\n\nconst path = ...\nconst render = yield* getRender(path);\nconst render2 = yield* getRender(path);\n\nrender.should.equal(render2);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencode%2Fyield-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbencode%2Fyield-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencode%2Fyield-cache/lists"}