Question

I use NHibernate with Memcached as a second level cache and have always been curious about the cache.use_minimal_puts configuration option.

According to the documentation:

hibernate.cache.use_minimal_puts: Optimizes second-level cache operation to minimize writes, at the cost of more frequent reads. This setting is most useful for clustered caches and, in Hibernate3, is enabled by default for clustered cache implementations.

To be clear, I'm not running Memcached in a cluster environment, but it does run on a remote machine. Another factor to consider may be whether or not there is any major difference in speed between reading and writing to Memcached.

Would I benefit from enabling cache.use_minimal_puts in this scenario?

Was it helpful?

Solution

I don’t have experience in NHibernate but have worked with Second level caches in Hibernate and I have been told that the same concepts are applicable to both.

The basic idea behind providing the parameter hibernate.cache.use_ minimal_puts is that before hibernate puts an object in cache it first check the second level cache whether the object is already present there, and if not then only put there.

This would be helpful ONLY when the data reads from caches are very less expensive than data updates. This is what the docs means about the following

...optimization of second-level cache operation to minimize writes, at the cost of more frequent reads.

The case that fits perfectly for this kind of optimization is replication in clustering.

If you are using clustering then the put operation is very expensive as it activates cache replication listeners in case of clustered caches. If you are not using clustering then this put operation is comparatively very cheap.

Even in case of clustering there might be cache providers which rely on invalidation of entities instead of replicating the changes done to them. In that case too, this parameter would be useless.

One factor that can hamper performance is the kind of replication synchronous or asynchronous) used by Memcache. I have not used MemCache but EhCache supports both models.

So in your case as you are NOT using clustering and though the cache is on a remote process I seriously doubt that there would be any performance benefit by setting this parameter to true.

OTHER TIPS

Just to add few more details.

hibernate.cache.use_minimal_puts, setting this value to true will prevent it from blindly overwriting the previously cached values, which solves clustered cache problems. according to the manual, it is enabled by default for clustered cache implementations.

Hibernate provides the configuration property hibernate.cache.use_minimal_puts, which optimizes cache access for clustered caches by increasing cache reads and decreasing cache updates.

CacheMode.REFRESH will bypass hibernate.cache.use_minimal_puts effect

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top