{"id":15673925,"url":"https://github.com/fabioricali/incache","last_synced_at":"2025-05-06T22:45:42.660Z","repository":{"id":57273239,"uuid":"100122317","full_name":"fabioricali/incache","owner":"fabioricali","description":"Powerful key/value in-memory storage or on disk to persist data","archived":false,"fork":false,"pushed_at":"2020-09-04T16:40:49.000Z","size":547,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-06T22:45:34.409Z","etag":null,"topics":["cache","cache-storage","global","http-response","in-memory","javascript","memory-storage","node-cache","nodejs","session-management","singleton","storage","window"],"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/fabioricali.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":"2017-08-12T15:53:05.000Z","updated_at":"2023-07-30T18:29:46.000Z","dependencies_parsed_at":"2022-09-17T05:11:07.285Z","dependency_job_id":null,"html_url":"https://github.com/fabioricali/incache","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fincache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fincache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fincache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fincache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabioricali","download_url":"https://codeload.github.com/fabioricali/incache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782459,"owners_count":21803380,"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","cache-storage","global","http-response","in-memory","javascript","memory-storage","node-cache","nodejs","session-management","singleton","storage","window"],"created_at":"2024-10-03T15:43:06.359Z","updated_at":"2025-05-06T22:45:42.636Z","avatar_url":"https://github.com/fabioricali.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/fabioricali/incache/master/extra/logo.png?2\" title=\"incache\"/\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\u003cbr/\u003e\u003cbr/\u003e\nPowerful key/value in-memory storage or on disk to persist data\n\u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://travis-ci.org/fabioricali/incache\" target=\"_blank\"\u003e\u003cimg src=\"https://travis-ci.org/fabioricali/incache.svg?branch=master\" title=\"Build Status\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/fabioricali/incache?branch=master\" target=\"_blank\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/fabioricali/incache/badge.svg?branch=master\u00262\" title=\"Coverage Status\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" title=\"License: MIT\"/\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/team-terrons-orange.svg\" title=\"Team Terrons\"/\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\u003c/div\u003e\n\n## What does?\nInCache is a module that store any info in memory, it can be used for example for storing **server sessions**, **caching http response** or **sharing singleton object** in your apps.\nIt also give you the possibility to save data on disk so you can avoid the data loss when the process exit or restart. In a browser scenario all data is saved on localStorage through a key.\n\n## Installation\n\n### Node.js\n```\nnpm install incache --save\n```\n\n## Examples\n\n### Basic\n```javascript\nconst InCache = require('incache');\nconst store = new InCache();\n\n// Create a record with key 'my key'\nstore.set('my key', 'my value');\n\n// Update 'my key'\nstore.set('my key', {a: 1, b: 2});\n\n// Get key\nstore.get('my key');\n\n// Remove 'my key'\nstore.remove('my key');\n\n// Clear\nstore.clear();\n\n// Expires after 2 seconds\nstore.set('my string', 'hello world', {maxAge: 2000});\n// Or expires on...\nstore.set('my string', 'hello world', {expires: '2028-08-22 12:00:00'});\n```\n\n### Auto remove expired records\n```javascript\nconst store = new InCache({\n    autoRemovePeriod: 2 //checks every 2 seconds\n});\n\nstore.set('my string', 'hello world', {maxAge: 4000});\n\nsetTimeout(()=\u003e{\n    console.log(store.count()) //=\u003e 0\n}, 6000);\n```\n\n### Max cache size\n```javascript\nconst store = new InCache({\n    maxRecordNumber: 5\n});\n\nstore.set('k0', 'v0');\nstore.set('k1', 'v1');\nstore.set('k2', 'v2');\nstore.set('k3', 'v3');\nstore.set('k4', 'v4');\nstore.set('k5', 'v5');\n\nconsole.log(store.count()); //=\u003e 5\nconsole.log(store.has('k0')); //=\u003e false\n```\n\n### Load manually\n```javascript\nconst store = new InCache({\n    autoLoad: false\n});\n\n// This method returns a Promise\nstore.load('my-path/my-store.json').then(() =\u003e {\n    console.log('loaded');\n}).catch(err =\u003e {\n    console.log(err);\n});\n```\n\n### Save on disk\nBy default this operation is running before the process is terminated\n```javascript\nconst store = new InCache({\n    autoSave: true\n});\n```\n\nSave when data is changed\n```javascript\nconst store = new InCache({\n    autoSave: true,\n    autoSaveMode: 'timer'\n});\n```\n\n### Save manually\n```javascript\nconst store = new InCache({\n    filePath: 'my-path/my-store.json'\n});\n\nstore.set('a key', 'a value');\n\n// This method returns a Promise\nstore.save();\n\n// or specify a path\nstore.save('a-path/a-file.json').then(()=\u003e{\n    console.log('saved');\n    store.load('a-path/a-file.json');\n}).catch(err =\u003e {\n    console.log(err);\n});\n```\n\n### Browser scenario\nIn browser environment the file path becomes a string key for localStorage interface:\n```javascript\nstore.load('myLocalStorageKey');\nstore.save('myLocalStorageKey');\n```\n\n### Events\n```javascript\n\n// Triggered when a record has been deleted\nincache.on('remove', key =\u003e {\n    console.log(key);\n});\n\n// Triggered before create/update\nincache.on('beforeSet', (key, value) =\u003e {\n    console.log(key, value);\n    if(foo)\n        return false;\n});\n\n// Triggered when a record has been created\nincache.on('create', (key, record) =\u003e {\n    console.log(key, record);\n});\n\n//Triggered when a record has been updated\nincache.on('update', (key, record) =\u003e {\n    console.log(key, record);\n});\n\n//Triggered when the cache is saved on disk\nincache.on('save', () =\u003e {\n    console.log('saved on disk');\n});\n\n//Triggered when the cache exceed max size\nincache.on('exceed', (diff) =\u003e {\n    console.log(`exceeded for ${diff}`);\n});\n\n//... for more events see the documentation\n```\n\n### API\nPlease see the **\u003ca href=\"https://github.com/fabioricali/incache/blob/master/api.md\"\u003efull documentation\u003c/a\u003e** for more details.\n\n### Browser\n\n#### Local\n```html\n\u003cscript src=\"node_modules/incache/dist/incache.min.js\"\u003e\u003c/script\u003e\n```\n\n#### CDN unpkg\n```html\n\u003cscript src=\"https://unpkg.com/incache/dist/incache.min.js\"\u003e\u003c/script\u003e\n```\n\n#### CDN jsDeliver\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/incache/dist/incache.min.js\"\u003e\u003c/script\u003e\n```\n\n## Changelog\nYou can view the changelog \u003ca target=\"_blank\" href=\"https://github.com/fabioricali/incache/blob/master/CHANGELOG.md\"\u003ehere\u003c/a\u003e\n\n## License\nInCache is open-sourced software licensed under the \u003ca target=\"_blank\" href=\"http://opensource.org/licenses/MIT\"\u003eMIT license\u003c/a\u003e\n\n## Author\n\u003ca target=\"_blank\" href=\"http://rica.li\"\u003eFabio Ricali\u003c/a\u003e\n\n## Contributor\n\u003ca target=\"_blank\" href=\"https://www.mdslab.org\"\u003eDavide Polano\u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioricali%2Fincache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabioricali%2Fincache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioricali%2Fincache/lists"}