Improved cache module to avoid inconsistent cache states with disabled caching methods.
Added unit tests.