Completely remade the caching functionality.
Fixes NPE when a discarded document is persisted.
Merge pull request #1 from laserval/new-cache

Fixes NPE when a discarded document is persisted.
Merge pull request #185 from jwestberg/new-cache

Completely remade the caching functionality.