1 | # coffee-cache
|
2 |
|
3 | Caches the contents of required CoffeeScript files so that they are not
|
4 | recompiled to help improve startup time.
|
5 |
|
6 | ## What it does
|
7 |
|
8 | In a Node.js application written in CoffeeScript, every time you start the
|
9 | application, all the relevant files must be compiled when they are required. If
|
10 | you have a very large application, this process can consume a large portion of
|
11 | your startup time. By caching the compiled JavaScript files, only those that
|
12 | have been updated must be recompiled, and the rest can be loaded off of the
|
13 | disk. In our usage, this has reduced the startup time from 7s to 2s, which means
|
14 | a lot when you have to restart your application every time you want to test a
|
15 | change.
|
16 |
|
17 | ## How to use
|
18 |
|
19 | 1. Add to your package.json dependencies and run `npm install` or run `npm install coffee-cache`.
|
20 |
|
21 | 2. In your entry point file, add the following:
|
22 |
|
23 | ```coffee
|
24 | require('coffee-cache')
|
25 | ```
|
26 |
|
27 | 3. That's it. By default the files are cached in the `./.coffee/` directory. If
|
28 | you want to change this, see below.
|
29 |
|
30 | ## Extra configuration
|
31 |
|
32 | You can specify the location of the directory to use for the cached files in one
|
33 | of two ways:
|
34 |
|
35 | 1. Start the process with the `COFFEE_CACHE_DIR` variable set:
|
36 |
|
37 | ```sh
|
38 | $ COFFEE_CACHE_DIR=/tmp/coffee-cache coffee app.coffee
|
39 | ```
|
40 |
|
41 | 2. Use the `setCacheDir` method on the required module:
|
42 |
|
43 | ```coffee
|
44 | require('coffee-cache').setCacheDir('../cached/')
|
45 | ```
|
46 |
|
47 | Just make sure your process has permission to create the necessary folder or
|
48 | files.
|