WO2018040167A1 - 数据缓存方法及装置 - Google Patents

数据缓存方法及装置 Download PDF

Info

Publication number
WO2018040167A1
WO2018040167A1 PCT/CN2016/100563 CN2016100563W WO2018040167A1 WO 2018040167 A1 WO2018040167 A1 WO 2018040167A1 CN 2016100563 W CN2016100563 W CN 2016100563W WO 2018040167 A1 WO2018040167 A1 WO 2018040167A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
data
database
deleted
operation instruction
Prior art date
Application number
PCT/CN2016/100563
Other languages
English (en)
French (fr)
Inventor
赖旭东
Original Assignee
广州市乐商软件科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 广州市乐商软件科技有限公司 filed Critical 广州市乐商软件科技有限公司
Publication of WO2018040167A1 publication Critical patent/WO2018040167A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Definitions

  • the present invention relates to the field of computer information processing technologies, and in particular, to a data caching method and apparatus.
  • the cache is between the application and the physical data source. Its purpose is to reduce the frequency of application access to the physical data source and improve the running performance of the application. Since the cached medium is memory, its read and write speed is fast.
  • the traditional data caching method needs to set the life cycle of the cache in the application to achieve the purpose of maintaining the cached data, and has the problems of high maintenance cost and difficulty in application development.
  • a data caching method comprising:
  • a data cache device comprising:
  • An instruction receiving module configured to receive a database operation instruction
  • condition determining module configured to determine, according to the database operation instruction, whether a cache data deletion condition is satisfied
  • the cache deletion module is configured to: when the determination result of the condition determination module is satisfied, delete the cache data to be deleted determined in the cache according to the database operation instruction.
  • the data caching method and device after receiving the database operation instruction, determining whether the cache data deletion condition is satisfied based on the database operation instruction; if satisfied, deleting the cache data to be deleted determined in the cache according to the database operation instruction . Therefore, the cache data to be deleted can be deleted according to the database operation instruction, and the automatic maintenance of the cache data can be realized without setting the life cycle of the cache in the application, thereby reducing the maintenance cost and reducing the development difficulty of the application.
  • FIG. 1 is a flow chart of a data caching method of an embodiment
  • FIG. 2 is a specific flowchart of a step of the data caching method of FIG. 1;
  • FIG. 3 is a specific flowchart of another step of the data caching method of FIG. 1;
  • FIG. 4 is a detailed flow chart of a manner of one step of a data caching method of a specific embodiment
  • FIG. 5 is a detailed flow chart of another manner of one step of the data caching method of a specific embodiment
  • FIG. 6 is a flowchart of a data caching method of another embodiment
  • FIG. 7 is a schematic diagram of a cache management interface of an application
  • Figure 8 is a diagram showing the relationship between an application and a data cache device
  • Figure 9 is a block diagram of a data buffering apparatus of an embodiment.
  • a data caching method includes:
  • the data caching method first receives the database operation instruction.
  • the database operation instructions include operation actions and data identification.
  • the operation action is an operation action that the database operation instruction needs to complete;
  • the data identifier is an identifier of the operation object of the database operation instruction, and preferably, the identifier is a unique identifier of the operation object of the database operation instruction. It can be understood that the operation object of the database operation instruction is the data in the database.
  • Different database operation instructions can be distinguished according to the operation actions of the database operation instruction, and then according to different types of database operation instructions, it is determined whether the corresponding type of database operation instruction satisfies the cache data deletion condition.
  • the cached data to be deleted determined in the cache according to the database operation instruction is deleted.
  • the cached data to be deleted may be the cached data corresponding to the data identifier in the cache, or may be the cached data that should be replaced according to the preset policy when the cache capacity reaches the maximum value.
  • the preset strategy may be a first in first out algorithm using a first in first out principle, or a LRU (Least Recently Used) algorithm using the least recently used principle, and of course other algorithms.
  • the preset policy is an LRU algorithm.
  • the data caching method after receiving the database operation instruction, determining whether the cache data deletion condition is satisfied based on the database operation instruction; if satisfied, deleting the cache, according to the The cached data to be deleted determined by the database operation instruction. Therefore, the cache data to be deleted can be deleted according to the database operation instruction, and the automatic maintenance of the cache data can be realized without setting the life cycle of the cache in the application, thereby reducing the maintenance cost and reducing the development difficulty of the application.
  • the step of determining whether the cache data deletion condition is satisfied based on the database operation instruction includes:
  • S231 Determine an action type of the operation action of the database operation instruction, and include at least one of the following two items; specifically, the action type includes an update action and a read action.
  • S234 If the action type of the operation action is a read action, determine whether the size of the cache data in the cache is greater than a cache capacity of the cache if the data to be operated is added, and if yes, determine that the cached data is satisfied. The condition is deleted, otherwise it is determined that the cache data deletion condition is not satisfied.
  • the cache data deletion condition is satisfied.
  • the cached data to be deleted determined in the cache according to the database operation instruction is deleted.
  • the step of deleting cache data to be deleted determined according to the database operation instruction in the deletion cache includes:
  • the cached data to be deleted in the cache is determined according to the database operation instruction.
  • the cached data to be deleted in the cache is deleted.
  • the method further includes:
  • the step of deleting the cached data to be deleted in the cache further includes:
  • S355 Perform an operation of the database data corresponding to the data identifier stored in the database according to the data identifier and the update action.
  • the database in the database needs to be first used.
  • the data is returned and stored in the cache to form cached data; this cached data is then returned to the application.
  • the cache data to be deleted in the cache is deleted by using a cache delete transaction; and the database corresponding to the data identifier stored in the database is completed according to the data identifier and the update action by using a database update transaction. The operation of the data.
  • a cache delete transaction is a set of instructions that will delete the cache data to be deleted in the cache.
  • the instructions in the set are executed, either the instructions in the set are all executed successfully, or the instructions in the set are not executed at all. Or roll back after execution. Avoid data errors caused by executing a part.
  • the database update transaction is rolled back, and after the database update transaction is rolled back, the cache deletion transaction is rolled back. In this way, the data hit rate is improved while maintaining the consistency of the data in the database and the cache.
  • the cached transaction is strong transaction support.
  • the cached transaction is consistent with the database's transaction.
  • the transaction of the database is to be started, and the corresponding cached transaction is first opened; the database
  • the transaction is successfully submitted, and the corresponding cached transaction is also successfully submitted; if the database transaction needs to be rolled back, the corresponding cached transaction is also rolled back.
  • the operation action of the database operation instruction is an example of an update action, wherein the update action includes deletion and modification.
  • the cache can be implemented through a cache pool. Referring to FIG. 4, if the cache deletion transaction is normal, the specific process of deleting the cached data to be deleted determined according to the database operation instruction in the cache includes:
  • S403 Clear the cached data; that is, delete the cached data to be deleted in the cache.
  • S404 Modify or delete the database data; that is, complete the operation of the database data corresponding to the data identifier stored in the database according to the data identifier and the update action.
  • the specific process of deleting the cached data to be deleted determined according to the database operation instruction in the cache includes:
  • S503 Clear the cached data; that is, delete the cached data to be deleted in the cache.
  • S504 Modify or delete the database data; that is, complete the operation of the database data corresponding to the data identifier stored in the database according to the data identifier and the update action.
  • the method further includes:
  • S670 Receive a buffer clear instruction; the cache clear instruction includes a data identifier of the data to be operated.
  • S690 Delete, according to the cache clearing instruction, data to be operated corresponding to the data identifier in the cache.
  • the cache clear instruction can be received through the cache management interface.
  • An example of a cache management interface as shown in Figure 7.
  • the cache is inconsistent with the data of the database.
  • the cache can be cleared by clearing the cache operation through the application's cache management interface.
  • you can also monitor the status and usage of the cache, such as the total capacity of the cache (that is, the cache capacity), the current capacity (that is, the used capacity), the number of requests, the number of hits, the hit rate, the number of rewrites, The number of erasures, etc.
  • the method before the step of receiving a database operation instruction, the method further includes:
  • S601 Receive a buffer capacity setting instruction, where the cache capacity setting instruction includes a cache identifier and a target capacity.
  • S603 Set a cache capacity of the cache corresponding to the cache identifier to the target capacity according to the cache identifier and the target capacity.
  • the data of the database can be a million or tens of millions of data. If the data is loaded into the cache, the system memory cannot be supported at all. Therefore, you need to set a maximum capacity value for the cache, which is the cache capacity. At the same time, based on the cache capacity, combined with the preset strategy, the self-management mechanism of the cache capacity can be realized.
  • each time the cached data in the cache is read the cached data is re-stored to the end of the cache.
  • the database data is stored at the end of the cache to form the cached data.
  • the cache is used to store key-value pairs ([key, value]).
  • a slow Save a table similar to a relational database.
  • a row of data in a table of a database is a database data.
  • the data identifier of the database data is used as a key (key) of the cache, and the data corresponding to the data identifier is stored as a data value (value) in the cache to form cache data. That is to say, the cached data stored in the cache is derived from the database data.
  • a keyword such as a data identifier, remove a cache object (similar to the database delete a data operation);
  • a collection of caches can be called a cache pool. It is similar to the library of relational databases.
  • the cache pool stores the cache.
  • a cache pool with the following features:
  • the maximum capacity can be set for the cache pool. Understandably, it is also possible to set the cache capacity for each cache only.
  • the present invention also provides a data buffering device of an embodiment corresponding to the above data caching method.
  • the data caching device can be used as a sub-module of an application program, and the application program is called. As shown in FIG. 8, the application and the data cache device will be in the same JVM (Java Virtual Machine).
  • JVM Java Virtual Machine
  • a data cache device of an embodiment corresponding to the data caching method includes:
  • the instruction receiving module 910 is configured to receive a database operation instruction
  • the condition determining module 930 is configured to determine, according to the database operation instruction, whether a cache data deletion condition is satisfied;
  • the cache deletion module 950 is configured to: when the determination result of the condition determination module 930 is satisfied, delete the cached data to be deleted determined in the cache according to the database operation instruction.
  • the data cache device determines, according to the database operation instruction, whether the cache data deletion condition is satisfied after receiving the database operation instruction; if yes, deleting the cache data to be deleted determined in the cache according to the database operation instruction. Therefore, the cache data to be deleted can be deleted according to the database operation instruction, and the automatic maintenance of the cache data can be realized without setting the life cycle of the cache in the application, thereby reducing the maintenance cost and reducing the development difficulty of the application.
  • the database operation instruction includes a data identifier and an operation action of the data to be operated;
  • the condition determination module 930 includes:
  • An action type determining unit configured to determine an action type of the operation action of the database operation instruction; and includes at least one of the following two items:
  • a first determining unit configured to determine that the cache data deletion condition is satisfied if the action type of the operation action is an update action, otherwise determine that the cache data deletion condition is not satisfied;
  • a second determining unit configured to determine if the action type of the operation action is a read action Entering the to-be-operated data, whether the size of the cached data in the cache is greater than the buffered cache capacity, and if so, determining that the cached data deletion condition is satisfied, otherwise determining that the cached data deletion condition is not satisfied.
  • the cache deletion module 950 includes:
  • a cache data determining unit configured to: when the operation action of the database operation instruction is an update action, determine cache data to be deleted in the cache according to the data identifier; or/and, when the operation action of the database operation instruction is read When the action is taken, the preset cache is used to determine the cached data to be deleted in the cache;
  • the cache data deleting unit is configured to delete the cached data to be deleted in the cache.
  • the database deletion module 960 is configured to determine, according to the data identifier and the update action, the cache data to be deleted in the cache, and the cache data deletion unit deletes the cache data to be deleted in the cache, according to the The data identification and the update action complete the operation of the database data corresponding to the data identifier stored in the database.
  • the cache deletion module 950 deletes the cache data to be deleted in the cache by using a cache deletion transaction; the database deletion module 960 implements the storage in the database according to the data identifier and the update action by using a database update transaction.
  • the data identifies the operation of the corresponding database data.
  • the database deletion module 960 rolls back the database update transaction, and after the database deletion module 960 rolls back the database update transaction, the cache deletes Module 950 rolls back the cache delete transaction.
  • the method further includes:
  • the clear instruction receiving module 970 is configured to receive a cache clear instruction; the cache clear instruction includes a data identifier of the data to be operated;
  • the clearing instruction execution module 990 is configured to delete the to-be-operated data corresponding to the data identifier in the cache according to the cache clearing instruction.
  • the method further includes:
  • the setting instruction receiving module 901 is configured to receive a cache capacity setting instruction, where the cache capacity setting instruction includes a cache identifier and a target capacity;
  • the cache capacity setting module 903 is configured to set a cache capacity of the cache corresponding to the cache identifier to the target capacity according to the cache identifier and the target capacity.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种数据缓存方法及装置,包括:接收数据库操作指令(S110);基于所述数据库操作指令判断是否满足缓存数据删除条件(S130);若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据(S150)。由于在接收到数据库操作指令后,基于所述数据库操作指令判断是否满足缓存数据删除条件;若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。因此,可以根据数据库操作指令,删除待删除的缓存数据,实现缓存数据的自动维护,而无需在应用程序中设置缓存的生命周期,从而,可以降低维护成本,降低应用程序的开发难度。

