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
How to extend server side caching scope across sessions?
This question concerns how to extend the benefits of server side caching across sessions. We are new adopters of Liferay so still learning some of the basics and are in the process of developing our first web site – our Liferay settings at present are largely ‘out of the box’ but we are now going through a tuning phase and adopting best practice.
We are noticing significant performance improvements when hitting a web page for the 2nd time within the same user web session eg the home page reduces from 10-15 seconds down to 1-2 secs. This can easily be explained by greatly reduced server activity the 2nd time (eg when initially creating the html for the home page 300+ SQL database requests will be issued but this reduces to 16 for subsequent hits on the home page from the same session). Presumably this is due, at least in part, to server side caching.
However new sessions will still see a 10-15 second response time the first time they hit the home page – the benefit of the cache does not seem to extend beyond a single session. Reading around I understand the difference between L1 and L2 cache which seems to be relevant here but cant find documentation on how to set this optimally for a production web site. Can somebody help to point me in the right direction or even suggest best practice settings for the cache?
I will raise the follow on question in this same post because it is obviously closely related. The next challenge will be how to keep the cache ‘warm’ while still allowing content to be dynamically updated (although this will be rare in a prod environment). Hopefully answers to the above will include this. Our web tier is load balanced across 2 computer centres but we are not planning a distributed caching solution at this stage so this aspect may present its own ‘challenges’
Any thoughts or information would be greatly appreciated. Thanks
We are noticing significant performance improvements when hitting a web page for the 2nd time within the same user web session eg the home page reduces from 10-15 seconds down to 1-2 secs. This can easily be explained by greatly reduced server activity the 2nd time (eg when initially creating the html for the home page 300+ SQL database requests will be issued but this reduces to 16 for subsequent hits on the home page from the same session). Presumably this is due, at least in part, to server side caching.
However new sessions will still see a 10-15 second response time the first time they hit the home page – the benefit of the cache does not seem to extend beyond a single session. Reading around I understand the difference between L1 and L2 cache which seems to be relevant here but cant find documentation on how to set this optimally for a production web site. Can somebody help to point me in the right direction or even suggest best practice settings for the cache?
I will raise the follow on question in this same post because it is obviously closely related. The next challenge will be how to keep the cache ‘warm’ while still allowing content to be dynamically updated (although this will be rare in a prod environment). Hopefully answers to the above will include this. Our web tier is load balanced across 2 computer centres but we are not planning a distributed caching solution at this stage so this aspect may present its own ‘challenges’
Any thoughts or information would be greatly appreciated. Thanks
Trevor Harris:
However new sessions will still see a 10-15 second response time the first time they hit the home page – the benefit of the cache does not seem to extend beyond a single session.
Untrue. When I start a new session after you, I have a completely different set of queries to execute because my 'where clause' values are going to be different. The cache stores the results of a complete query, but if the query had not been performed before, there's nothing in the cache.
Our web tier is load balanced across 2 computer centres but we are not planning a distributed caching solution at this stage so this aspect may present its own ‘challenges’![]()
Challenges? This is doomed to failure. Not for caching as much as for indexing. Liferay uses local indexing to improve performance and reduce DB impact, but when you are not completely clustered, you'll see all kinds of weird things where images are missing, docs are missing, ... From experience I've learned if you're in a clustered environment, do a 100% cluster or don't do it at all.
Thanks for the reply David – I am aware at this stage that we have a lot to learn about Liferay and certainly understand the complications that can come with caching in a multi-server non-clustered environment.
Re the first point though, about a completely different set of queries being required because of different where clauses, I am struggling to understand why that would be the case here. This is our first simple use case of a public facing ‘brochure ware’ web site so I don’t see why session #2 should have significantly different database queries to session #1 (apart from browser related possibly if that is taken into account?). Could you explain that to me at a high level? Later use cases will involve authenticated users and then I can understand the problem but at the moment this is all shared, static information. Are we missing something basic here in how our objects are defined – do they need to be defined as application scope in order for the cache to be re-used across sessions?
Re the first point though, about a completely different set of queries being required because of different where clauses, I am struggling to understand why that would be the case here. This is our first simple use case of a public facing ‘brochure ware’ web site so I don’t see why session #2 should have significantly different database queries to session #1 (apart from browser related possibly if that is taken into account?). Could you explain that to me at a high level? Later use cases will involve authenticated users and then I can understand the problem but at the moment this is all shared, static information. Are we missing something basic here in how our objects are defined – do they need to be defined as application scope in order for the cache to be re-used across sessions?
Well, I may have mistook when you said "user web sessions" as a session for a user once logged in, in which case the cached values for a previous user would not be valid.
For the guest-like situation, the queries should not have changed and would indicate perhaps either the cache expired or the cache was not large enough to hold all of the entities retrieved the first go round.
For the guest-like situation, the queries should not have changed and would indicate perhaps either the cache expired or the cache was not large enough to hold all of the entities retrieved the first go round.