{"id":13527270,"url":"https://github.com/jaredwray/flat-cache","last_synced_at":"2025-07-30T18:06:12.934Z","repository":{"id":27868369,"uuid":"31359273","full_name":"jaredwray/flat-cache","owner":"jaredwray","description":"A stupidly simple key/value storage using files to persist the data","archived":false,"fork":false,"pushed_at":"2024-06-25T18:12:17.000Z","size":389,"stargazers_count":165,"open_issues_count":0,"forks_count":30,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T13:10:40.736Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredwray.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}},"created_at":"2015-02-26T09:12:16.000Z","updated_at":"2024-09-20T21:01:58.000Z","dependencies_parsed_at":"2022-08-02T21:01:18.733Z","dependency_job_id":"6b2681a7-2fcb-4876-82ad-a974f2a04265","html_url":"https://github.com/jaredwray/flat-cache","commit_stats":{"total_commits":163,"total_committers":22,"mean_commits":7.409090909090909,"dds":0.6748466257668712,"last_synced_commit":"e174443c80c7d12170dd960d8224a9b7c32bde45"},"previous_names":["royriojas/flat-cache"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fflat-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fflat-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fflat-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fflat-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredwray","download_url":"https://codeload.github.com/jaredwray/flat-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229222422,"owners_count":18039284,"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-08-01T06:01:44.508Z","updated_at":"2024-12-11T12:06:39.308Z","avatar_url":"https://github.com/jaredwray.png","language":"JavaScript","readme":"# flat-cache\n\n\u003e A stupidly simple key/value storage using files to persist the data\n\n[![NPM Version](https://img.shields.io/npm/v/flat-cache.svg?style=flat)](https://npmjs.org/package/flat-cache)\n[![tests](https://github.com/jaredwray/flat-cache/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/jaredwray/flat-cache/actions/workflows/tests.yaml)\n[![codecov](https://codecov.io/github/jaredwray/flat-cache/branch/master/graph/badge.svg?token=KxR95XT3NF)](https://codecov.io/github/jaredwray/flat-cache)\n[![npm](https://img.shields.io/npm/dm/flat-cache)](https://npmjs.com/package/flat-cache)\n\n## install\n\n```bash\nnpm i --save flat-cache\n```\n\n## Usage\n\n```js\nconst flatCache = require('flat-cache');\n// loads the cache, if one does not exists for the given\n// Id a new one will be prepared to be created\nconst cache = flatCache.load('cacheId');\n\n// sets a key on the cache\ncache.setKey('key', { foo: 'var' });\n\n// get a key from the cache\ncache.getKey('key'); // { foo: 'var' }\n\n// fetch the entire persisted object\ncache.all(); // { 'key': { foo: 'var' } }\n\n// remove a key\ncache.removeKey('key'); // removes a key from the cache\n\n// save it to disk\ncache.save(); // very important, if you don't save no changes will be persisted.\n// cache.save( true /* noPrune */) // can be used to prevent the removal of non visited keys\n\n// loads the cache from a given directory, if one does\n// not exists for the given Id a new one will be prepared to be created\nconst cache = flatCache.load('cacheId', path.resolve('./path/to/folder'));\n\n// The following methods are useful to clear the cache\n// delete a given cache\nflatCache.clearCacheById('cacheId'); // removes the cacheId document if one exists.\n\n// delete all cache\nflatCache.clearAll(); // remove the cache directory\n```\n\n## Motivation for this module\n\nI needed a super simple and dumb **in-memory cache** with optional disk persistance in order to make\na script that will beutify files with `esformatter` only execute on the files that were changed since the last run.\nTo make that possible we need to store the `fileSize` and `modificationTime` of the files. So a simple `key/value`\nstorage was needed and Bam! this module was born.\n\n## Important notes\n\n- If no directory is especified when the `load` method is called, a folder named `.cache` will be created\n  inside the module directory when `cache.save` is called. If you're committing your `node_modules` to any vcs, you\n  might want to ignore the default `.cache` folder, or specify a custom directory.\n- The values set on the keys of the cache should be `stringify-able` ones, meaning no circular references\n- All the changes to the cache state are done to memory\n- I could have used a timer or `Object.observe` to deliver the changes to disk, but I wanted to keep this module\n  intentionally dumb and simple\n- Non visited keys are removed when `cache.save()` is called. If this is not desired, you can pass `true` to the save call\n  like: `cache.save( true /* noPrune */ )`.\n\n## License\n\n[MIT](LICENSE) © [Jared Wray](https://jaredwray.com)\n\n","funding_links":[],"categories":["Repository","JavaScript"],"sub_categories":["Cache"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Fflat-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredwray%2Fflat-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Fflat-cache/lists"}