{"id":15497390,"url":"https://github.com/heapwolf/through-cache","last_synced_at":"2025-04-22T22:29:30.943Z","repository":{"id":12069638,"uuid":"14656712","full_name":"heapwolf/through-cache","owner":"heapwolf","description":"a through stream that caches","archived":false,"fork":false,"pushed_at":"2013-11-24T18:52:07.000Z","size":140,"stargazers_count":20,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T19:34:27.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/heapwolf.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":"2013-11-24T06:13:32.000Z","updated_at":"2019-07-15T21:09:13.000Z","dependencies_parsed_at":"2022-09-03T14:31:22.797Z","dependency_job_id":null,"html_url":"https://github.com/heapwolf/through-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fthrough-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fthrough-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fthrough-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heapwolf%2Fthrough-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heapwolf","download_url":"https://codeload.github.com/heapwolf/through-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250333718,"owners_count":21413445,"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-02T08:33:19.650Z","updated_at":"2025-04-22T22:29:30.927Z","avatar_url":"https://github.com/heapwolf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# SYNOPSIS\nA through stream that caches\n\n# MOTIVATION\nThere are some cases where the same data is piped over and over again.\nIn these cases there is no reason to repeat the transformation of the\ndata when the result can be retrieved from a cache.\n\n# USAGE\nCreate a cache and pipe to its `cache` method.\n\n```js\n//\n// create a new cache\n//\nvar tc = require('through-cache')()\n\na.pipe(tc.cache(function(obj) {\n\t\n\t//\n\t// this only gets called once because\n\t// the exact same data is written again.\n\t//\n\t// but two writes are made to the `b` stream,\n\t// one from the `a` stream and one from the \n\t// cache.\n\t//\n\n\tvar str = '\u003cdiv\u003e' + obj.value + '\u003c/div\u003e'\n\tthis.push(str)\n\n}).pipe(b)\n\nstream.write({ value: 'hello, world' })\nstream.write({ value: 'hello, world' })\n```\n\nTo cache a function that will get applied to the data.\n\n```js\na.pipe(tc.cache(function(obj) {\n\n\t// the transform function will get cached and then \n\t// applied to the data every time data gets pushed \n\t// to the stream.\n\n\tthis.transform(function(data) {\n\t\treturn '\u003cdiv\u003e' + data + '\u003c/div\u003e'\n\t})\n\n\tthis.push(obj.value)\n\n}).pipe(b)\n```\n\nAnd to invalidate the cache.\n\n```\ntc.invalidate()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheapwolf%2Fthrough-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheapwolf%2Fthrough-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheapwolf%2Fthrough-cache/lists"}