ForgeTotal.js 5
sk

Total.js 5

Ukladaj pomalé výsledky na disk cez FILECACHE

Total.js 5 · total5@0.0.19 cacheperformancefiles Spustené s Total.js 5

FILECACHE(id, expiration, callback, maker) hľadá cache súbor pre id. Ak existuje a je mladší ako expiration (text ako '1 minute'), callback dostane jeho obsah; inak zavolá maker(done), aby hodnotu vypočítal, uloží ju a vráti. Výsledok sa serializuje ako JSON. Na rozdiel od CACHE prežije reštart a hodí sa aj pre veľké výsledky.

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 });
	});
}