cache middleware based on debug