Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Caching implementation in Liferay 7.2
Hi All ,
I want to implement caching in liferay 7.2 . I found this just ONE link for reference when searched.
https://dev-journal.in/2018/04/27/how-to-implement-caching-in-liferay7/
I am not very clear with the info.
Can you please give me more information on the same or share a sample module if available.
Note: I donot intend to use Redis, I want to Liferay cache implementation.
Thanks in Advance.
Regards,
Prathibha
I want to implement caching in liferay 7.2 . I found this just ONE link for reference when searched.
https://dev-journal.in/2018/04/27/how-to-implement-caching-in-liferay7/
I am not very clear with the info.
Can you please give me more information on the same or share a sample module if available.
Note: I donot intend to use Redis, I want to Liferay cache implementation.
Thanks in Advance.
Regards,
Prathibha
Hi,
Li feray provides either the SingleVMPool or the MultiVMPool (for clustered environments)
https://docs.liferay.com/ce/portal/7.1-latest/javadocs/portal-kernel/com/liferay/portal/kernel/cache/SingleVMPool.html
https://docs.liferay.com/ce/portal/7.1-latest/javadocs/portal-kernel/com/liferay/portal/kernel/cache/MultiVMPool.html
Which one to use depends on whether you have a cluster and also on your caching strategy.
Li feray provides either the SingleVMPool or the MultiVMPool (for clustered environments)
https://docs.liferay.com/ce/portal/7.1-latest/javadocs/portal-kernel/com/liferay/portal/kernel/cache/SingleVMPool.html
https://docs.liferay.com/ce/portal/7.1-latest/javadocs/portal-kernel/com/liferay/portal/kernel/cache/MultiVMPool.html
Which one to use depends on whether you have a cluster and also on your caching strategy.
I followed this link https://dev-journal.in/2018/04/27/how-to-implement-caching-in-liferay7/ I am getting error while running deploy . Error below:
error : Exporting an empty package 'com.liferay.cache.exception'
error : Exporting an empty package 'com.liferay.cache.model'
error : Exporting an empty package 'com.liferay.cache.service.persistence'
error : Exporting an empty package 'com.liferay.cache.exception'
error : Exporting an empty package 'com.liferay.cache.model'
error : Exporting an empty package 'com.liferay.cache.service.persistence'
Really, that link you keep sharing is total crap...
First, we don't need fake entities in 7, it is easier to build API and Impl modules w/o the SB overhead.
But more importantly, what he documents isn't a cache as much as it is an "in memory data sink". Caching implies expiry, flushing, size limits, etc. That implementation you're pointing to is not a cache.
First, we don't need fake entities in 7, it is easier to build API and Impl modules w/o the SB overhead.
But more importantly, what he documents isn't a cache as much as it is an "in memory data sink". Caching implies expiry, flushing, size limits, etc. That implementation you're pointing to is not a cache.
Ok, so if it is not right . Can you please point to the right references. As much as it is important to say it not right , it would be very helpful to say what is right. Thanks for pointing out. Please let me know how can I implement service caching and some implementation references.
We don't know what you're trying to do, so it is hard to recommend anything.
The only thing you posted was that you tried implementing something from a blog somewhere that is untried, nonstandard and unnecessary.
So if you could start over and explain what you needed, we'd be happy to offer the right path to accomplish what you need...
The only thing you posted was that you tried implementing something from a blog somewhere that is untried, nonstandard and unnecessary.
So if you could start over and explain what you needed, we'd be happy to offer the right path to accomplish what you need...
I searched a lot for info and didnt find any sample so had to try this link.
Thank you . Now that I know I will get exact , right and needed solution. I am happy to explain.
We have MVC portlets which are communicating to OSGI service modules.
OSGI service modules make REST API calls to get data from webservices.
Some data which doesn't change frequently needs to be cached at OSGI services.
For ex: product code and description, model code and description. Sometimes it can be a bean ( simple or complex) which can be serialized.
I havent done caching before so I wanted some sample or link where I can find the right info.
Thanks in advance.
Thank you . Now that I know I will get exact , right and needed solution. I am happy to explain.
We have MVC portlets which are communicating to OSGI service modules.
OSGI service modules make REST API calls to get data from webservices.
Some data which doesn't change frequently needs to be cached at OSGI services.
For ex: product code and description, model code and description. Sometimes it can be a bean ( simple or complex) which can be serialized.
I havent done caching before so I wanted some sample or link where I can find the right info.
Thanks in advance.
So I would actually recommend leveraging SingleVMPool for this. It handles storing data in ehcache for you, so you get cache sizing, expiration, etc but you don't have to worry about doing manual cache management yourself.
I found this reference that can help you leverage it: http://wwwilpower.blogspot.com/2015/01/adding-custom-cache-to-liferay.html
I would not suggest using MultiVMPool for this. MultiVMPool broadcasts across the cluster, so nodes could be loaded down with data they don't need just because another node has fetched the info. Let each node use its own cache so it holds data it needs to service requests that it gets.
As far as implementation goes, it would be a simple matter of asking SimpleVMPool to return your cached value; if you get one, return it, if not it is a cache miss and you should hit your web service. Remember to put the web service result into SimpleVMPool before returning it so it is in the cache for the next value.
This logic would go right in where you are currently just invoking the web service directly now, so it is easy to fit in to what you already have.
I found this reference that can help you leverage it: http://wwwilpower.blogspot.com/2015/01/adding-custom-cache-to-liferay.html
I would not suggest using MultiVMPool for this. MultiVMPool broadcasts across the cluster, so nodes could be loaded down with data they don't need just because another node has fetched the info. Let each node use its own cache so it holds data it needs to service requests that it gets.
As far as implementation goes, it would be a simple matter of asking SimpleVMPool to return your cached value; if you get one, return it, if not it is a cache miss and you should hit your web service. Remember to put the web service result into SimpleVMPool before returning it so it is in the cache for the next value.
This logic would go right in where you are currently just invoking the web service directly now, so it is easy to fit in to what you already have.
Thanks a ton for your reply. I appreciate it . I can proceed in the right direction now.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™