refactored caching.py