Cache for community edition

13
Cache For Community Edition By Anirban Sen Chowdhary

Transcript of Cache for community edition

Cache For Community Edition

By Anirban Sen Chowdhary

We have seen examples on Mule Cache mechanism with Cache Scope. But this time we will see implementing Cache for Mule Community Edition.Mule Community Edition doesn’t have the Cache Scope as Mule Enterprise Edition, so to implement Cache in Community Edition we require Custom Interceptor.

You can already refer https://github.com/ddossot/mule-in-action-2e/blob/master/chapter12/src/main/java/com/prancingdonkey/interceptor/PayloadCacheInterceptor.java which shows implementing Cache in Community Edition by David Dassot.In my demonstration I have modified the code and implemented on the top of it with additional Filter Expression

How to Cache with Community Edition??

To use Cache with Mule we have to construct our flow in following way :-

You can see the flow is divided into 2 parts and is connected by VM component. You can see we have used Custom Interceptor to implement Cache in this Community Edition

Our Mule config will be as follow:-

You can see we are using our Custom interceptor implemented and a spring property filterExpression which will filter the expression we want to implement .

Our Custom interceptor Java class:-

In next step we will be running and testing the application. This web service will interact with database retrieve a row from the database and show the row value in the SOAP response.

Here how we will test the web service :-

You can see that we have used SoapUI to test the web service. Now when we hit the service, you can see in the SOAP request, it takes id as input and then fetches all the data from the database for that id.

Now, what we will do is manually deleting the entire row from the database. In my case, I have used sql server and deleted the row from the table using a SQL query:-

With this in place, if we again hit the service, we will get the same response as we got earlier:-

And that means our Cache is working and it’s responding from the Cache and not hitting the actual Database !!! So our Custom interceptor is implementing the Cache !!

So you can see that we have implemented the Cache for the Community Edition which has the feature of filtering the expression like the Cache scope of Enterprise Edition. So, you can implement your own Cache using Custom Interceptor.

In my next slide I will bring some other techniques in Mule implementation .Hope you have enjoyed this simpler version. Keep sharing your knowledge and let our Mule community grow

Thank You