db caching fix and cleanup