implemented memory caching middleware