{"id":20604792,"url":"https://github.com/themost-framework/cache","last_synced_at":"2026-02-12T11:04:36.450Z","repository":{"id":43193715,"uuid":"469451898","full_name":"themost-framework/cache","owner":"themost-framework","description":"MOST Web Framework Caching Module","archived":false,"fork":false,"pushed_at":"2024-05-25T09:19:00.000Z","size":629,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T13:42:27.087Z","etag":null,"topics":["cache","caching","data"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/themost-framework.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":"2022-03-13T17:59:36.000Z","updated_at":"2024-05-25T09:13:14.000Z","dependencies_parsed_at":"2024-11-16T09:26:13.969Z","dependency_job_id":"09ae1348-45b0-4691-ad64-c5e117a12746","html_url":"https://github.com/themost-framework/cache","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/themost-framework","download_url":"https://codeload.github.com/themost-framework/cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244885515,"owners_count":20526293,"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","caching","data"],"created_at":"2024-11-16T09:24:52.241Z","updated_at":"2026-02-12T11:04:36.395Z","avatar_url":"https://github.com/themost-framework.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @themost/cache\nMOST Web Framework Data Caching\n\n@themost/cache implements the default data caching strategy that is going to be used by any [@themost](https://github.com/themost-framework) data application\n\nImportant note: This module has been separated from [@themost/data](https://github.com/themost-framework/data) even if it exports the default caching strategy.\n\n## Installation \n    npm i @themost/cache\n\n## Configuration\n\n`@themost/cache/platform-server#DefaultDataCachingStrategy` is being registered by `@themost/data#DataConfiguration`:\n\n    {\n        \"services\": [\n            {\n                \"serviceType\": \"@themost/cache#DataCacheStrategy\",\n                \"strategyType\": \"@themost/cache/platform-server#DefaultDataCacheStrategy\"\n            }\n        ]\n    }\n        \nConfigure absolute expiration timeout by setting `absoluteExpiration` under `settings/cache` section:\n\n    {\n        \"settings\": {\n            \"cache\": {\n                \"absoluteExpiration\": 900\n            }\n        }\n    }\n\nThis setting is going to be used by [node-cache](https://github.com/node-cache/node-cache#initialize-init) which is the caching engine initiated by `@themost/cache#DefaultDataCacheStrategy` strategy.\n\n`@themost/cache/platform-server#IndexedCacheStrategy` is an alternative caching strategy which uses disk for caching items.\n\n    {\n        \"services\": [\n            {\n                \"serviceType\": \"@themost/cache#DataCacheStrategy\",\n                \"strategyType\": \"@themost/cache/platform-server#IndexedCacheStrategy\"\n            }\n        ]\n    }\n    \nConfigure disk cache root under `settings/cache` section (the default value is `.cache/diskCache`):\n\n    {\n        \"settings\": {\n            \"cache\": {\n                \"absoluteExpiration\": 900,\n                \"rootDir\": \".cache/diskCache\"\n            }\n        }\n    }\n\nand the interval -in seconds- of validating the expiration of cached items: \n\n    {\n        \"settings\": {\n            \"cache\": {\n                \"absoluteExpiration\": 900,\n                \"rootDir\": \".cache/diskCache\",\n                \"checkingPeriod\": 60\n            }\n        }\n    }\n\nCheckout other data caching strategies like [@themost/memcached](https://www.npmjs.com/package/@themost/memcached), [@themost/redis](https://www.npmjs.com/package/@themost/redis) etc.\n\n## Output caching\n\n`@themost/cache#OutputCaching` enables caching mechanisms on [expressjs](https://github.com/expressjs/express) application based on pre-defined cache profiles\n\ne.g.\n\n    const clientCacheProfile = {\n        location: 'client',\n        duration: 60 * 60, // 1 hour\n        varyByHeader: [\n            'accept',\n            'accept-encoding',\n            'accept-language',\n            'accept-profile'\n        ],\n        varyByParam: [\n            '*' // use any query param\n        ],\n        varyByCallback: async (req) =\u003e {\n            if (req.headers.authorization) {\n                return `context=${MD5(req.headers.authorization).toString()}`\n            }\n            return null;\n        } \n    }\n\n    ...\n\n    // setup cache\n    app.use(OutputCaching.setup({\n        rootDir: '.cache/indexedCache',\n        absoluteExpiration: 20 * 60 // 20 minutes,\n        checkingPeriod: 60 * 1000 // 1 minute\n    }));\n\n    ...\n\n    app.use('/api/hello', OutputCaching.cache(clientCacheProfile), (req, res, next) =\u003e {\n        return res.json({\n            message: 'Hello World'\n        });\n    });\n\nwhere `/api/hello` response will be cached on client side based on several parameters defined in `clientCacheProfile`.\n\n### OutputCaching.cache(PreOutputCacheConfiguration)\n\nCaches response based on cache profile parameters\n\n#### duration\n\n\u003e int\n\nGets or sets the time duration in seconds during which the response is cached.\n\n#### location\n\n\u003e string \n\nGets or sets the output cache location.\n\n|   |   |\n|---|---|\n| client | The output cache is located on the browser\n| server | The output cache is located on the server\n| serverAndClient | The output cache is located both on the client and server\n| none | The output cache is disabled\n| any | The output cache is located both on the client and server\n\n#### varyByHeader\n\n\u003e string[]\n\nGets or sets an array of headers used to vary the cached output\n\n#### varyByParam\n\n\u003e string[]\n\nGets or sets an array of query string params used to vary the cached output\n\n#### varyByContentEncoding\n\n\u003e string\n\nGets or sets a content encoding which will be used to vary the cached output\n\n#### varyByCallback\n\n\u003e function(): Promise\u0026lt;string\u0026gt;\n\n`varyByCallback()` method may used to programmatically vary the cached output.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthemost-framework%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Fcache/lists"}