Implement in-memory storage backend

**Work in progress: DO NOT MERGE**

This pull request extends the storage API slightly (to add a finalise operation) but the bulk of the changes are to implement the in-memory backend.

Done:

- Add finalise operation to the storage API.

Todo:

- Implement in-memory storage backend;

- Rework tests to use the in-memory storage backend where possible.