Add custom count_memory callback for <cache> tag.

For more accurate entry size measurement.
Cache Tag: add alternatives mapping to cache after adding entries.
RAM cache: Fix cache manager balancing bug.

cost_hits and hits were mixed up for cost-aware managers, leading to
gross underestimation of the hit ratio compared to non-cost managers.