Database cache and database cache mechanism

Source: Internet
Author: User
Tags object serialization

Database cache and database cache mechanism
Refresh database cache
Exec dbms_stats.gather_table_stats ('pro', 'tbl _ request', cascade => true );
Alter system flush shared_pool;
What is the database cache mechanism? That is, how does the cache function the database? The more detailed, the better.

First, you need to understand what is the database cache mechanism (it is best to find a book)
It has been a long time. I forgot. However, you can give a similar example to help you understand it.
If you still need to look at the specific example code, you 'd better find the relevant books on the database to explain in more detail. on the Internet, it is rare to explain in detail if you are at school. Ask a teacher, or you can go to some database forums to find information.

The database cache mechanism caches data between applications and physical data sources to reduce the frequency of applications accessing physical data sources and improve the running performance of applications. Data in the cache is the replication of data in the physical data source. during runtime, the application reads and writes data from the cache. Data in the cache and the physical data source will be synchronized at a specific time or event.
The cache medium is generally memory, so the read/write speed is very fast. However, if the volume of data stored in the cache is very large, the hard disk will also be used as the cache medium. The implementation of cache should not only consider the storage media, but also take into account the management of concurrent access to the cache and the lifecycle of the cache data.

Another example is:

Static website content is stored directly on the server by some simple static webpages, which can easily reach amazing access volumes. However, dynamic websites are dynamic. That is to say, each time a user accesses a page, the server needs to execute database queries, start templates, execute business logic, and finally generate a Web page that you see, all of these are dynamically and instantly generated. From the processor resource point of view, this is relatively expensive.
For most network applications, overload is not a major problem. Because most network applications are not mongoingtonpost.com or Slashdot; they are usually very small and simple, or medium-sized sites, with only a small amount of traffic. However, it is necessary for medium-to large-scale traffic sites to solve the overload problem as much as possible. This requires caching.
The purpose of caching is to avoid repeated computation, especially for time-consuming and resource-consuming computation.

What are the cache technologies of Hibernate?

Cache is a temporary container of database data in the memory. It contains temporary copies of database table data in the memory and is located between the database and applications, it is used to reduce the frequency of Physical Data Source Access by applications and improve the running performance of applications.

Hibernate Cache Mechanism

1.1 cache range of The Persistence Layer

In the persistence layer design, several data cache policies at different levels are often required. The criteria for dividing these layers vary according to different situations. Generally, the data cache of ORM should include the following layers:

Transaction Layer Cache)

The cache can only be accessed by the current transaction. The cache lifecycle depends on the transaction lifecycle. When the transaction ends, the cache ends the lifecycle. In this range, the cache medium is memory. Transactions can be database transactions or application transactions. Each transaction has its own cache. Data in the cache is usually in the form of correlated objects.

Application/Process Layer Cache)

The cache is shared by all transactions in the process. These transactions may access the cache concurrently, so you must adopt the necessary transaction isolation mechanism for the cache. The cache lifecycle depends on the process lifecycle. When a process ends, the cache ends. The cache within the process scope may store a large amount of data, so the storage media can be memory or hard disk. The data in the cache can be in the form of correlated objects or loose data of objects. The object's loose data format is somewhat similar to the object's serialized data, but the object's loose decomposition algorithm requires faster than the object serialization algorithm.

Cluster Layer Cache)

In the cluster environment, the cache is shared by the processes of one or more machines. Data in the cache is replicated to every process node in the cluster environment. Data Consistency in the cache is ensured through remote communication between processes. Data in the cache is usually in the form of loose data of objects. For most applications, you should carefully consider whether to use the cluster-range cache, because the access speed may not necessarily be much faster than the direct access to database data.

The persistence layer provides caching at multiple levels. If no data is found in the transaction-level cache, You can query it in the process-level or cluster-level cache. If no data is found, you can only query it in the database. Transaction-level cache is the first level of the persistence layer, which is usually required. Process-level or cluster-level cache is the second level of the persistence layer, which is usually optional.

1.2 hibernate Cache Mechanism

Hibernate provides two types of cache. The first type is Session cache, which is also called a level-1 cache. Because the lifecycle of a Session Object usually corresponds to a database transaction or an application transaction, its cache is the cache of the transaction scope. The first-level cache is required and cannot be detached. In the first cache, each instance of the persistence class has a unique OID.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.