My application needs to cache non-serializable objects for performance reasons. These non-serializable objects are in-memory models built from an external resource. For example, a validation template is stored as XML in the database, and an in-memory model is constructed by parsing the XML. The in-memory model is relatively expensive to build, so caching improves performance. However, the in-memory model needs to be reloaded from the database when the underlying record is changed.
In a single application scenario, I stored the objects in a simple map. When a record is changed in the database, the in-memory model is rebuilt and replaced the old entry in the map.
In a distributed scenario, I need the invalidation message to propagate across the cluster so that all nodes rebuild the in-memory model when the record changes. I have looked at Infinispan and Hazelcast and they both require all cached objects to be serializable. However, if the cache operates in an invalidation mode (where data is not sent across the wire), I don't see why the cached objects need to be serializable.
What techniques are commonly used in this scenario? Is this scenario unusual (i.e. should I be doing something different)?