Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ehcache & MultiThreading

Does ehcache support multi-threading by default or does it require any configuration changes? On multi threading my application with Ehcache i found that the DB hit count is actually increasing i.e. there is no global cache available for all the threads despite the fact that my cache's are all Singletons. Any suggestions?

like image 326
hakish Avatar asked Jun 02 '09 11:06

hakish


1 Answers

This may help answer your question, from the FAQ:

Is it thread safe to modify Element values after retrieval from a Cache?

Remember that a value in a cache element is globally accessible from multiple threads. It is inherently not thread safe to modify the value. It is safer to retrieve a value, delete the cache element and then reinsert the value.

(emphasis added by me)

like image 156
matt b Avatar answered Sep 19 '22 15:09

matt b