Java caching required

I am looking for a caching solution for a Java web application. We have an instance of Oracle db and 2-3 instances that are removed from our db. We want to cache data locally in our application, since we cannot accept db response time. Our data set has an average size (several thousand rows per table) and is changed manually (not so often) from our application (without direct access to db).

So what we think is a solution that allows us to have all the data needed for local use. We would like to reduce the amount of data retrieved from db and overwritten in cache.

So, for example, when one object is changed, we don’t want to cancel all cached requests in this table, we rather want to change the local cached requests, so the request can still be executed locally from the data cache. Caches should replicate their changes / retrieve data modified by other application instances from db.

We considered EhCache as a second-level cache of Hibernate, but it is not valid for all cached requests for this table with any modification of the table. I quickly looked through Hibernate Services, but I don’t know if this will allow us to override the default behavior for Level 2 sleep caching to meet our needs.

Are there any other solutions that we could use?

Change We want to have very fast data access. Effectively, what we are looking for is a cache being accessed.

+4
source share
3 answers

Have you checked the JBoss cache? You can define seeding policies for your requests separately, and it is also very easy to synchronize between cluster nodes. If you need, you can read the article that I collected some time ago, when it is useful to you;

http://dinukaroshan.blogspot.com/2009/10/jboss-caching-integration.html

+3
source

If you use EhCache and you have several applications in clusters, you will have to use a mechanism (JMS, JGroups, ...) to replicate the data cache.

One thing you should be aware of is that if you have another application that is not running in Java, the application will not be notified: JGroups are available only in Java, and your application, other than Java, will not be able to invalidate the organization’s caching. EhCache / Jgroups support allows you to configure replication in ONE configuration file (no additional code required!)

It seems that you are looking for the EhCache Update Through Copy feature. Let me point out one of the configuration options for EhCache:

Update via copy and invalidation

Update via copy : data sent to all nodes
Pros: Avoid a complete cache reload
Cons: Unrelated data between nodes is possible and useless if the TTL of cached data is low

Update using invalidation . Invalidation notification sent to all nodes. If the data is already cached, the nodes again delete the cached data request.
Pros: data consistency and easier network traffic
Cons: a lot of database queries, and this can lead to massive data demand at the same time.


Async vs sync

Asynchronous
Pros: fast response and data transfer
Cons: UDP ...

Synchronize
Pros: data integrity
Cons: Perf ...


Hope this helps you choose the right solution.

+2
source

The invalidity of a cached query result is not something that controls the cache, but how Hibernate processes its QueryCache ... Without changing this code, I don’t see how you do it. And besides, I don’t think that there is a better solution "fits all" to this problem.

So, if you want a very specialized caching of the query result, I think you will have to implement this yourself.

Also, if you need higher consistency guarantees, you probably want to use cluster caches rather than replicated ones ...

0
source

Source: https://habr.com/ru/post/1446206/


All Articles