Cache expiration of documents

Documents will now automatically expire periodically from the cache if left unused for a longer period of time (currently 10 seconds by default).

This fixes problems with documents getting stuck in the cache when stages crashed while working with them. It also eases debugging by quite a bit since all changes are now periodically persisted to MongoDB.