jaysylvester / citizen

Node.js MVC web application framework. Includes routing, serving, caching, session management, and other helpful tools.
MIT License
100 stars 7 forks source link

Cache route and controller renderings under format namespaces #85

Closed jaysylvester closed 3 years ago

jaysylvester commented 3 years ago

Route cache renderings are stored currently as their compression schemes:

render: {
  identity : render,
  gzip     : zipped,
  deflate  : deflated
}

With a given route now able to return multiple formats (HTML, JSON, etc.) using the Accept header, the route cache needs to be reworked so a single route cache can store multiple formats:

render: {
  'text/html': {
    identity : renderHTML,
    gzip     : zipped,
    deflate  : deflated
  },
  'application/json': {
    identity : renderJSON,
    gzip     : zipped,
    deflate  : deflated
  }
}

The best approach is probably to only render and cache each format as it's requested. This will minimize CPU and memory usage, but will require modifying cache.exists(), cache.setRoute(), and cache.getRoute().

Need to think more about how this will work for controller caching. Probably similar to routes.