I was thinking of implementing something like this, since it's fairly straightfoward. Or so I thought....
Eviction based on, say a fraction of total free memory, would make sense. In Java 1.5, it is easy to get the MXBean that return heap information, etc.
What users might want to do is specify how much memory is allocated for a particular cache (region), or to a percentage of the maximum heap storage for caching... not to simply evict on some arbitrary percentage of memory free. Somehow this seems a bit unstable.
If it were possible, calcuating a cache's exact memory footprint would be ideal. I believe, though, with some sort of sampling (and maybe by serializing the data itself), a "good enough" estimate could be obtained. And actually, providing an estimated size of the cache (in bytes) would be useful to know as a user. For commonly-kept objects (such as "String" or "integer"), using the Java "SizeOf" program should produce a good size estimate of these types. Sampling should be done randomly, of course, and if just perhaps 1% of the objects were sampled,