# Cache slow results on disk with FILECACHE

> Use FILECACHE() to compute a result once and reuse it from a file for a period, even after a restart.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 199e2b942373007270d2a87c79ec2477773b3bf71f16023c0c31bf2294bcf4a9
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`FILECACHE(id, expiration, callback, maker)` looks for a cached file for `id`. If it exists and is younger than `expiration` (text such as `'1 minute'`), the callback receives its content; otherwise it calls `maker(done)` to compute the value, stores it and returns it. The result is serialized as JSON. Unlike `CACHE`, it survives restarts and works for large results.

```js controllers/report.js
exports.install = function() {
	ROUTE('GET /report/', report);
};

var computed = 0;

function report($) {

	FILECACHE('monthly-report', '1 minute', function(err, response) {
		$.json({ report: response, computed: computed });
	}, function(done) {
		// The expensive work goes here
		computed++;
		done(null, { total: 42, generated: computed });
	});
}
```