Description

数据缓存方法及装置 技术领域
本发明涉及计算机信息处理技术领域,尤其涉及一种数据缓存方法及装置。
背景技术
较早时期的数据都是保存在物理磁盘中,但物理磁盘的读写速度慢,无法满足于高并发的读写操作,因此,缓存应运而生。缓存介于应用程序和物理数据源之间,其作用是降低应用程序对物理数据源访问的频次,提高应用程序的运行性能。由于缓存的介质是内存,其读写速度快。
由于缓存资源有限,需要对缓存数据进行维护。传统的数据缓存方法需要在应用程序中设置缓存的生命周期,以实现对缓存数据进行维护的目的,存在维护成本高、应用程序开发难度大的问题。
发明内容
基于此,有必要针对传统的数据缓存方法维护成本高、应用程序开发难度大的问题,提供一种降低维护成本及应用程序开发难度的数据缓存方法及装置。
一种数据缓存方法,包括:
接收数据库操作指令;
基于所述数据库操作指令判断是否满足缓存数据删除条件;
若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
一种数据缓存装置,包括:
指令接收模块,用于接收数据库操作指令;
条件判断模块,用于基于所述数据库操作指令判断是否满足缓存数据删除条件;
缓存删除模块,用于若所述条件判断模块的判断结果为满足时,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
上述数据缓存方法及装置,由于在接收到数据库操作指令后,基于所述数据库操作指令判断是否满足缓存数据删除条件;若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。因此,可以根据数据库操作指令,删除待删除的缓存数据,实现缓存数据的自动维护,而无需在应用程序中设置缓存的生命周期,因此,可以降低维护成本,降低应用程序的开发难度。
附图说明
图1为一实施例的数据缓存方法的流程图;
图2为图1的数据缓存方法的一个步骤的具体流程图;
图3为图1的数据缓存方法的另一个步骤的具体流程图;
图4为一个具体实施例的数据缓存方法的一个步骤的一种方式的具体流程图;
图5为一个具体实施例的数据缓存方法的一个步骤的另种方式的具体流程图;
图6为另一实施例的数据缓存方法的流程图;
图7为应用程序的缓存管理界面示意图;
图8为应用程序与数据缓存装置的关系图;
图9为一实施例的数据缓存装置的结构图。
具体实施方式
为了便于理解本发明,下面将参照相关附图对本发明进行更全面的描述。附图中给出了本发明的较佳的实施例。但是,本发明可以以许多不同的形式来实现,并不限于本文所描述的实施例。相反地,提供这些实施例的目的是使对本发明的公开内容的理解更加透彻全面。
除非另有定义,本文所使用的所有的技术和科学术语与属于本发明的技术领域的技术人员通常理解的含义相同。本文中在本发明的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本发明。本文所使用的术语“或/和”包括一个或多个相关的所列项目的任意的和所有的组合。
如图1所示,为本发明一实施例的数据缓存方法,包括:
S110:接收数据库操作指令。
当应用程序需要对数据库进行操作时,系统将产生数据库操作指令即调用统一的缓存接口。本数据缓存方法首先接收该数据库操作指令。具体地,数据库操作指令包括操作动作及数据标识。其中,操作动作为数据库操作指令需要完成的操作动作;数据标识为数据库操作指令的操作对象的标识,优选地,该标识为数据库操作指令的操作对象的唯一标识。可以理解的,数据库操作指令的操作对象是数据库中的数据。
S130:基于所述数据库操作指令判断是否满足缓存数据删除条件。
可以根据数据库操作指令的操作动作来区分不同的数据库操作指令,再根据不同类型的数据库操作指令,判断相应类型的数据库操作指令是否满足缓存数据删除条件。
S150:若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
在满足缓存数据删除条件时,删除缓存中、根据数据库操作指令确定的待删除的缓存数据。待删除的缓存数据可以是缓存中数据标识对应的缓存数据,也可以是在缓存容量达到最大值时,按照预设策略应该被替换的缓存数据。预设策略可以是采用先进先出原则的先进先出算法,也可以是采用最近最少使用原则的LRU(Least Recently Used,最近最少使用)算法,当然也可以是其它算法。优选地,为了提高缓存的命中率,预设策略为LRU算法。
若不满足,则直接执行数据库操作指令。即根据数据标识及更新动作完成对数据库中存储的数据标识对应的数据库数据的操作。
上述数据缓存方法,由于在接收到数据库操作指令后,基于所述数据库操作指令判断是否满足缓存数据删除条件;若满足,删除缓存中、根据所述 数据库操作指令确定的待删除的缓存数据。因此,可以根据数据库操作指令,删除待删除的缓存数据,实现缓存数据的自动维护,而无需在应用程序中设置缓存的生命周期,从而,可以降低维护成本,降低应用程序的开发难度。
请参阅图2,在其中一个实施例中,所述基于所述数据库操作指令判断是否满足缓存数据删除条件的步骤,包括:
S231:判断所述数据库操作指令的所述操作动作的动作类型,并包括下述两项中的至少一项;具体地,动作类型包括更新动作及读取动作。
S233:若所述操作动作的动作类型为更新动作,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件;
S234:若所述操作动作的动作类型为读取动作,判断若加入所述待操作数据,所述缓存中的缓存数据的大小是否大于所述缓存的缓存容量,若是,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件。
如此,在数据库操作指令的操作动作为更新动作时,或者在数据库操作指令的操作动作为读取动作、加入待操作数据缓存中的缓存数据的大小大于缓存的缓存容量时,满足缓存数据删除条件。此时,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。从而,实现自动缓存数据的自动维护,降低维护成本及应用程序的开发难度。
请参阅图3,在其中一个实施例中,所述删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的步骤,包括:
S351:当所述数据库操作指令的操作动作为更新动作时,根据所述数据标识确定缓存中待删除的缓存数据;或/及,当所述数据库操作指令的操作动作为读取动作时,采用预设策略确定缓存中待删除的缓存数据。
如此,根据所述数据库操作指令,确定缓存中待删除的缓存数据。
S353:删除所述缓存中待删除的缓存数据。
在确定缓存中待删除的缓存数据之后,删除缓存中待删除的缓存数据。
在其中一个实施例中,所述删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的步骤之后,还包括:
根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
进一步地,当所述数据库操作指令的操作动作为更新动作时,所述删除所述缓存中待删除的缓存数据的步骤之后,还包括:
S355:根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
如此,完成数据库操作指令对应的对数据库数据的操作。从而,使得缓存中的数据与数据库中的数据保持一致性。
在一个具体实施例中,若在接收操作动作为更新动作的数据库操作指令之后,若后续再接收到应用程序产生的、操作动作为读取操作的数据库操作指令,则需要先将数据库中的数据库数据返回并存储至缓存中,形成缓存数据;然后再将该缓存数据返回至应用程序。
更进一步地,通过一个缓存删除事务实现删除所述缓存中待删除的缓存数据;通过一个数据库更新事务实现根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
一个缓存删除事务是将实现删除所述缓存中待删除的缓存数据的指令的集合,在该集合内的指令执行时,要么该集合内的指令全部执行成功,要么该集合内的指令全部不执行或执行后回滚。避免因执行一部分而导致的数据错误。
具体地,在所述数据库更新事务中抛出异常错误时,对所述数据库更新事务进行回滚,并在对所述数据库更新事务进行回滚后,对所述缓存删除事务进行回滚。如此,在保持数据库与缓存中的数据的一致性的同时,提高数据的命中率。
在一个具体实施例中,缓存的事务是强事务支持。缓存的事务与数据库的事务保持一致。数据库的事务要开启,对应的缓存的事务先开启;数据库 的事务提交成功,对应的缓存的事务也跟着提交成功;若数据库的事务需要回滚,对应的缓存的事务也跟着回滚。
以数据库操作指令的操作动作为更新动作为例,其中,更新动作包括删除及修改。缓存可以通过缓存池来实现。请参阅图4,若缓存删除事务正常,则删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的具体流程包括:
S401:开启缓存删除事务;
S402:开启数据库更新事务;
S403:清除缓存数据;即删除缓存中待删除的缓存数据。
S404:修改或删除数据库数据;即,根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
S405:提交数据库更新事务;
S406:提交缓存删除事务。
请参阅图5,若数据库更新事务异常,则删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的具体流程包括:
S501:开启缓存删除事务;
S502:开启数据库更新事务;
S503:清除缓存数据;即删除缓存中待删除的缓存数据。
S504:修改或删除数据库数据;即,根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
S505:返回数据库更新异常;
S506:回滚数据库更新事务;
S507:回滚缓存删除事务。
请参阅图6,在其中一个实施例中,所述接收数据库操作指令的步骤之前,或删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的步骤之后,所述还包括:
S670:接收缓存清除指令;所述缓存清除指令包括待操作数据的数据标识。
S690:根据所述缓存清除指令删除缓存中所述数据标识对应的待操作数据。
可以通过缓存管理界面接收缓存清楚指令。一个缓存管理界面示例图,如图7所示。在应用程序运行过程中,倘若人为地修改数据库的数据,以致缓存与数据库的数据不一致。此时,无需重启应用程序,可以通过应用程序的缓存管理界面通过清除缓存操作清除缓存。如此,当应用程序再次读取缓存时,重新加载缓存数据。通过缓存管理界面,还可以监控到缓存的状态和使用情况,如缓存的总容量(即缓存容量)、当前容量(即已使用的容量)、请求次数、命中次数、命中率、重写次数、擦除次数等。
请继续参阅图6,在其中一个实施例中,所述接收数据库操作指令的步骤之前,还包括:
S601:接收缓存容量设置指令,所述缓存容量设置指令包括缓存标识及目标容量。
S603:根据所述缓存标识及所述目标容量,将所述缓存标识对应的缓存的缓存容量设置为所述目标容量。
数据库的数据可以为百万级或千万级的数据量,如果数据都被加载到缓存,那么系统内存根本无法支持。因此,需要为缓存设置一个最大容量值,即缓存容量。同时,在该缓存容量的基础上,结合预设策略,可实现缓存容量的自我管理机制。
以LRU算法为例,每次读取缓存中的缓存数据时,都会把此缓存数据重新存储到缓存的尾端。每次在缓存中插入新的数据库数据时,都会把此数据库数据存储到缓存的尾端,形成缓存数据。每次在把数据库数据存储到缓存的尾端之前,先判断若加入该数据库数据,缓存的大小是否达到缓存容量,如果是,则将缓存中近期最少被读取的数据(即头部的数据)移除,然后才把数据库数据插入到缓存。
在其中一个具体实施例中,缓存用于存储键值对([key,value])。一个缓 存,类似于关系数据库的一个表。数据库某个表的一行数据,就是一个数据库数据。把数据库数据的数据标识作为缓存的一关键字(key),且把数据标识对应的数据作为数据值(value),存储到缓存中,形成缓存数据。也就是说,缓存存放的缓存数据源自数据库数据。缓存,具有以下功能:
(1)插入一个缓存数据(类似于数据库某个表插入一条数据的操作);
(2)根据某个关键字,如某个数据标识,获取某个缓存对象(类似于数据库的查询操作);
(3)根据多个关键字,如多个数据标识,获取多个缓存对象(类似于数据库的查询操作);
(4)根据某个关键字,如某个数据标识,移除某个缓存对象(类似于数据库的删除一条数据操作);
(5)清空当前缓存(类似于数据库的清空表的操作);
(6)获取当前缓存的实际容量(类似于数据库的查询某个表有多少条数据的操作)。
(7)获取当前缓存的缓存标识(类似于获取数据库的某个表的表名)。
(8)设置缓存的缓存容量(类似于设置数据库的某个表的大小)。
缓存的集合可以称之为缓存池。它类似于关系数据库的库。缓存池存放的是缓存。缓存池,具有以下功能:
(1)插入一个缓存(类似于数据库创建一个表)。
(2)根据某个关键字,如缓存标识,获取一个缓存;
(3)根据某个关键字,如缓存标识,移除某个缓存(类似于数据库的删除某个表的操作);
(4)清除所有缓存;
(5)返回所有缓存;
(6)返回所有缓存的总数;
(7)设定最大容量。
(8)自动判断当前容量达到最大容量时,自动移除最久没有被读取的缓 存数据。
在本具体实施例中,可以对缓存池设置最大容量。可以理解地,也可以仅对每一个缓存设置缓存容量。
本发明还提供一与上述数据缓存方法对应的实施例的数据缓存装置,该数据缓存装置可作为应用程序的一个子模块,供应用程序调用。如图8所示,应用程序和该数据缓存装置将同处于同一个JVM(Java Virtual Machine,Java虚拟机)内。
如图9所示,一与上述数据缓存方法对应的实施例的数据缓存装置,包括:
指令接收模块910,用于接收数据库操作指令;
条件判断模块930,用于基于所述数据库操作指令判断是否满足缓存数据删除条件;
缓存删除模块950,用于若条件判断模块930的判断结果为满足时,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
上述数据缓存装置,由于在接收到数据库操作指令后,基于所述数据库操作指令判断是否满足缓存数据删除条件;若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。因此,可以根据数据库操作指令,删除待删除的缓存数据,实现缓存数据的自动维护,而无需在应用程序中设置缓存的生命周期,从而,可以降低维护成本,降低应用程序的开发难度。
在其中一个实施例中,所述数据库操作指令包括待操作数据的数据标识及操作动作;条件判断模块930,包括:
动作类型判断单元,用于判断所述数据库操作指令的所述操作动作的动作类型;并包括下述两项中的至少一项:
第一判断单元,用于若所述操作动作的动作类型为更新动作,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件;
第二判断单元,用于若所述操作动作的动作类型为读取动作,判断若加 入所述待操作数据,所述缓存中的缓存数据的大小是否大于所述缓存的缓存容量,若是,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件。
在其中一个实施例中,缓存删除模块950,包括:
缓存数据确定单元,用于当所述数据库操作指令的操作动作为更新动作时,根据所述数据标识确定缓存中待删除的缓存数据;或/及,当所述数据库操作指令的操作动作为读取动作时,采用预设策略确定缓存中待删除的缓存数据;
缓存数据删除单元,用于删除所述缓存中待删除的缓存数据。
进一步地,还包括:
数据库删除模块960,用于缓存数据确定单元根据所述数据标识及所述更新动作确定缓存中待删除的缓存数据,且缓存数据删除单元删除所述缓存中待删除的缓存数据之后,根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
具体地,缓存删除模块950通过一个缓存删除事务实现删除所述缓存中待删除的缓存数据;数据库删除模块960通过一个数据库更新事务实现根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
更具体地,在所述数据库更新事务中抛出异常错误时,数据库删除模块960对所述数据库更新事务进行回滚,并在数据库删除模块960对所述数据库更新事务进行回滚后,缓存删除模块950对所述缓存删除事务进行回滚。
在其中一个实施例中,还包括:
清除指令接收模块970,用于接收缓存清除指令;所述缓存清除指令包括待操作数据的数据标识;
清除指令执行模块990,用于根据所述缓存清除指令删除缓存中所述数据标识对应的待操作数据。
在其中一个实施例中,还包括:
设置指令接收模块901,用于接收缓存容量设置指令,所述缓存容量设置指令包括缓存标识及目标容量;
缓存容量设置模块903,用于根据所述缓存标识及所述目标容量,将所述缓存标识对应的缓存的缓存容量设置为所述目标容量。
以上实施例仅表达了本发明的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出多个变形和改进,这些都属于本发明的保护范围。因此,本发明专利的保护范围应以所附权利要求为准。

