Orientdb 简明教程

OrientDB - Caching

Caching 是一个概念,它将创建一个数据库表结构的副本,为用户应用程序提供一个舒适的环境。OrientDB 具有多个不同级别的缓存机制。

Caching is a concept that will create a copy of the database table structure providing a comfortable environment for the user applications. OrientDB has several caching mechanisms at different levels.

以下插图给出了有关缓存是什么的想法。

The following illustration gives an idea about what caching is.

caching mechanisms

在上述插图中, DB1DB2DB3 是应用程序中使用的三个不同的数据库实例。

In the above illustration DB1, DB2, DB3 are the three different database instances used in an application.

Level-1 缓存是一个 Local cache ,它存储特定会话已知的所有实体。如果此会话中有三个事务,它将保留所有三个事务使用的所有实体。当您关闭会话或执行“clear”方法时,会清除此缓存。它减轻了应用程序与数据库之间的 I/O 操作负担,进而提高了性能。

Level-1 cache is a Local cache which stores all the entities known by a specific session. If you have three transactions in this session, it will hold all entities used by all three transactions. This cache gets cleared when you close the session or when you perform the "clear" method. It reduces the burden of the I/O operations between the application and the database and in turn increases the performance.

Level-2 缓存是一个 Real cache ,它通过使用第三方提供程序来工作。您可以完全控制缓存的内容,即您将能够指定应删除哪些条目,应将哪些条目存储更长时间,依此类推。它是多个线程之间的完全共享缓存。

Level-2 cache is a Real cache that works by using third party provider. You can have full control over the contents of the cache, i.e. you will be able to specify which entries should be removed, which ones should be stored longer and so on. It is a full shared cache among multiple threads.

Storage model 就是存储设备,即磁盘、内存或远程服务器。

Storage model is nothing but storage device that is disk, memory, or remote server.

How Cache Works in OrientDB?

OrientDB 缓存可在不同环境中提供不同的方法。缓存主要用于更快的数据库事务,减少事务的处理时间并提高性能。以下流程图显示了缓存如何在本地模式和客户端-服务器模式下工作。

OrientDB caching provides different methodologies in different environments. Caching is mainly used for faster database transactions, reducing the processing time of a transaction and increasing the performance. The following flow diagrams show how caching works in local mode and client-server mode.

Local Mode (Embedded Database)

以下流程图告诉您记录如何在本地模式(即当您的数据库服务器位于本地主机时)在存储和使用的应用程序之间进行。

The following flow diagram tells you how the record is in-between storage and used application in the local mode i.e., when your database server is in your localhost.

embedded database

当客户端应用程序请求记录时,OrientDB 检查以下内容:

When the client application asks for a record OrientDB checks for the following −

  1. If a transaction has begun, then it searches inside the transaction for changed records and returns it if found.

  2. If the local cache is enabled and contains the requested record, then returns it.

  3. If at this point the record is not in cache, then asks for it to the Storage (disk, memory).

Client Server Mode (Remote Database)

下述流程图说明了记录位于存储与客户端-服务器模式中使用的应用程序之间的过程,即位于远程位置的数据库服务器。

The following flow diagram tells you how the record is in-between storage and used application in the client-server mode i.e., when your database server is in remote location.

remote database

当客户端应用程序请求记录时,OrientDB 检查以下信息:

When the client application asks for a record, OrientDB checks for the following −

  1. If a transaction has begun, then it searches inside the transaction for changed records and returns it if found.

  2. If the local cache is enabled and contains the requested record, then returns it.

  3. At this point, if the record is not in cache, then asks for it to the Server through a TCP/IP call.

  4. In the server, if the local cache is enabled and contains the requested record, then returns it.

  5. At this point, still the record is not cached in the server, then asks for it to the Storage (disk, memory).