Define a new beforeCache event used to cleanup DOM before caching.