Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-3675 Introduce caching to getSearchLocales() #1863

Merged
merged 1 commit into from
Nov 18, 2016

Conversation

pgutkowski
Copy link
Contributor

@pgutkowski pgutkowski commented Oct 31, 2016

TRUNK-3675

Description

This PR introduces Spring's caching functionality to OpenMRS. As proof of concept, results of getSearchLocales are cached.

We couldn't use annotation driven cache configuration, because we are still using old TransactionProxyFactoryBean to handle transactions, so CacheInterceptor is added to preInterceptors of TransactionProxyFactoryBean, to handle cache. More info can be found in Spring documentation.

In long run, we probably will want to replace SimpleCacheManager with EhCacheManager, but I couldn't properly inject it, I guess HIbernate's second level cache ehCache is colliding with it, because when it was disabled, I was able to register my API EhCacheManager

I managed to set up ehcache manager for API instead of SimpleCacheManager. Previously it didn't work because Hibernate used singleton factory, Right now we will have 2 caches - hibernateCache and apiCache. I'm still working on making cache configuration extendable by modules.

Related Issue

see https://issues.openmrs.org/browse/TRUNK-3675

Checklist:

  • My pull request only contains one single commit.
  • My pull request is based on the latest master branch
    git pull --rebase upstream master.
  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.
  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@mention-bot
Copy link

@PawelGutkowski, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bmamlin, @suniala and @jdegraft to be potential reviewers.

@pgutkowski pgutkowski force-pushed the TRUNK-3675 branch 2 times, most recently from be845f9 to 2db9b51 Compare October 31, 2016 12:29
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 55.633% when pulling 2db9b51 on PawelGutkowski:TRUNK-3675 into b196a68 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 55.654% when pulling 2db9b51 on PawelGutkowski:TRUNK-3675 into b196a68 on openmrs:master.

@@ -345,6 +358,7 @@
* @should include currently selected full locale and langugage
* @should include users proficient locales
* @should exclude not allowed locales
* @should cache results for an user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here 'an user' -> 'a user'

* @verifies cache results for an user
*/
@Test
public void getSearchLocales_shouldCacheResultsForAnUser() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForAnUser -> ForAUser

@pgutkowski pgutkowski force-pushed the TRUNK-3675 branch 2 times, most recently from 2b3aae8 to 501d622 Compare November 11, 2016 10:00
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 55.727% when pulling 501d622 on PawelGutkowski:TRUNK-3675 into 17c22ce on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 55.708% when pulling 501d622 on PawelGutkowski:TRUNK-3675 into 17c22ce on openmrs:master.

diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, when you setup ehcache this way you don't have to declare caches for each name... If they are not declared the defaults are used... Am I wrong here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm right modules can use caches based on the default cache config without having to explicitly declare names here. Sys admins seeing too much memory consumption could edit the file and disable some of caches by overriding their settings. We could provide more granular adjustments of config for module developers in a separate issue if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, default caches are created.

We could provide more granular adjustments of config for module developers in a separate issue if needed.

I think it is a good idea

@@ -9,7 +9,7 @@
graphic logo is a trademark of OpenMRS Inc.

-->
<ehcache>
<ehcache name="hibernateCache">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you tell Hibernate to use "hibernateCache"? Or is it the default name it looks for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, ehcache.xml is default filename. In fact, we can rename it to hibernate-ehcache.xml by adding net.sf.ehcache.configurationResourceName parameter to hiebrnate.cfg, if you think we need to be more clear about it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wondered why you added name="hibernateCache" here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it for debugging purposes, because default name is "DEFAULT". At first I had problem with those multiple CacheManager instances, so having explicit names was handy, and I think it can be useful in future if anybody will have to do something with those.

diskPersistent="false" diskExpiryThreadIntervalSeconds="45"/>

<cache name="userSearchLocales"
maxElementsInMemory="5000"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this too high?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably is, I've copied this configuration from commit which was reverted a couple months ago, I guess we can limit it to 500?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 55.727% when pulling 898bf3b on PawelGutkowski:TRUNK-3675 into e037b58 on openmrs:master.

@rkorytkowski rkorytkowski merged commit 1e84458 into openmrs:master Nov 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants