How to save cache for Java / J2EE web application?

I am developing an application for this every time I need to connect to the service. I want to keep every search in the cache for future reference. Is there any way to do this?

I heard about memcached. But I did not find a suitable site for reference. Can we use ehcache as we use in hibernate?

+4
source share
3 answers

There are various caching solutions in Java. Among them are Infinispan, EhCache and OSCache.

All of them can also be used autonomously, for example. none of them were created exclusively to work as a Hibernate caching provider.

Functionality between caches is slightly different. Infinispan, for example, provides support for the first class of transactions (this means that the element will not be inserted into the cache if the transaction into which the element was inserted by rollbacks). EhCache has excellent support for a really big process, but with storage heaps for the cache.

OSCache comes with very convenient tags for caching content on JSP pages (but this does not work with JSF).

Most of them are capable of performing a typical spill on a disk subject and have some mechanisms for canceling invalid entries. For example, Infinispan has eviction policies, and they do delete obsolete entries from the cache (memory preservation). OSCache, in turn, never deletes an entry from the cache, but marks it as obsolete. When an entry is available, the caller is notified of a record update (used as an exception, but may be different).

These things are usually a β€œcache”, except for a simple concurrent hash map. If your requirements are modest, do not miss this simple solution. Cache memory can be a little complicated to configure, and for you a map in the application area can be enough.

+4
source

You can easily cache data for each user (i.e. session) using OSCache jsp tags. For example, imagine a web application in which the user "worklist" has not changed, and then always serves the cached (i.e. already generated) jsp until the list changes (by calling the flush cache elsewhere in the application)

A jsp-level cover code with a cache tag as follows:

<cache:cache key="foobar" scope="session"> <%= myBean.getData() %> </cache:cache> 

means that the java code myBean.getData () will only be called once per session (unless it turns red)

+1
source

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


All Articles