java - How to cache information in a DAO in a threadsafe manner -


I often need the implementation of DAO for some reference data, which does not change very often, sometimes I am on DAO I cache it in the archive area - so that it is only once full and clearly updated if necessary.

Although it brings issues of several concurrency - what if another thread tries to access data during data loading or renewal

Obviously this data is received Both the makers and setters can be controlled by synchronizing - but for a large web application this is an overhead.

What I want as a trivial faulty Stormman Please suggest alternative ways of applying it.

Public Class Location IDOIMPL Applicable Location DAO {Private List & Location; Location & gt; Places = null; Public listing & lt; Location & gt; GetAllLocations () {if (places == zero) {loadAllLocations (); } Return location; }

For more information, I am using hibernate and spring but this requirement will apply to many techniques.

Some more thoughts:

Should not it be handled in the code at all - in turn, handle echocach or similar? Is there a common pattern of this that I am missing? Obviously, this can be achieved in many ways, but I have never found any pattern that is simple and strong.

Thanks in advance!

If you just want a quick roll-your own caching solution, then see the article on JavaSpecialist, which That's the review of that book.

It talks about implementing an original thread secure cache.

The way this is done, it ensures that only a concurrent thread triggers longer-lasting computing (in your case, your database call in your DAO).

If you need this, then you have to modify this solution to add a cash expiry.

It is a waste of other ideas about caching itself. Without using the weak Hasham for your cache, GC will not be able to release the memory used by the cache if necessary. If you are sometimes accessing data (but the data that is caching for caching is still difficult to calculate), then you would want to help the weak collector, when less memory becomes weak and weak.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -