lasso-js / lasso

Advanced JavaScript module bundler, asset pipeline and optimizer
582 stars 75 forks source link

Cache invalidates after restart of node server #176

Closed schetnikovich closed 8 years ago

schetnikovich commented 8 years ago

Please guide me if I missed something, but it seems that page cache invalidates after each restart of node server. This leads to long waiting times for the first user.

While investigating this problem, I enabled logging for lasso/perf logger in the following way:

require('raptor-logging').configure({
  loggers: {
    'lasso/perf': 'DEBUG'
  }
});

Each time I restart node server, I see the following when I visit page for the first time:

DEBUG lasso/perf: Completed walk in 137ms
DEBUG lasso/perf: Completed walk in 31ms
DEBUG lasso/perf: Completed walk in 29ms
DEBUG lasso/perf: Completed walk in 1ms
DEBUG lasso/perf: Completed walk in 1ms
INFO lasso/perf: Bundle mappings built in 208ms
DEBUG lasso/perf: Completed walk in 147ms
DEBUG lasso/perf: Completed walk in 3ms
DEBUG lasso/perf: Completed walk in 2ms
INFO lasso/perf: Page bundles built in 363ms
INFO lasso/perf: Async page bundles written in 91ms
INFO lasso/perf: Page bundles written in 1866ms             
INFO lasso/perf: Built page "index" in 2321ms              

Subsequent requests to the same page are instantaneous. My page template looks like this (attributes like package-path, cache-key and name are not used because they already have sane defaults) :

<lasso-page />

...

I also tried different lasso configurations: enabling or disabling bundling, minifying or fingerprinting — the same result.

Did I missed some configuration option?

Thank you!

Environment:

lasso2.7.2
node6.5.0
npm3.10.3
OSMacOS 10.12
patrick-steele-idem commented 8 years ago

This is not fully documented, but you can configure the cache differently for each environment by specifying a cacheProfile in your config:

var cacheProfile = process.env.NODE_ENV === 'production' ? 'production' : 'development';

require('lasso').configure({
  cacheProfile: cacheProfile
});

Here's how the production cache profile impacts caching: https://github.com/lasso-js/lasso/blob/402c4b01dcaeb20a92d703e2bfab983ff18be01b/lib/LassoCache.js#L14-L55

You'll notice that with the production cache profile the final output of lasso is persisted to disk so that it will be very fast on server restart.

Sorry for the lack of documentation :/ Please let me know if that works for you. We need to update the docs.

schetnikovich commented 8 years ago

@patrick-steele-idem It works like a breeze 🚀

We need to update the docs.

Actually, I think you need to write a book :) It is astonishing how much did you covered by numerous open source projects integrated to the whole system. How this is possible? :) Most of us simply don't understand the scope of functionality, that is possible to do with Lasso + Marko + Marko Widgets.