Claims (10)

  1. 一种数据缓存方法,其特征在于,包括:
    接收数据库操作指令;
    基于所述数据库操作指令判断是否满足缓存数据删除条件;
    若满足,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
  2. 根据权利要求1所述的数据缓存方法,其特征在于,所述数据库操作指令包括待操作数据的数据标识及操作动作;
    所述基于所述数据库操作指令判断是否满足缓存数据删除条件的步骤,包括:
    判断所述数据库操作指令的所述操作动作的动作类型,并包括下述两项中的至少一项;
    若所述操作动作的动作类型为更新动作,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件;
    若所述操作动作的动作类型为读取动作,判断若加入所述待操作数据,所述缓存中的缓存数据的大小是否大于所述缓存的缓存容量,若是,判定满足所述缓存数据删除条件,否则判定不满足所述缓存数据删除条件。
  3. 根据权利要求1所述的数据缓存方法,其特征在于,所述删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的步骤,包括:
    当所述数据库操作指令的操作动作为更新动作时,根据所述数据标识确定缓存中待删除的缓存数据;或/及,当所述数据库操作指令的操作动作为读取动作时,采用预设策略确定缓存中待删除的缓存数据;
    删除所述缓存中待删除的缓存数据。
  4. 根据权利要求3所述的数据缓存方法,其特征在于,当所述数据库操作指令的操作动作为更新动作时,所述删除所述缓存中待删除的缓存数据的步骤之后,还包括:
    根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
  5. 根据权利要求4所述的数据缓存方法,其特征在于,
    通过一个缓存删除事务实现删除所述缓存中待删除的缓存数据;
    通过一个数据库更新事务实现根据所述数据标识及所述更新动作完成对数据库中存储的所述数据标识对应的数据库数据的操作。
  6. 根据权利要求5所述的数据缓存方法,其特征在于,
    在所述数据库更新事务中抛出异常错误时,对所述数据库更新事务进行回滚,并在对所述数据库更新事务进行回滚后,对所述缓存删除事务进行回滚。
  7. 根据权利要求1所述的数据缓存方法,其特征在于,所述接收数据库操作指令的步骤之前,或删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据的步骤之后,还包括:
    接收缓存清除指令;所述缓存清除指令包括待操作数据的数据标识;
    根据所述缓存清除指令删除缓存中所述数据标识对应的待操作数据。
  8. 根据权利要求1所述的数据缓存方法,其特征在于,所述接收数据库操作指令的步骤之前,还包括:
    接收缓存容量设置指令,所述缓存容量设置指令包括缓存标识及目标容量;
    根据所述缓存标识及所述目标容量,将所述缓存标识对应的缓存的缓存容量设置为所述目标容量。
  9. 一种数据缓存装置,其特征在于,包括:
    指令接收模块,用于接收数据库操作指令;
    条件判断模块,用于基于所述数据库操作指令判断是否满足缓存数据删除条件;
    缓存删除模块,用于若所述条件判断模块的判断结果为满足时,删除缓存中、根据所述数据库操作指令确定的待删除的缓存数据。
  10. 根据权利要求9所述的数据缓存装置,其特征在于,还包括:
    清除指令接收模块,用于接收缓存清除指令;所述缓存清除指令包括待操作数据的数据标识;
    清除指令执行模块,用于根据所述缓存清除指令删除缓存中所述数据标识对应的待操作数据。
