Coder Social home page Coder Social logo

think-html-cache's Introduction

think-html-cache

html-cache middleware for ThinkJS 2.0

Install

npm install think-html-cache

How to use

register middleware

create file is not exist, src/common/bootstrap/middleware.js

import htmlCache from 'think-html-cache';
think.middleware('html_cache', htmlCache);

hook config

src/common/config/hook.js

export default {
  logic_before: ['prepend', 'html_cache'],
  view_after: ['append', 'html_cache']
}

html_cache config

create file is not exist src/common/config/html_cache.js:

export default {
  on: true, //use html_cache
  type: 'base', //cache content store type
  timeout: 0,
  callback: function(key){
    return think.md5(key);
  },
  rules: {
    'home/index/index': ['index_{page}', timeout, callback],
    'index/detail': ['index_{id}', timeout, callback]
  },
  //adapter config
  adapter: {
    file: {
      path: think.getPath('common', 'runtime') + '/html_cache' //when type is file, set cache path
    }
  }
}

type

cache content store type, support base & file.

timeout

expire time, if value is 0, only expired when template is updated.

callback

encrypt cache key, such as:

function (key) {
  return think.md5(key);
}

rules

cache rules, key is [module]/[controller]/[action].

can get paramters in rule:

'index_{page}' // get page paramter from GET
'index_{:module}' // get module value
'index_{:controller}' //get controller value
'index_{:action}' //get action value
'index_{cookie.xxx}' //get value from cookie

LICENSE

MIT

think-html-cache's People

Contributors

welefen avatar

Watchers

James Cloos avatar teen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.