Filter all message events in the Master when not elected.

Review: https://reviews.apache.org/r/19374
Added cache::erase and cache::size.

Review: https://reviews.apache.org/r/19375