CacheClass refactored to run in constant time