{"id":26255186,"url":"https://github.com/reaxi/cache-eight","last_synced_at":"2025-12-30T00:06:22.120Z","repository":{"id":57192429,"uuid":"464932374","full_name":"reaxi/cache-eight","owner":"reaxi","description":" file caching with v8 serialization strategy","archived":false,"fork":false,"pushed_at":"2022-10-01T05:57:31.000Z","size":8,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-08T19:05:20.551Z","etag":null,"topics":["cache","file","hacktoberfest","json","node-js","nodejs","v8"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/reaxi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-01T14:44:02.000Z","updated_at":"2025-03-01T19:24:00.000Z","dependencies_parsed_at":"2022-08-24T03:10:29.548Z","dependency_job_id":null,"html_url":"https://github.com/reaxi/cache-eight","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/reaxi%2Fcache-eight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reaxi%2Fcache-eight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reaxi%2Fcache-eight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reaxi%2Fcache-eight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reaxi","download_url":"https://codeload.github.com/reaxi/cache-eight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243467020,"owners_count":20295309,"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":["cache","file","hacktoberfest","json","node-js","nodejs","v8"],"created_at":"2025-03-13T19:17:45.960Z","updated_at":"2025-12-30T00:06:22.080Z","avatar_url":"https://github.com/reaxi.png","language":"JavaScript","readme":"# cache-eight\n\n\u003e **cache** + v**8**\n\n-   checksum keys\n\n-   access data from json files (persistent cache)\n\n-   optimize functions execution time for expensive operations\n\n-   data is saved using v8's serialize / deserialize\n\n## why?\n\ncaching expensive pure functions results\n\nsame inputs -\u003e same results\n\n### use case\n\nfrom 3s to 1s\n\n\u003e @todo\n\n## Usage\n\n```ts\nimport Cache from 'cache-eight';\n\nconst cache = new Cache();\n```\n\n```\nfolder                           file\n\u003e OS_temp_dir/.cache8/appName -\u003e cache.json\n```\n\n#### high level api\n\n```ts\nconst values = [1, 2, 3];\nconst key = values.toString();\n\nconst cached = await cache.get(key, () =\u003e values.map(value =\u003e value * 2));\n// will return the cached if valid or the actual value (and serialize for the future)\n```\n\ncustom options:\n\n```ts\nconst customPath = path.resolve(process.cwd());\n\n//custom folder:\nconst customCache = new Cache(customPath);\n\n//custom file:\ncustomCache.get(k, () =\u003e v, { filePath: 'my-file.json' });\n\n// cache duration (time to live):\ncustomCache.get(k, () =\u003e v, { ttl: 1000 * 60 }); // number in ms;\n```\n\n#### granular control api\n\n```ts\nconst values = [1, 2, 3];\nconst key = values.toString();\n\nasync function get() {\n    const cached = await cache.deserialize(key);\n\n    // if has cached value, return early (skipping further functions)\n    if (cached) return cached;\n\n    //else get it from somewhere\n    const result = values.map(value =\u003e value * 2);\n\n    //cache the result\n    await cache.serialize(key, result);\n\n    return result;\n}\n\nawait get();\n```\n\n## API\n\n```ts\nget(key, () =\u003e val, options?) =\u003e val\nserialize(key, val, options?) =\u003e val\ndeserialize(key, options?) =\u003e cachedVal | false\n\n// key and val are any valid Json objects\n\n\noptions = {\n    filPath: string + .json //file.json\n    ttl: number //ms\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freaxi%2Fcache-eight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freaxi%2Fcache-eight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freaxi%2Fcache-eight/lists"}