Cache data processing method, device, computer equipment and storage medium
By monitoring the database data update operation and deleting cached data after the update is successful, the problem of inconsistency between the database and cached data is solved, and the data consistency is guaranteed.
Patent Information
- Application Number
- CN202011445989.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-08
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2040-12-08
AI Technical Summary
After the database storage data is updated, the data in the cache may be inconsistent with the database, causing the data requester to obtain the data before the update.
Monitor the success of database data update operation, delete old data in the cache area, and write the delete task to the message queue when the update fails, try the deletion operation again, record the number of failures and alarm information, and ensure data consistency.
By establishing a retry mechanism for failed deletion, we ensure that the cached data is deleted successfully after being updated, avoiding the data requester from obtaining old data, and ensuring the consistency between the database and cache.
Smart Images

Figure CN112487037B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method for processing cache data, a device for processing cache data, a computer device, and a computer-readable storage medium. Background Art
[0002] Currently, when a storage system receives a data request, it first checks whether the requested data is in the cache area. If so, it directly returns the cached data to the corresponding requester without performing any operations on the database. If the requested data is not in the cache area, it searches the database for the requested data, returns the data found in the database to the corresponding requester, and caches a copy of the data in the cache area.
[0003] However, when the data in the database is updated, if the deletion of the original data in the cache fails, the original data will still be retained in the cache. In this way, when the storage system has a corresponding data request, the original data in the cache is still obtained instead of the updated new data, and the consistency of the data between the database and the cache cannot be guaranteed.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present application is to provide a cache data processing method, cache data processing device, computer equipment and computer-readable storage medium, aiming to solve the problem that when the database storage data is updated, the database data and the cache data are easily inconsistent.
[0006] To achieve the above purpose, the present application provides a method for processing cache data, comprising the following steps:
[0007] When a data update operation is detected in the database, detecting whether the target data of the data update operation is updated successfully;
[0008] When it is detected that the target data is updated successfully, deleting the cached data of the target data in the cache area;
[0009] Detecting whether deletion of the cached data fails;
[0010] When it is detected that the cache data deletion fails, the key value corresponding to the cache data is written into the message queue to record the deletion task corresponding to the cache data;
[0011] When the key value sent by the message queue is received, the cache data obtained based on the key value query is deleted, and the process returns to execute the step of detecting whether the cache data has failed to be deleted.
[0012] Furthermore, after the step of detecting whether the cache data has failed to be deleted, the method further includes:
[0013] When it is detected that the cache data has failed to be deleted, the number of deletion failures corresponding to the cache data is recorded;
[0014] Detecting whether the number of deletion failures is greater than a preset number;
[0015] If so, output a warning message.
[0016] Furthermore, the step of detecting whether the number of deletion failures is greater than a preset number includes:
[0017] Check whether the number of deletion failures of the cached data within a preset time period is greater than a preset number.
[0018] Further,
[0019] After the step of writing the key value corresponding to the cached data into a message queue to record the deletion task corresponding to the cached data when the cached data deletion fails is detected, the method further includes:
[0020] When it is detected that the number of the key values in the message queue is greater than a preset threshold, an alarm message is output.
[0021] Furthermore, the database is a distributed database of the blockchain; when the data update operation is detected in the database, the step of detecting whether the target data targeted by the data update operation is updated successfully includes:
[0022] When a data update operation is detected in the distributed database of the blockchain, update query information of the target data targeted by the data update operation is sent to the distributed database of the blockchain to detect whether the target data targeted by the data update operation is updated successfully;
[0023] Among them, when a positive response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated successfully; when a negative response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated unsuccessfully.
[0024] Furthermore, after the step of detecting whether the target data targeted by the data update operation is successfully updated when the data update operation is detected in the database, the method further includes:
[0025] When it is detected that the target data fails to be updated, update failure prompt information corresponding to the target data is generated.
[0026] Furthermore, after the step of detecting whether the cache data has failed to be deleted, the method further includes:
[0027] When it is detected that the cache data is deleted successfully, updated cache data corresponding to the target data is generated in the cache area.
[0028] To achieve the above object, the present application further provides a cache data processing device, the cache data processing device comprising:
[0029] A monitoring module, used to detect whether the target data targeted by the data update operation is successfully updated when a data update operation occurs in the database;
[0030] A deletion module, used to delete the cached data of the target data in the cache area when detecting that the target data is updated successfully;
[0031] A judgment module, used for detecting whether the cache data fails to be deleted;
[0032] A writing module, configured to write a key value corresponding to the cached data into a message queue to record a deletion task corresponding to the cached data when it is detected that the cached data has failed to be deleted;
[0033] The processing module is used to delete the cache data obtained by querying the key value when receiving the key value sent by the message queue, and return to execute the step of detecting whether the cache data fails to be deleted.
[0034] To achieve the above object, the present application also provides a computer device, the computer device comprising:
[0035] The computer device includes a memory, a processor, and a cache data processing program stored in the memory and executable on the processor. When the cache data processing program is executed by the processor, the steps of the cache data processing method described above are implemented.
[0036] To achieve the above objectives, the present application also provides a computer-readable storage medium, on which a cache data processing program is stored. When the cache data processing program is executed by a processor, the steps of the cache data processing method as described above are implemented.
[0037] The cache data processing method, cache data processing device, computer equipment and computer-readable storage medium provided by the present application establish a deletion retry mechanism for cache data that fails to be deleted in the storage area. After the storage data is updated, it is ensured that the cache data cached in the cache area before the storage data is updated can be deleted successfully, so that the data requester will not obtain the storage data before the update, thereby ensuring the consistency of the data between the database and the cache. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 This is a schematic diagram of the steps of a method for processing cache data in an embodiment of the present application;
[0039] Figure 2 A schematic block diagram of a cache data processing device according to an embodiment of the present application;
[0040] Figure 3 A schematic block diagram of the structure of a computer device according to an embodiment of the present application.
[0041] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0043] Reference Figure 1 In one embodiment, the method for processing cache data includes:
[0044] Step S10: When a data update operation is detected in the database, detecting whether the target data of the data update operation is updated successfully;
[0045] Step S20: when it is detected that the target data is updated successfully, deleting the cached data of the target data in the cache area;
[0046] Step S30, detecting whether the cache data fails to be deleted;
[0047] Step S40: When it is detected that the cache data deletion fails, the key value corresponding to the cache data is written into the message queue to record the deletion task corresponding to the cache data;
[0048] Step S50: upon receiving the key value sent by the message queue, deleting the cache data obtained by querying the key value, and returning to execute the step of detecting whether the cache data has failed to be deleted.
[0049] In this embodiment, the execution terminal of the embodiment may be a computer device or a processing device for caching data.
[0050] As described in step S10: the system of the terminal includes a database and a cache area (such as a memory cache), wherein the cache area is used to cache the data in the database.
[0051] Optionally, the terminal may monitor whether a data update operation for data stored in the database occurs in the database, wherein the data update operation may be a data modification operation (including data insertion) or a data deletion operation.
[0052] Optionally, when the terminal detects that a data update operation has occurred in the database, the data in the database targeted by the data update operation (i.e., the database data) is used as the target data, and the target data is operated based on the specific operation mode corresponding to the data update operation. When the data update operation is a data modification operation, the modified target data is used as the updated target data; when the data update operation is a data deletion operation, the target data is directly deleted from the database.
[0053] Furthermore, when the target data is operated based on the data update operation, the terminal can detect whether the data update operation is successfully executed by detecting whether the target data before and after the update are consistent. When the terminal detects that the data update operation is successfully executed, it is determined that the target data in the database is updated successfully; when the terminal detects that the data update operation fails, it is determined that the target data in the database is updated unsuccessfully.
[0054] As described in step S20: when the terminal detects that the target data in the database is successfully updated, the cache data previously cached in the cache area of the target data is queried. It should be understood that when the terminal caches the data in the database into the cache area, a mapping relationship between the database data and the cache data is established, and based on the mapping relationship, the cache data corresponding to the database data can be queried in the cache area.
[0055] Optionally, the terminal can use the key value (key value) of the database data in the database as the key value of the cache data corresponding to the database data in the cache area, so as to establish a mapping relationship between the two based on the key value associated with both the database data and the cache data. Of course, the terminal can also assign a new key value to the cache data corresponding to the database data, and then only need to establish a mapping relationship between the key value of the database data and the key value of the cache data, that is, query the key value of the cache data according to the key value of the database data, and then query the cache data based on the key value of the cache data.
[0056] In this way, the terminal can query the corresponding cache data in the cache area based on the key value corresponding to the target data.
[0057] When the terminal obtains cache data corresponding to the target data through query in the cache area, the cache data obtained through query is deleted from the cache area.
[0058] As described in step S30: after the terminal performs a deletion operation on the cached data of the target data in the cache area, it can further detect whether the cached data fails to be deleted.
[0059] Optionally, the terminal can query the cached data in the cache area according to the key value of the target data (or the key value corresponding to the cached data); when no data is found in the cache area, it is determined that the cached data has been deleted successfully; when the cached data corresponding to the key value is queried in the cache area, it is determined that the cached data has been deleted unsuccessfully.
[0060] As described in step S40: Optionally, the key value corresponding to the cached data is recorded as the first key value, and when the terminal detects that the currently deleted cached data fails to be deleted, the first key value corresponding to the cached data that failed to be deleted is written into the message queue (Message Queue, MQ). It should be noted that the message queue is a "first-in, first-out" data structure in the basic data structure, and in this embodiment, the message queue is used to record the deletion task corresponding to the cached data, that is, writing the first key value into the message queue is equivalent to generating and recording a deletion task to be executed.
[0061] Among them, an ACK (Acknowledge character) confirmation character mechanism is established between the terminal and the message queue. When the message queue detects that there is a new key value written in the queue, it will send a confirmation character to the terminal.
[0062] Optionally, after the terminal writes the first key value into the message queue, it can further detect whether a confirmation character sent by the message queue is received within the first preset time length. When the terminal receives the confirmation character sent by the message queue within the first preset time length, it is determined that the first key value has been successfully written into the message queue; when the terminal does not receive the confirmation character sent by the message queue within the first preset time length, the first key value is re-written into the message queue. The first preset time length can be set according to actual needs, such as 1 second, 3 seconds, 5 seconds, etc. In this way, it can be ensured that the first key value is successfully written into the message queue.
[0063] Optionally, if the terminal detects that the currently deleted cached data is successfully deleted from the cache area, the terminal may not process it. After that, when the terminal receives a data request from the data request end for the target data (i.e., the updated target data), it detects that the cached data corresponding to the target data does not exist in the cache area (at this time, the cached data corresponding to the target data before the update has been successfully deleted), then the target data is obtained from the database and sent to the data request end, and the target data is cached in the cache area to generate the corresponding cached data (i.e., the cached data corresponding to the updated target data). It should be understood that for the implementation of this scenario, the data update operation previously used to update the target data needs to be a data modification operation, not a data deletion operation.
[0064] As described in step S50: Optionally, the key value written in the message queue is recorded as the second key value (or the key value sent by the message queue is recorded as the second key value).
[0065] Optionally, when the second key value is stored in the message queue, the message queue may send the second key value to the terminal according to a preset rule, wherein the preset rule may be receiving a second key value acquisition instruction sent by the terminal, or sending the second key value to the terminal once every preset interval.
[0066] Optionally, the terminal can monitor in real time whether the processing thread of the terminal is idle, and when detecting that there is an idle processing thread, send a second key value acquisition instruction to the message queue, so that the message queue can send the second key value to the terminal.
[0067] Optionally, when the terminal receives the second key value sent by the message queue, it determines that a deletion task needs to be executed currently, and searches the cache area for the first key value that matches (or is consistent with) the second key value, and then further determines that the cache data corresponding to the first key value obtained by the query is the cache data corresponding to the second key value.
[0068] Further, after the terminal obtains the cache data corresponding to the second key value through querying in the cache area, the cache data (i.e., the cache data corresponding to the first key value matching the second key value) is deleted from the cache area. Then, the terminal returns to the step of detecting whether the cache data has failed to be deleted (i.e., returns to step S30).
[0069] Optionally, after the terminal executes step S30 again, if it is detected again that the cache data deletion fails, the first key value corresponding to the cache data is written into the message queue again, and this cycle is repeated until the cache data is successfully deleted from the cache area.
[0070] In one embodiment, by establishing a deletion retry mechanism for cached data that fails to be deleted in the storage area, after the storage data is updated, it is ensured that the cached data cached in the cache area before the storage data is updated can be deleted successfully, so that the data requester will not obtain the storage data before the update, thereby ensuring the consistency of data between the database and the cache.
[0071] In one embodiment, based on the above embodiment, after the step of detecting whether the cache data has failed to be deleted, the method further includes:
[0072] Step S60: when it is detected that the cache data fails to be deleted, the number of deletion failures corresponding to the cache data is recorded;
[0073] Step S61, detecting whether the number of deletion failures is greater than a preset number;
[0074] Step S62: If yes, output warning information.
[0075] In this embodiment, when the terminal detects that the cache data has failed to be deleted, in addition to writing the first key value corresponding to the cache data into the message queue, the number of deletion failures corresponding to the cache data may also be recorded.
[0076] Further, each time the terminal detects that the number of deletion failures corresponding to cached data is updated, it detects whether the currently updated number of deletion failures is greater than a preset number, wherein the preset number is greater than zero and can be specifically set according to actual needs, such as 1 time, 3 times, etc.
[0077] Optionally, when the terminal detects that the number of deletion failures of the current update is less than or equal to the preset number, the terminal may not take any action; when the terminal detects that the number of deletion failures of the current update is greater than the preset number, the terminal generates an alarm message of cache service downtime and outputs the alarm message to the engineer's associated equipment to prompt the engineer to troubleshoot and repair the cache service in a timely manner.
[0078] The terminal stores the contact information of the data maintenance engineer, and the engineer's associated devices can be queried based on the contact information.
[0079] Optionally, the warning information may be sent via email, text message, etc.
[0080] In this way, by effectively judging whether the cache service is down, relevant engineers can be prompted to repair the cache service in a timely manner, so that the cache data that needs to be deleted can be successfully deleted, thereby ensuring the consistency of data between the database and the cache.
[0081] In one embodiment, based on the above embodiment, the step of detecting whether the number of deletion failures is greater than a preset number includes:
[0082] Step S70: Detect whether the number of failed deletions of the cached data within a preset time period is greater than a preset number.
[0083] In this embodiment, the terminal may start recording time when detecting that the cache data fails to be deleted, and when the terminal detects that the recorded time reaches a preset time length, the number of deletion failures recorded for the cache data within the preset time length is obtained. In order to distinguish it from the first preset time length, the preset time length is the second preset time length, and the value of the second preset time length can be set according to actual needs, such as one minute, three minutes, etc.
[0084] It should be understood that during this period, the terminal can continuously obtain the second key value from the message queue to delete and retry the cache data corresponding to the second key value.
[0085] Furthermore, the terminal detects whether the number of deletion failures of the cached data recorded within a preset time period is greater than a preset number; if not, the terminal does not process it; if so, the terminal generates an alarm message of cache service downtime and outputs the alarm message to the engineer's associated device.
[0086] In this way, relevant engineers can be prompted in time to repair the cache service, so that the cache data that needs to be deleted can be successfully deleted as soon as possible, thereby ensuring the consistency of data between the database and the cache.
[0087] In one embodiment, based on the above embodiment, after the step of writing the key value corresponding to the cached data into a message queue to record the deletion task corresponding to the cached data when the cached data deletion fails is detected, the method further includes:
[0088] Step S80: When it is detected that the number of the key values in the message queue is greater than a preset threshold, an alarm message is output.
[0089] In this embodiment, after the terminal executes step S40, the terminal may periodically send inquiry information to the message pair to inquire the message queue about the number of second key values stored in the queue, and detect whether the number of second key values is greater than a preset threshold based on the number of second key values fed back by the message queue. The preset threshold may be set according to actual needs, such as 5, 10, etc.
[0090] Optionally, when the terminal detects that the number of second key values in the message queue is greater than a preset threshold, it determines that there are currently multiple different cache data deletion failures, and the cache service is determined to be down, and an alarm message of the cache service downtime is generated, and then the alarm message is output to the engineer's associated equipment.
[0091] In this way, it is possible to more accurately determine whether the cache service is down, and based on this, prompt engineers to repair the cache service in a timely manner. By effectively determining whether the cache service is down, it is possible to prompt relevant engineers to repair the cache service in a timely manner, so that the cache data that needs to be deleted can be successfully deleted, thereby ensuring the consistency of data between the database and the cache.
[0092] In one embodiment, based on the above embodiment, the database is a distributed database of the blockchain; when the data update operation is detected in the database, the step of detecting whether the target data targeted by the data update operation is updated successfully includes:
[0093] Step S90: When a data update operation is detected in the distributed database of the blockchain, update query information of the target data targeted by the data update operation is sent to the distributed database of the blockchain to detect whether the target data targeted by the data update operation is updated successfully;
[0094] Among them, when a positive response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated successfully; when a negative response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated unsuccessfully.
[0095] In this embodiment, the database is a distributed database of the blockchain, that is, the storage data of the terminal is stored in a distributed database built based on the blockchain technology.
[0096] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0097] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation monitoring. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and the maintenance of the correspondence between the user's real identity and the blockchain address (authority management), etc., and, under authorization, supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first adapts the interface for parsing and authentication (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). The smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other events are called to trigger the execution and complete the contract logic. It also provides the function of contract upgrade and cancellation. The operation monitoring module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, network monitoring, node equipment health monitoring, etc.
[0098] Optionally, the terminal can monitor whether the blockchain of any node in the blockchain network corresponding to the distributed database has any data update operation for the data stored in the database, and when a data update operation is detected in the distributed database of the blockchain, it can send update query information of the target data to the blockchain of any node in the blockchain network to query the blockchain whether the target data targeted by the current data update operation has been updated.
[0099] Optionally, when the distributed database receives update query information of the target data sent by the terminal, it can detect whether the target data targeted by the current data update operation has been globally updated in the blockchain network; if so, it is determined that the target data has been updated successfully, and then an affirmative response of the target data is sent to the terminal as feedback information of the update query information; if not, it is determined that the target data has failed to be updated, and then a negative response of the target data is sent to the terminal as feedback information of the update query information.
[0100] Optionally, when the terminal receives a positive response from the distributed database of the blockchain based on the update query information feedback, the terminal determines that the target data is updated successfully; when the terminal receives a negative response from the distributed database of the blockchain based on the update query information feedback, the terminal determines that the target data is updated unsuccessfully.
[0101] In this way, by using blockchain to ensure the security of stored data, update detection of stored data is achieved, so that the corresponding cached data can be further deleted in a timely manner, thereby ensuring the consistency of data between stored data and cached data.
[0102] In one embodiment, based on the above embodiment, after the step of detecting whether the target data targeted by the data update operation is successfully updated when the data update operation is detected in the database, the method further includes:
[0103] Step S100: When it is detected that the target data fails to be updated, update failure prompt information corresponding to the target data is generated.
[0104] In this embodiment, when the terminal detects that the update of the target data targeted by the data update operation fails, it can generate update failure prompt information corresponding to the target data, and output the update failure prompt information to the associated device of the engineer responsible for database maintenance, so as to prompt the relevant engineer to promptly investigate the cause of the failure to update the target data, so that the database can be repaired in time, so that the database service can be restored to normal as soon as possible, thereby avoiding losses caused by database abnormalities as much as possible.
[0105] In one embodiment, based on the above embodiment, after the step of detecting whether the target data targeted by the data update operation is successfully updated when the data update operation is detected in the database, the method further includes:
[0106] Step S110: When it is detected that the cache data is deleted successfully, cache data corresponding to the updated target data is generated in the cache area.
[0107] In this embodiment, when the terminal detects that the cached data (i.e., the cached data corresponding to the target data before the update) is deleted successfully, the updated target data can be copied to the cache area, thereby generating cached data corresponding to the updated target data in the cache area. It should be understood that for the implementation of this scenario, the data update operation previously used to update the target data needs to be a data modification operation, not a data deletion operation, that is, if the data update operation previously used to update the target data is a data deletion operation, then step S110 does not need to be performed.
[0108] In this way, when data is updated in the database, data consistency between the database and the cache can be achieved.
[0109] Reference Figure 2 In an embodiment of the present application, a cache data processing device 10 is also provided, comprising:
[0110] The monitoring module 11 is used to detect whether the target data of the data update operation is successfully updated when a data update operation occurs in the database;
[0111] A deleting module 12 is used to delete the cached data of the target data in the cache area when it is detected that the target data is updated successfully;
[0112] A judgment module 13, used to detect whether the cache data fails to be deleted;
[0113] The writing module 14 is used to write the key value corresponding to the cached data into the message queue to record the deletion task corresponding to the cached data when it is detected that the cached data deletion fails;
[0114] The processing module 15 is used to delete the cache data obtained based on the key value query when receiving the key value sent by the message queue, and return to execute the step of detecting whether the cache data fails to be deleted.
[0115] Reference Figure 3 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used for caching data processing programs. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for processing cached data is implemented.
[0116] Those skilled in the art will understand that Figure 3 The structure shown in is merely a block diagram of a portion of the structure related to the present application solution and does not constitute a limitation on the computer device to which the present application solution is applied.
[0117] In addition, the present application also proposes a computer-readable storage medium, the computer-readable storage medium includes a cache data processing program, and the cache data processing program, when executed by a processor, implements the steps of the cache data processing method described in the above embodiment. It can be understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.
[0118] To summarize, the cache data processing method, cache data processing device, computer equipment and storage medium provided in the embodiments of the present application establish a deletion and retry mechanism for cache data that fails to be deleted in the storage area. After the storage data is updated, it is ensured that the cache data cached in the cache area before the storage data is updated can be deleted successfully, so that the data requester will not obtain the storage data before the update, thereby ensuring the consistency of the data between the database and the cache.
[0119] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0120] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0121] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for processing cache data, characterized in that: include: When a data update operation is detected in the database, detecting whether the target data of the data update operation is updated successfully; When it is detected that the target data is updated successfully, deleting the cached data of the target data in the cache area; Detecting whether deletion of the cached data fails; When it is detected that the cache data deletion fails, the key value corresponding to the cache data is written into the message queue to record the deletion task corresponding to the cache data; wherein the key value written into the message queue is recorded as the second key value, and when the second key value is stored in the message queue, the message queue sends the second key value to the terminal according to a preset rule; the preset rule is to send the second key value to the terminal once every preset interval; When receiving the key value sent by the message queue, deleting the cache data obtained by querying based on the key value, and returning to execute the step of detecting whether the cache data fails to be deleted; The update operation includes a modification operation. When the data update operation is the modification operation, the modified target data is used as the updated target data; After the step of detecting whether the cache data has failed to be deleted, the method further includes: When it is detected that the cache data is deleted successfully, updated cache data corresponding to the target data is generated in the cache area.
2. The method for processing cache data according to claim 1, characterized in that: After the step of detecting whether the cache data has failed to be deleted, the method further includes: When it is detected that the cache data has failed to be deleted, the number of deletion failures corresponding to the cache data is recorded; Detecting whether the number of deletion failures is greater than a preset number; If so, output a warning message.
3. The method for processing cache data according to claim 2, characterized in that: The step of detecting whether the number of deletion failures is greater than a preset number includes: Check whether the number of deletion failures of the cached data within a preset time period is greater than a preset number.
4. The method for processing cache data according to claim 1, characterized in that: After the step of writing the key value corresponding to the cached data into a message queue to record the deletion task corresponding to the cached data when the cached data deletion fails is detected, the method further includes: When it is detected that the number of the key values in the message queue is greater than a preset threshold, an alarm message is output.
5. The method for processing cache data according to claim 1, characterized in that: The database is a distributed database of the blockchain; When the data update operation is detected in the database, the step of detecting whether the target data of the data update operation is updated successfully comprises: When a data update operation is detected in the distributed database of the blockchain, update query information of the target data targeted by the data update operation is sent to the distributed database of the blockchain to detect whether the target data targeted by the data update operation is updated successfully; Among them, when a positive response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated successfully; when a negative response is received from the distributed database of the blockchain based on the update query information feedback, it is determined that the target data is updated unsuccessfully.
6. The method for processing cache data according to claim 1 or 5, characterized in that: After the step of detecting whether the target data targeted by the data update operation is successfully updated when the data update operation is detected in the database, the method further includes: When it is detected that the target data fails to be updated, update failure prompt information corresponding to the target data is generated.
7. A cache data processing device, characterized in that: The method for processing cache data according to any one of claims 1 to 6 comprises: A monitoring module, used to detect whether the target data targeted by the data update operation is successfully updated when a data update operation occurs in the database; A deletion module, used to delete the cached data of the target data in the cache area when detecting that the target data is updated successfully; A judgment module, used for detecting whether the cache data fails to be deleted; A writing module, configured to write a key value corresponding to the cached data into a message queue to record a deletion task corresponding to the cached data when it is detected that the cached data has failed to be deleted; The processing module is used to delete the cache data obtained by querying the key value when receiving the key value sent by the message queue, and return to execute the step of detecting whether the cache data fails to be deleted.
8. A computer device, characterized in that: The computer device includes a memory, a processor, and a cache data processing program stored in the memory and executable on the processor. When the cache data processing program is executed by the processor, the steps of the cache data processing method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a cache data processing program, and when the cache data processing program is executed by a processor, the steps of the cache data processing method according to any one of claims 1 to 6 are implemented.
