Added a bit of optimizations to the caching strategy.