How to implement cache in spring-integration? - spring-integration

I want to implement the cache so whenever table is updated in database ,my entity should get updated.How can i implement caching feature in spring integration ?

See the Spring Framework Caching Abstraction.
You would need some mechanism to invalidate the cache when the external resource changes.

Related

Spring Hibernate SessionFactory.getCurrentSession in multithreaded environment

I have written a batch application which spawns multiple threads to read assigned files and save records to database. The architecture uses Spring context and Hibernate.
Transaction is managed by Spring and I am using SessionFactory.getCurrentSession to get a session to perform a save operation for each thread.
Consider that I have a generic DAO that handles get, save, update operations and a facade to hide Hibernate implementation, how can I be assured that two threads when invoking SessionFactory.getCurrentSession() are getting their dedicated Session object to perform DB operations.
I found a post in StackOverflow where someone recommended not to use current_session_context_class=thread when using spring managed transaction. what is the default implementation used by Spring for current_session_context_class property?
Thanks in Advance!
As of Spring 2.0 Spring integrates with hibernate throuhg its own implementation(s) of the CurrentSessionContext interface provided by hibernate.
By default spring sets this to the SpringSessionContext to integrate properly. In general you don't want or need to mess with the current_session_context_class unless you are using JTA (although when using Hibernate 4 with a recent Spring version it should also just work).

Using EHCache in JSF Web Application

I am working on JSF application. I want to cache some database table on periodic basis. I heard EHCache does it, but I only see its use in Hibernate. Is it possible to use EHCache in JSF application or is there some alternative for that in JSF?
if you want use EHCache in front end part you should write cache handler with
net.sf.ehcache.CacheManager or primefaces support now ehcache, if application is big, prefer to have
cache handler service which put/get/check objects from the cache.
It is your responsibility to integrate with a caching layer if none of the frameworks you use provide such an integration. You will usually do this at the service layer that computes your view objects from your stored domain objects.
Ehcache supports different caching patterns. And here again, picking the one that fits your use case is your responsibility.

Global Transaction Handling in Spring Integration

Its a Spring Integration application.I have a requirement where I need to persist to DB and then post to Queue/Topic. This should be part of a single transaction. I am planning to use the JTATransactionManager. Application Server is Tomcat. Would someone please provide some sample configuration code required for this implementation.
You need a third party stand-alone XA transaction manager such as Atomikos. Tomcat doesn't have one.
You might also consider alternatives to using full-blown 2pc.

Use external cache provider for RazorEngine

Currently RazorEngine, caches the template in memory.
Is there anyway to use an external caching provider?
We have 10 web servers in a webfarm, and now each of them needs to cache the template separately. That would be great if we can implement our own caching system and use something like Memcached.
Yes, you should now be able to do that in 3.5.0 (currently beta). You can provide your own ICachingProvider implementation that fits your needs. Documentation and an example implementation can be found here. What you want to do is saving the compiled assemblies and then loading the assemblies and the template-types when needed.
Disclaimer: I contributed that API to RazorEngine.

spring.net application scope repository object on loadbalanced application

We have an application running on a loadbalanced environment, let say webserver A and B.
The loadbalancing is on the HTTP level, so the loadbalancer directs each user request to one of both webservers.
The scope of the repositories in the application is managed by the spring.net container,
and the application relies on data that can be cached by the repository (performance reasons).
In this case we can never be sure that the cached data in the repositories on both webservers is the same.
Is there mechanism in spring.net that can manage this kind problem? Or is there another common approach for this kind of thing?
Any ideas?
Thx,
Bert
Spring.NET is an object container. It is not intended to be used as a caching container therefore you should not store your data in the repositories. What you need in this case is a distributed caching solution such as memcached. It has a .NET client library also.
So basically your repositories will first look in the distributed cache if the object exists and if not then hit the real data store in order to get the object and store it into the cache. Spring.NET will handle the lifetime of these repositories and as you are running in a webfarm you will have a repository per server but this won't be an issue because these repositories will use a distributed cache to fetch data so you will get consistent resylts between all the servers in the farm.

Resources