Posting this here because I think I saw this in a homebrewing website but I really don't know, sorry if this is a core rule. I remember reading about an enhancement called "Mage's Hammer" or something like this.

What it did was, it would destroy the caster's highest prepared spell/spell per day if the caster was attacked. Was looking for it to re-read the description, but can't find it anywhere. Any idea?