Text this: Learning How and What to Memorize: Cognition-Inspired Two-Stage Optimization for Evolving Memory