Git Product home page Git Product logo

hibernate-mysql-cache's Introduction

hibernate-mysql-cache

A Simple Hibernate MySQL example explaining different Caching mechanisms offered in Hibernate

Hibernate Caching

First level Cache (Session Object) enabled by default… available only for the session… retrieved from DB and store in first level cache, next db hit not done… but loaded entity can be removed by evict().. After that again call to db is made... To clear cache entirely use clear()

Second level Cache(Session Factory)… enable it explicitly… available to entire application… first checks in first level cache… if not available in first level cache then looks into second level cache… if cache entity present in second level cache… it will store it into first level cache and then loads it..

This way next time app will get the info from first level cache itself… if not present in both caches, db query is executed and data is stored in both caches before returning…

Caching Strategies offered -> READ_ONLY, READ_WRITE, NON RESTRICTED READ WRITE, TRANSACTIONAL

If user updates db directly then cache will not reflect it… it's better to use the session api so that the cache is always updated

HibernateUtil.getSessionFactory().getStatistics().getEntityFetchCount() - gets the first level cache count

HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheHitCount() - gets the second level cache count

Various Second Level Caches available are,

EhCache,

OSCache,

Jboss related Cache

Query Cache - If you use Query to fetch data, you can cache those results also using query cache. In order to achieve this Query cache has to be enabled in hibernate configuration file and the query.cacheable should be set to true in java side also

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.