PCT/CN2016/100563 2016-08-31 2016-09-28 数据缓存方法及装置 WO2018040167A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610798142.6 2016-08-31
CN201610798142.6A CN106354851A (zh) 2016-08-31 2016-08-31 数据缓存方法及装置

Publications (1)

Publication Number Publication Date
WO2018040167A1 true WO2018040167A1 (zh) 2018-03-08

Family

ID=57858596

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/100563 WO2018040167A1 (zh) 2016-08-31 2016-09-28 数据缓存方法及装置

Country Status (2)

Country Link
CN (1) CN106354851A (zh)
WO (1) WO2018040167A1 (zh)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108897495A (zh) * 2018-06-28 2018-11-27 北京五八信息技术有限公司 缓存更新方法、装置、缓存设备及存储介质
CN109325054A (zh) * 2018-07-23 2019-02-12 中国建设银行股份有限公司 基于缓存的数据处理方法、系统和存储介质
CN109918348A (zh) * 2019-03-26 2019-06-21 努比亚技术有限公司 应用浏览记录的清理方法、终端及计算机可读存储介质
CN110362588A (zh) * 2019-07-16 2019-10-22 山东浪潮通软信息科技有限公司 一种轻量级跨主机缓存刷新方法及装置
CN111046106A (zh) * 2019-12-19 2020-04-21 杭州中恒电气股份有限公司 缓存数据同步方法、装置、设备及介质
CN112487037A (zh) * 2020-12-08 2021-03-12 平安国际智慧城市科技股份有限公司 缓存数据的处理方法、装置、计算机设备及存储介质
CN112559572A (zh) * 2020-12-22 2021-03-26 上海悦易网络信息技术有限公司 一种用于Key-Value缓存系统数据缓存预热的方法及设备

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107707619B (zh) * 2017-08-28 2020-12-04 北京小米移动软件有限公司 分布式存储方法及装置
CN110427386B (zh) * 2019-08-05 2023-09-19 广州方硅信息技术有限公司 数据处理方法、装置及计算机存储介质
CN112631741A (zh) * 2020-12-09 2021-04-09 网宿科技股份有限公司 事务处理方法、设备及存储介质
CN114138807B (zh) * 2021-12-06 2024-04-12 四三九九网络股份有限公司 一种实时更新数据库热点数据缓存的方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101217449A (zh) * 2008-01-09 2008-07-09 金蝶软件(中国)有限公司 远程调用管理方法
CN101226542A (zh) * 2008-02-01 2008-07-23 中国建设银行股份有限公司 一种报表缓存的方法
CN103338243A (zh) * 2013-06-20 2013-10-02 新浪网技术(中国)有限公司 Web节点的缓存数据更新方法和系统
US9332160B1 (en) * 2015-09-09 2016-05-03 Samuel Chenillo Method of synchronizing audio-visual assets

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102331986B (zh) * 2010-07-12 2014-07-16 阿里巴巴集团控股有限公司 一种数据库缓存管理方法及一种数据库服务器

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101217449A (zh) * 2008-01-09 2008-07-09 金蝶软件(中国)有限公司 远程调用管理方法
CN101226542A (zh) * 2008-02-01 2008-07-23 中国建设银行股份有限公司 一种报表缓存的方法
CN103338243A (zh) * 2013-06-20 2013-10-02 新浪网技术(中国)有限公司 Web节点的缓存数据更新方法和系统
US9332160B1 (en) * 2015-09-09 2016-05-03 Samuel Chenillo Method of synchronizing audio-visual assets

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108897495A (zh) * 2018-06-28 2018-11-27 北京五八信息技术有限公司 缓存更新方法、装置、缓存设备及存储介质
CN108897495B (zh) * 2018-06-28 2023-10-03 北京五八信息技术有限公司 缓存更新方法、装置、缓存设备及存储介质
CN109325054A (zh) * 2018-07-23 2019-02-12 中国建设银行股份有限公司 基于缓存的数据处理方法、系统和存储介质
CN109918348A (zh) * 2019-03-26 2019-06-21 努比亚技术有限公司 应用浏览记录的清理方法、终端及计算机可读存储介质
CN109918348B (zh) * 2019-03-26 2023-09-19 努比亚技术有限公司 应用浏览记录的清理方法、终端及计算机可读存储介质
CN110362588A (zh) * 2019-07-16 2019-10-22 山东浪潮通软信息科技有限公司 一种轻量级跨主机缓存刷新方法及装置
CN110362588B (zh) * 2019-07-16 2023-03-31 浪潮通用软件有限公司 一种轻量级跨主机缓存刷新方法及装置
CN111046106A (zh) * 2019-12-19 2020-04-21 杭州中恒电气股份有限公司 缓存数据同步方法、装置、设备及介质
CN112487037A (zh) * 2020-12-08 2021-03-12 平安国际智慧城市科技股份有限公司 缓存数据的处理方法、装置、计算机设备及存储介质
CN112559572A (zh) * 2020-12-22 2021-03-26 上海悦易网络信息技术有限公司 一种用于Key-Value缓存系统数据缓存预热的方法及设备

