# Persist small settings with MEMORIZE

> Keep a JSON object on disk that survives restarts, for counters and settings that do not need a database.

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

`MEMORIZE(name)` returns a plain object that is saved to `databases/memorize_<name>.json` and loaded again when the app starts. Change it with `data.set(key, value)`, which also schedules the save. Saves are delayed (10 seconds by default) so several changes become one write; pass a delay in milliseconds as the second argument to change it. It is meant for small amounts of data such as counters, flags and settings.

```js definitions/counter.js
MAIN.counter = MEMORIZE('counter', 100);
```

```js controllers/counter.js
exports.install = function() {
	ROUTE('POST /hit/', hit);
	ROUTE('GET /hits/', hits);
};

function hit($) {
	var count = (MAIN.counter.hits || 0) + 1;
	MAIN.counter.set('hits', count);
	$.json({ hits: count });
}

function hits($) {
	$.json({ hits: MAIN.counter.hits || 0 });
}
```
