Added ability to clean cache according to a function