Data processing and caching in db on data retrieval