{"id":23150188,"url":"https://github.com/felixwieland/attic","last_synced_at":"2025-04-04T14:42:33.919Z","repository":{"id":36528905,"uuid":"227457567","full_name":"FelixWieland/attic","owner":"FelixWieland","description":"Sophisticated caching library","archived":false,"fork":false,"pushed_at":"2023-03-03T11:21:16.000Z","size":293,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T17:48:47.791Z","etag":null,"topics":["caching","fallback","lifetime","persistent-storage"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/FelixWieland.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}},"created_at":"2019-12-11T20:49:37.000Z","updated_at":"2023-03-08T16:23:35.000Z","dependencies_parsed_at":"2023-01-17T02:19:49.101Z","dependency_job_id":null,"html_url":"https://github.com/FelixWieland/attic","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/FelixWieland%2Fattic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixWieland%2Fattic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixWieland%2Fattic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixWieland%2Fattic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FelixWieland","download_url":"https://codeload.github.com/FelixWieland/attic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198412,"owners_count":20900078,"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":["caching","fallback","lifetime","persistent-storage"],"created_at":"2024-12-17T18:16:39.524Z","updated_at":"2025-04-04T14:42:33.898Z","avatar_url":"https://github.com/FelixWieland.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# attic\n\n![](https://badge.fury.io/js/%40fwieland%2Fattic.svg)\n[![Actions Status](https://github.com/FelixWieland/attic/workflows/Test/badge.svg)](https://github.com/FelixWieland/attic/actions)\n[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/FelixWieland/attic/blob/master/LICENSE)\n\nAttic synchronizes persistent storage such as localStorage with an object in memory to reduce access time. In addition, it can track the lifetime of an element and discard it if it is too old. To minimize null values, you must specify a fallback (for example, an API query) each time you read from the cache. If an element does not exist or the lifetime of an element has expired, the fallback function is used and the result of this function is stored with the ID passed in the Get function. This means that the cache does not have to be filled explicitly via a set function (although the possibility exists in Attic).\n\n# Installation\n```sh\n// with npm\nnpm install @fwieland/attic\n\n// with yarn\nyarn add @fwieland/attic\n```\n\n# Usage\n\nHere is a quick example to get you started:\n\n```js\nimport Attic from '@fwieland/attic';\n\nconst cache = new Attic(\"storageName\", {\n\tlifetime: 10000, //10sec\n})\n\ncache.get(\"id1\")\n\t.fallback(() =\u003e fetch('https://jsonplaceholder.typicode.com/todos/1').then(r =\u003e r.json())\n\t.then(content =\u003e console.log(content));\n\n```\n\nTo reduce the boilerplate of extracting the json (in case of API-Requests) attic allows to specify a fallbackExtractor function.\n\n```js\nconst cache = new Attic(\"storageName\", {\n\tfallbackExtractor: (r) =\u003e r.json(),\n})\n\ncache.get(\"id1\")\n\t.fallback(() =\u003e fetch('https://jsonplaceholder.typicode.com/todos/1'))\n\t.then(content =\u003e console.log(content));\n\n```\n\n# Options\n\nYou can provide different options to customize and extend attic:\nThe provided examples are the default values of attic.\n\n```js\nconst cache = new Attic(\"storageName\", {\n\n\t// spezifies the liftime of a item\n\tliftime: null,\n\n\t// will get called on the fallback promise\n\tfallbackExtractor: (e) =\u003e e, \n\n\t// On default attic will load the spezific item into memory if it is the first time requested.\n\t// If synOnInit is true attic will load all items that are stored in the persitentCache into the memoryCache.\n\tsyncOnInit: false, \n\n\t// memoryCache, TS-Interface: ICache\n\tmemoryCache: new MemoryCache(),\t\n\n\t//localStorage, TS-Interface: ICache\n\tpersistentCache: new PersistentCache(), \n})\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixwieland%2Fattic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixwieland%2Fattic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixwieland%2Fattic/lists"}