Major overhaul of caching system