{"id":18368216,"url":"https://github.com/thinkjs/think-html-cache","last_synced_at":"2025-04-06T17:31:39.839Z","repository":{"id":73609589,"uuid":"45368071","full_name":"thinkjs/think-html-cache","owner":"thinkjs","description":"html-cache middleware for ThinkJS 2.0","archived":false,"fork":false,"pushed_at":"2015-12-23T03:31:49.000Z","size":10,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T12:07:24.726Z","etag":null,"topics":["thinkjs","thinkjs2"],"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/thinkjs.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":"2015-11-02T02:33:58.000Z","updated_at":"2017-03-10T01:11:52.000Z","dependencies_parsed_at":"2023-03-16T02:43:41.169Z","dependency_job_id":null,"html_url":"https://github.com/thinkjs/think-html-cache","commit_stats":null,"previous_names":["welefen/think-html-cache"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-html-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-html-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-html-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-html-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-html-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247522339,"owners_count":20952525,"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":["thinkjs","thinkjs2"],"created_at":"2024-11-05T23:25:09.270Z","updated_at":"2025-04-06T17:31:39.565Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# think-html-cache\n\nhtml-cache middleware for ThinkJS 2.0\n\n## Install\n\n```sh\nnpm install think-html-cache\n```\n\n## How to use\n\n### register middleware\n\ncreate file is not exist, `src/common/bootstrap/middleware.js`\n\n```js\nimport htmlCache from 'think-html-cache';\nthink.middleware('html_cache', htmlCache);\n```\n\n### hook config\n\n`src/common/config/hook.js`\n\n```js\nexport default {\n  logic_before: ['prepend', 'html_cache'],\n  view_after: ['append', 'html_cache']\n}\n```\n\n### html_cache config\n\ncreate file is not exist `src/common/config/html_cache.js`:\n\n```js\nexport default {\n  on: true, //use html_cache\n  type: 'base', //cache content store type\n  timeout: 0,\n  callback: function(key){\n    return think.md5(key);\n  },\n  rules: {\n    'home/index/index': ['index_{page}', timeout, callback],\n    'index/detail': ['index_{id}', timeout, callback]\n  },\n  //adapter config\n  adapter: {\n    file: {\n      path: think.getPath('common', 'runtime') + '/html_cache' //when type is file, set cache path\n    }\n  }\n}\n```\n\n**type**\n\ncache content store type, support `base` \u0026 `file`.\n\n**timeout**\n\nexpire time, if value is `0`, only expired when template is updated.\n\n**callback**\n\nencrypt cache key, such as:\n\n```js\nfunction (key) {\n  return think.md5(key);\n}\n```\n\n**rules**\n\ncache rules, key is `[module]/[controller]/[action]`.\n\ncan get paramters in rule:\n\n```\n'index_{page}' // get page paramter from GET\n'index_{:module}' // get module value\n'index_{:controller}' //get controller value\n'index_{:action}' //get action value\n'index_{cookie.xxx}' //get value from cookie\n```\n\n\n## LICENSE\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-html-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-html-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-html-cache/lists"}