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

Cache eviction problem #9

Closed
larshelge opened this issue May 12, 2017 · 3 comments
Closed

Cache eviction problem #9

larshelge opened this issue May 12, 2017 · 3 comments

Comments

@larshelge
Copy link
Contributor

larshelge commented May 12, 2017

It appears that cache eviction is not working properly. Versions:

Hibernate: 5.1.5.Final
Hibernate-l2-memcached: 5.1.5.0

In our app we are relying on clearing / evicting the second level cache. The code looks like this:

sessionFactory.getCache().evictEntityRegions();
sessionFactory.getCache().evictCollectionRegions();
sessionFactory.getCache().evictDefaultQueryRegion();
sessionFactory.getCache().evictQueryRegions();

This works when ehcache is used as cache provider. However, this code appears to have no effect when using hibernate-l2-memcached as cache provider.

Evidence 1

  • We load a web page twice, and verify from database logs (Postgres) that no queries hit the database after first page load.
  • Clear second level cache using the function described above.
  • Load the same web page again. This time, still no queries hit the database. Verified that this works with ehcache.

Evidence 2

  • We load a web page.
  • Inspect memcached server instance running on localhost by listing all keys and values (we get 5629 entries).
  • Clear second level cache using the function described above.
  • Inspect memcached server instance again. This time we still get the exact same number of cache entries.

Conclusion

It appears that hibernate-l2-memcached is not implementing the programmatic cache eviction contract properly based on these observations.

@mihaicostin
Copy link
Owner

There is already something in place for that, but there's a missing link with the configuration.
I'll start looking into this soon and fix it.

@mihaicostin
Copy link
Owner

It should work now with version 5.1.5.1, as long as the property hibernate.memcached.clearSupported is set to true.

BTW, region eviction works for memcached by using an increment (similar to what's described here https://github.com/memcached/memcached/wiki/ProgrammingTricks#deleting-by-namespace ): a "clearIndex" value that is always included in the cache-key generation. Because of this, using clear a lot might be quite expensive.

This also means that in your "Evidence 2" scenario, after you clear the second level cache the number of keys won't decrease (only after the old clearIndex will expire).

The "Evidence 1" scenario, however, should be fixed.
Let me know if you run into any other issue and if I've got the time, I'm happy to help.

@larshelge
Copy link
Contributor Author

Excellent, thanks a lot for the quick fix. Much appreciated! I can confirm it works now. Closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants