Implemented thread and last_50 query-level caching with clearing if changes are made