Q:

Compound keys in Ehcache / delete from cache by part key

I want to store objects in a Cache which use keys that use different objects as a common identifier. This works fine when putting keys into the cache or when looking up entries from the cache.
However, sometimes I want to clear the cache from certain objects. Then I only have parts of the key available. I want to delete all entries that match this part of the key. Is there an easy way of clearing the cache from such entires?

A:

Well, I got as far as using the Searchable API which works for caches that do not overflow to disk. In my case, there is apparently no solution. I built my own cache now which stands on top of the Guava cache where I serialize entries by using a RemovalListener and check for the existence of a value stored on disk in the CacheLoader. I still experience some minor issuses since the RemovalListener is not synchronized on the cache's keys. Otherwise, this works fine. Since Guava caches are less expensive than Ehcaches, this also allows me to create several instances. When I serialize, I create files for each key region such that I can just delete an entire folder if I need to clean up for a compound key value.

