refactored redis caching middleware