Also Published As

Publication number Publication date
CN106354851A (zh) 2017-01-25

Similar Documents

Publication Publication Date Title
WO2018040167A1 (zh) 数据缓存方法及装置
US11775524B2 (en) Cache for efficient record lookups in an LSM data structure
EP2478442B1 (en) Caching data between a database server and a storage system
US20180067962A1 (en) Consistent execution of partial queries in hybrid dbms
KR100745883B1 (ko) 투명한 네트워크 에지의 데이터 캐시
JP4028820B2 (ja) コンピュータ・システムでのトランザクションの選択的キャッシングの方法および装置
Zhou et al. Spitfire: A three-tier buffer manager for volatile and non-volatile memory
US8825959B1 (en) Method and apparatus for using data access time prediction for improving data buffering policies
US20150193144A1 (en) System and Method for Implementing SSD-Based I/O Caches
US8589438B2 (en) System for accessing shared data using multiple application servers
US8572130B2 (en) Replacement policy for resource container
US20230148215A1 (en) Key-value storage using a skip list
JP4398464B2 (ja) 1つのターゲット・ボリュームと1つのソース・ボリュームとの間のポイント・イン・タイム・コピー関連性を管理するためのシステム、方法、及びプログラム
JP2013228999A (ja) データベース処理装置、方法、プログラム及びデータ構造
US8732404B2 (en) Method and apparatus for managing buffer cache to perform page replacement by using reference time information regarding time at which page is referred to
US10642745B2 (en) Key invalidation in cache systems
JP4189342B2 (ja) ストレージ装置、ストレージコントローラ及びライトバックキャッシュ制御方法
US20230090835A1 (en) Reducing requests using probabilistic data structures
KR101419428B1 (ko) 모바일 환경에 구축된 데이터베이스에 대한 트랜잭션 로깅 및 회복 장치 및 그 방법
CN115878677A (zh) 分布式多级缓存的数据处理方法和装置
An et al. Your read is our priority in flash storage
CN116775700A (zh) 一种数据缓存方法、装置及存储介质
US20240118982A1 (en) Early Database Transaction Visibility
US11526474B2 (en) Reducing requests using probabilistic data structures
JP2008269408A (ja) データ検索システム

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16914730

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16914730

Country of ref document: EP

Kind code of ref document: A1