Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ORM and distributed caching


Published on

Slides from meet up in Moscow, 2012 May 17

Published in: Technology
  • Be the first to comment

  • Be the first to like this

ORM and distributed caching

  1. 1. ORM and Distributed Caching Alexey Ragozin May 2012
  2. 2. ORM cache hierarchy Session Level 1 Query cache Entry cache Level 2 Database
  3. 3. ORM cache hierarchy Session POJO Level 1 Query cache Entry cache Sets of PK Entities Level 2 Database
  4. 4. Second level cacheQuery cache Query -> Result set (list of entry references)Entity cache PK (entry reference) -> Entity dataMakes query cache usefulHelps with “N+1 select” problemActively used for lazy loading of entities
  5. 5. Consistency problemStale data in entity cache = big problemSingle process application Locking, to prevent concurrent updates Write through – modify DB and cache togetherDistributed application1. JTA transaction manager (add cache to Tx)2. Use distributed locks for concurrency control
  6. 6. Solving Query ProblemCaching queries Exact query match may be infrequent Invalidation is messyWhy not execute quires in cache? Execute query in entity cache No invalidation problem Coherence, GemFire, Hazelcast has index support
  7. 7. Queries in Entity CachePro DB is not involved in query processing Fallback to DB for complex quries Still using old good (or bad) JPQLCons ALL entities should be loaded in cache Only simple selects, no join queries are supported  though link traversing works as usual
  8. 8. What is Next? Coherence cache is durable Why update DB synchronously?Write behind for ORMPRO reducing transaction execution time removing DB from critical pathCON Coherence does not honor transaction boundaries DB is out of sync, no way for execution complex JPQL
  9. 9. Few More Interesting Stuff Works with TopLink Grid Real transaction support Durability via distributed disk logHIBERNATE OGM JPQL for NoSQL (data grid included) Lucene (Hibernate Search) support
  10. 10. Thank you Alexey Ragozin