large refactoring of the cache system