First Level Cache - bobocode-breskul/bibernate GitHub Wiki

First Level Cache

Overview

The First Level Cache is a fundamental feature in Bibernate that stores entities retrieved during the lifecycle of a session. It acts as a buffer, ensuring that subsequent requests for the same entity within the same session are served from the cache, reducing database access.

How It Works

  • Entities retrieved in a session are cached in the First Level Cache.
  • If the same entity is requested again in the same session, it is fetched from the cache instead of the database.
  • The cache is tied to the session and is cleared when the session is closed or explicitly cleared.

Benefits

  • Performance Improvement: Significantly reduces the number of database queries, enhancing performance.
  • Consistency: Ensures consistency within a session by serving entities from the cache.
  • Reduced Latency: Decreases database access latency, improving the application's responsiveness.