A method, device and medium for maintaining cache data consistency

By writing new data to the user's invisible type cache in high-frequency access and high concurrency scenarios and converting it to the user's visible type after the database is updated successfully, the problem of inconsistency between cache and database data is solved, and data consistency and Timeliness.

CN114356949BActive Publication Date: 2024-12-13政采云股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210026392.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-11
Publication Date
2024-12-13
Estimated Expiration
2042-01-11

AI Technical Summary

Technical Problem

The prior art is difficult to maintain the consistency between cached data and database data in high-frequency access and high-concurrency scenarios, resulting in the data read by users that may be old data or inconsistent.

Method used

By receiving new data requested by the user, writing it to the cache of invisible type of user, and determining within the preset time that the cache update is successful, writing the new data to the database to ensure that the database update is successful and then sending it to User-visible caches to avoid inconsistencies between cache and database data.

Benefits of technology

It effectively avoids the problem of inconsistency between cache and database data, ensures that the data read by users is always up-to-date and consistent, and improves data timeliness and system reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114356949B_ABST
    Figure CN114356949B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and medium for maintaining cache data consistency, which are applied to the field of cache data processing, storing new data in a cache of a user-invisible type, judging whether the cache is updated successfully within a preset time, and if so, updating the database, and further judging whether the database is updated successfully, and if successful, setting the new data to a user-visible type. By setting the data structure in the cache, the new data can be set as a user-visible type for the user to read only after the cache update and database update are completed, as the user-invisible type data, since the new data cannot be used if it is not converted to a user-visible type, the user uses the user-visible type data from beginning to end, avoiding the problem of inconsistent data read in any cache and database update link in the current situation, and ensuring the consistency of the data read by the user in the cache and the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cache data processing, and in particular to a method, device and medium for maintaining cache data consistency. Background Art

[0002] In Internet technology, a large number of operation requests are encountered in a short period of time. In order to prevent a large number of requests from entering the database and to cope with high-frequency access and infrequently modified data queries, which will cause delays in other data operations, this requires high data timeliness. Ensuring that the data in the cache remains consistent with the data in the database is a necessary prerequisite for the effectiveness of the cache.

[0003] There are two solutions to cache data consistency at present. One is to delete the cache first, then update the database, and finally delete the cache. The other is to update the cache first, then update the database, and then delete the cache after the database update fails. The first solution is that the user reads new data when updating the database, and then deletes the cached data. If the cache deletion fails, the data read by the user in the cache is old data, resulting in inconsistency between the data in the cache and the data read in the database. The second solution is that the user reads the new data after the cache is updated, and further updates the database. If the database update fails, the data that has been accessed in the database is old data, resulting in inconsistency between the data in the cache and the data read in the database.

[0004] Therefore, how to ensure cache data consistency is an urgent problem that needs to be solved by those skilled in the art. Summary of the invention

[0005] The purpose of the present invention is to provide a method, device and medium for maintaining cache data consistency, thereby ensuring cache data consistency.

[0006] In order to solve the above technical problems, the present invention provides a method for maintaining cache data consistency, comprising:

[0007] Receive new data requested by the user for update, and write the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type;

[0008] Determine whether the cache is updated successfully within the preset time;

[0009] If the cache update is successful, the new data is written to the database;

[0010] Determine whether the database is updated successfully;

[0011] If the database is updated successfully, the new data is sent to the user-visible cache to complete the cache update for user reading.

[0012] Preferably, before writing new data into the database, the method further includes:

[0013] When the cache is not updated successfully within the preset time, it is determined that the cache update fails, and the process returns to the step of writing the new data into the user-invisible type cache according to the data structure;

[0014] Count the number of times new data is written;

[0015] When the number of detection writes reaches a preset number of times, the cache update fails, and the new data is marked and the process proceeds to the step of writing the new data into the database.

[0016] Preferably, it also includes:

[0017] When the database is not updated successfully, the new data written to the cache is deleted.

[0018] Preferably, after the database is updated successfully, before the new data is sent to the cache of the user-visible type, the method further includes:

[0019] Determine whether the new data is labeled data;

[0020] If so, the process returns to the step of writing the new data into the cache of the user-invisible type according to the data structure, and deletes the data in the cache of the user-visible type.

[0021] Preferably, it also includes:

[0022] After the new data is sent to the user-visible cache, prompt information is output to facilitate the user to obtain the updated new data.

[0023] Preferably, the data structure is of Map type.

[0024] Preferably, it also includes:

[0025] When the new data is not marked data, the process proceeds to a step of sending the new data to a user-visible type cache.

[0026] In order to solve the above technical problem, the present invention further provides a device for maintaining cache data consistency, comprising:

[0027] A first writing module, used for receiving new data requested by a user for update, and writing the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type;

[0028] A first judgment module is used to judge whether the cache is updated successfully within a preset time, and if the update is successful, trigger the second writing module;

[0029] The second writing module is used to write new data into the database;

[0030] The second judgment module is used to judge whether the database is updated successfully. If the update is successful, the sending module is triggered;

[0031] The sending module is used to send new data to the user-visible type cache to complete the cache update for user reading.

[0032] In order to solve the above technical problem, the present invention further provides a device for maintaining cache data consistency, comprising:

[0033] Memory for storing computer programs;

[0034] A processor is used to implement the steps of the method for maintaining cache data consistency as described above when executing a computer program.

[0035] In order to solve the above technical problem, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for maintaining cache data consistency as described above are implemented.

[0036] The present invention provides a method for maintaining cache data consistency, the method comprising receiving new data requested by a user for update, storing the new data in a cache of a user-invisible type, judging whether the cache is successfully updated within a preset time, that is, judging whether the new data is successfully written into the cache, if so, updating the database, further judging whether the database is successfully updated, and if successful, setting the new data to a user-visible type. The method sets the data structure in the cache so that the data read by the user is a user-visible type of data, and the new data, as a user-invisible type of data, can be set to a user-visible type for the user to read only after the cache update and database update are completed. If the cache update or database update is unsuccessful, the new data cannot be used because it has not been converted to a user-visible type. The user uses user-visible type data from beginning to end, avoiding the problem of inconsistent data read in any cache and database update link in the current situation, and ensuring the consistency of the data read by the user in the cache and database.

[0037] In addition, the present invention also provides a device and medium for maintaining cache data consistency, which have the same beneficial effects as the above-mentioned method for maintaining cache data consistency. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] Figure 1 A flowchart of a method for maintaining cache data consistency is provided for an embodiment of the present invention;

[0040] Figure 2 A structural diagram of a device for maintaining cache data consistency provided by an embodiment of the present invention;

[0041] Figure 3 A structural diagram of another device for maintaining cache data consistency provided by an embodiment of the present invention;

[0042] Figure 4 A flowchart of another method for maintaining cache data consistency provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of the present invention.

[0044] The core of the present invention is to provide a method, device and medium for maintaining cache data consistency, thereby ensuring cache data consistency.

[0045] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0046] It should be noted that the method for maintaining cache data consistency provided by the present invention is applicable to high-concurrency scenarios. When the data timeliness requirement is very high, it is necessary to ensure that the data in the cache is consistent with the data in the database and no differences occur. This requires a process and update strategy that are relatively dependent on the cache, and on this basis, the embodiments of the present invention are performed to ensure cache data consistency.

[0047] Figure 1 A flowchart of a method for maintaining cache data consistency is provided in an embodiment of the present invention, such as Figure 1 As shown, the method includes:

[0048] S11: receiving new data requested by a user for update, and writing the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type.

[0049] Before step S11, the user initiates an update request to update the data in the cache and database. The central processing unit (CPU) receives the user's update request and uses the user data in the update request as new data. The new data in the user's update request is used as the update data for updating the cache and database. When reading data, the data in the cache needs to be read first. If there is no data in the cache, the database is further read and the data read in the database is written into the cache. On this basis, the new data is first written into the cache.

[0050] Normally, after the update, when the user reads the data in the cache, the data in the cache is not differentiated, so that the data read by the user includes new data and old data. In order to distinguish which data in the current cache should be used by the user, the data needs to be classified. The data structure is a combination of data organized together in some form, which not only stores data but also supports operations to access and process data. The data in the cache is divided into user-visible type and user-invisible type. The data read by the user in the cache is user-visible data, that is, the data currently used by the user, and the user-invisible type is the new data used for updating according to the user's update request. Further, if the cache and database are updated successfully, the new data of the user-invisible type being processed is converted into user-visible type data for user reading.

[0051] It is understandable that there is no specific requirement for the specific type of the data structure, and it can be a Map type or a List type, as long as the data being accessed and the data for updating can be distinguished.

[0052] S12: Determine whether the cache is updated successfully within a preset time. If the update is successful, proceed to step S13.

[0053] In step S11, the new data is written into a cache of a user-invisible type according to the data structure, and it is further determined whether the cache is updated successfully within the preset time, that is, it is determined whether the new data is successfully written into the cache within the preset time. If the update is successful, step S13 is entered; if the update is unsuccessful, it means that the current write has failed, and it is necessary to retry the step of writing the new data into the user-invisible cache of the data structure in step S11.

[0054] It should be noted that the preset time is the expiration time of the data written to the update cache. For example, the preset time is 1ms. It is determined whether it is written within 1ms. If it is written beyond 1ms, it means that it is not written within the preset time and the update fails. The length of the preset time is not specifically limited in the present invention and is set according to actual conditions. If a shorter effective time is set for the new data, this time refers to the business time of the application updating the database, and can be slightly longer than the time of the database update operation, so as to delete the newly written data operation in the cache when the subsequent database update operation fails.

[0055] If the preset time is short, you do not need to delete the newly written data in the cache. If the preset time is too long, the data writing process takes a short time. If the current write fails, you can retry the data writing process several times. Or, when the subsequent database update fails, the cache update is successful, and the time for deleting the new data in the cache is included in the preset time.

[0056] S13: Write the new data into the database.

[0057] In step S12, it is determined whether the cache is updated successfully within the preset time. If the update is successful, the new data is written into the database. It can be understood that the purpose of step S13 is to update the database data. There is no limitation on the way of writing into the database. It can be written according to code instructions, and it does not need to be written with a data structure.

[0058] S14: Determine whether the database is updated successfully. If the update is successful, proceed to step S15.

[0059] In step S13, the new data is written into the database. If the queue or list has a higher priority than other data in the database, the new data fails to be written into the database. Therefore, it is determined whether the new data is successfully written into the database. In other words, it is determined whether the database is updated successfully. If the update is successful, it means that both the cache update and the database update are successful, and the process goes to step S15. If the update fails, the new data that is successfully updated in the cache is deleted.

[0060] S15: Send the new data to the user-visible type cache to complete the cache update for user reading.

[0061] In step S14, it is determined whether the database is updated successfully. If the update is successful, the new data is sent to the user-visible type cache to complete the cache update for easy reading by the user. It can be understood that the new data is written to the user-invisible type in the cache when the update request is made. When both the cache and the database are updated successfully, the new data is sent to the user-visible type for easy reading by the user.

[0062] The present invention provides a method for maintaining cache data consistency, the method comprising receiving new data requested by a user for update, storing the new data in a cache of a user-invisible type, judging whether the cache is successfully updated within a preset time, that is, judging whether the new data is successfully written into the cache, if so, updating the database, further judging whether the database is successfully updated, and if successful, setting the new data to a user-visible type. The method sets the data structure in the cache so that the data read by the user is a user-visible type of data, and the new data, as a user-invisible type of data, can be set to a user-visible type for the user to read only after the cache update and database update are completed. If the cache update or database update is unsuccessful, the new data cannot be used because it has not been converted to a user-visible type. The user uses user-visible type data from beginning to end, avoiding the problem of inconsistent data read in any cache and database update link in the current situation, and ensuring the consistency of the data read by the user in the cache and database.

[0063] Based on the above embodiment, before writing the new data into the database in step S13, the following is further included:

[0064] When the cache is not updated successfully within the preset time, it is determined that the cache update fails, and the process returns to the step of writing the new data into the user-invisible type cache according to the data structure;

[0065] Count the number of times new data is written;

[0066] When the number of detection writes reaches a preset number of times, the cache update fails, and the new data is marked and the process proceeds to the step of writing the new data into the database.

[0067] In step S12, it is determined whether the cache is updated successfully within the preset time. If not, it means that the cache update fails and it is necessary to retry the step of writing new data into the user invisible type cache according to the data structure in step S11. Specifically, the preset time in the present invention only represents the time for writing new data into the cache once.

[0068] When the cache update fails, the new data is rewritten into the user-invisible cache and the number of times the new data is written is counted. If the cache update is still in a failed state when the number of writes reaches the preset number, the new data needs to be marked to indicate the failed new data. It should be noted that the marking method is not limited and can be set according to the actual situation. A binary mark can be added at the beginning or end of the new data, or the marked new data can be placed in a separate list. If placed in the list, the new data needs to be read in the list when updating the database.

[0069] Normally, to solve the problem of cache data consistency, you can first delete the cache and then update the database. If the database update is successful, then delete the cache. The present invention combines the data in the cache under normal circumstances. If the new data is not successfully accessed into the cache, it indirectly becomes updating the database first, and then further updating the database.

[0070] After the update cache fails, the embodiment provides that the cache is rewritten and the number of writes is counted. When the number of writes reaches a preset number, the cache fails to update the data, and the data is marked. This facilitates the subsequent update of the database to determine the marked new data, thereby preventing the problem of inconsistent cache data caused by only updating the database.

[0071] Based on the above embodiment, in step S14, it is determined whether the database is updated successfully. If the database is not updated successfully, the following steps are further included:

[0072] When the database is not updated successfully, the new data written to the cache is deleted.

[0073] When the database is not updated successfully, it means that the data accessed by the user is old data in the user-visible type, and the new data in the newly written cache needs to be deleted. It is understandable that in order to reduce the user's response time and improve the execution efficiency of the system, in the case of a database update failure, the update cache is executed asynchronously, and the new data can be retried. If the update result fails after the retry, the new data in the newly written cache is deleted. If the preset time in the above embodiment is short, the step of deleting the new cache data may not be performed.

[0074] This embodiment provides that when the database is not updated successfully, the new data written into the cache is deleted, thereby reducing the user's response time and improving the execution efficiency of the system.

[0075] Specifically, after the database is updated successfully, before sending the new data to the user-visible type cache in step S15, the following is further included:

[0076] Determine whether the new data is labeled data;

[0077] If so, the process returns to the step of writing the new data into the cache of the user-invisible type according to the data structure, and deletes the data in the cache of the user-visible type.

[0078] Based on the above embodiment, there are two types of new data stored in the database, one is the new data that has been stored in the cache and updated successfully, and the other is the new data that failed to be written to the cache and is marked. After the database is updated, it is further determined what kind of data the new data is. If it is marked data, it means that the previous cache update failed and the cache needs to be updated again. Enter step S11 and delete the old user-visible data in the cache. Due to the failure retry mechanism, this process is an asynchronous process.

[0079] This embodiment provides a method for determining whether new data is marked data. If so, an attempt is made to update the cache and delete the old data to update the cache, thereby ensuring the consistency of the cache data.

[0080] Based on the above embodiment, after the new data is sent to the user-visible cache, the method further includes:

[0081] Output prompt information to facilitate users to obtain updated new data.

[0082] It can be understood that the data in the user-visible type in the cache is for users to read, and the new data in the user-invisible type cache involved in the present invention cannot be read by users. Regardless of whether the update is successful or not, if the new data is not converted into user-visible type data, the data read by the user is old data.

[0083] Specifically, the prompt information can be a dialog box on the page to remind the user, or it can be output as information on the way to obtain updated new data after the program instruction is executed. The present invention does not make specific limitations and can be set according to actual conditions.

[0084] This embodiment provides that after new data is sent to a user-visible cache, prompt information is output to facilitate the user to obtain the updated new data, and the user is promptly reminded to obtain new data on the basis of ensuring the consistency of the cached data.

[0085] In the above embodiment S11, it is mentioned that the data structure includes two types: user-visible type and user-invisible type, and the data structure is of Map type.

[0086] The values ​​in the Map are also Map structures. In the Map structure of the value, the key has two values, 1 and 0. 1 represents the data currently in use, and 0 represents the data currently not in use. The two corresponding values ​​are the user's cached data.

[0087] The data structure of the cache is of Map type, which is used to distinguish which data in the current cache should be used by the user. At the same time, after the database data is updated, there is no need to query the database to obtain new data, but to obtain new data directly from the cache, ensuring the consistency of database data and cache data. The new data structure format reference:

[0088] Map <key,Map<key2,value> >

[0089] The key is the first-level index, the key index of the data to be queried, and the value in the Map is Map<key2,value> This stores the data of the second-level index, where key2 has only two values, the values ​​stored are the data currently being accessed by the user (assuming key is 1) and the data currently updated by the user (assuming key is 0). In this embodiment, key 1 indicates a user-visible type, and 0 indicates a user-invisible type. Since the data structure of the Map collection is only valid for the key and has nothing to do with the value, it is only a preferred embodiment.

[0090] The data structure provided in this embodiment is of Map type, which is convenient for distinguishing which data in the current cache can be used by the user, so as to maintain the consistency of the cache data for subsequent update operations.

[0091] On the basis of the above embodiment, when the new data is not marked data, the method further includes:

[0092] Proceed to the step of sending new data to the cache of user-visible types.

[0093] In the above embodiment, it has been mentioned that after the database is updated successfully, there are two types of new data, which will not be elaborated here. It is necessary to determine what kind of data the new data is. If it is not marked data, it means that the previous cache update is successful, then the new data is sent to the user-visible type cache and converted into user-visible type data, that is, the new data is set as user-accessed data, that is, data with key 1.

[0094] This embodiment provides a step of sending the new data to a user-visible type cache when the new data is not marked data, so that the user can read the new data easily.

[0095] The above describes in detail various embodiments corresponding to the method for maintaining cache data consistency. On this basis, the present invention also discloses a device for maintaining cache data consistency corresponding to the above method. Figure 2 A structural diagram of a device for maintaining cache data consistency provided by an embodiment of the present invention. Figure 2 As shown, the device for maintaining cache data consistency includes:

[0096] A first writing module 11 is used to receive new data requested by a user for update, and write the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type;

[0097] A first judging module 12 is used to judge whether the cache is updated successfully within a preset time, and if the update is successful, trigger the second writing module 13;

[0098] The second writing module 13 is used to write new data into the database;

[0099] The second judging module 14 is used to judge whether the database is updated successfully. If the update is successful, the sending module 15 is triggered;

[0100] The sending module 15 is used to send new data to the user-visible type cache to complete the cache update for user reading.

[0101] Since the embodiments of the device part correspond to the above embodiments, please refer to the description of the embodiments of the device part for the embodiments of the device part, and will not be repeated here.

[0102] The present invention provides a device for maintaining cache data consistency, which includes receiving new data requested by a user to update, storing the new data in a cache of a user-invisible type, judging whether the cache is successfully updated within a preset time, that is, judging whether the new data is successfully written into the cache, and if so, updating the database, and further judging whether the database is successfully updated, and if successful, setting the new data to a user-visible type. The method sets the data structure in the cache so that the data read by the user is a user-visible type of data, and the new data can be set as a user-visible type for the user to read only after the cache update and database update are completed. If the cache update or database update is unsuccessful, the new data cannot be used because it has not been converted to a user-visible type. The user uses user-visible type data from beginning to end, avoiding the problem of inconsistent data read in any cache and database update link in the current situation, and ensuring the consistency of the data read by the user in the cache and database.

[0103] Figure 3 A structural diagram of another device for maintaining cache data consistency provided by an embodiment of the present invention, such as Figure 3 As shown, the device comprises:

[0104] A memory 21, used for storing computer programs;

[0105] The processor 22 is used to implement the steps of the method for maintaining cache data consistency when executing a computer program.

[0106] The device for maintaining cache data consistency provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.

[0107] Among them, the processor 22 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 22 can be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 22 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU; the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 22 may be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 22 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0108] The memory 21 may include one or more computer-readable storage media, which may be non-transitory. The memory 21 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 21 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 22, it can implement the relevant steps of the method for maintaining cache data consistency disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 21 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include but is not limited to data involved in the method for maintaining cache data consistency, etc.

[0109] In some embodiments, the device for maintaining cache data consistency may also include a display screen 23 , an input and output interface 24 , a communication interface 25 , a power supply 26 , and a communication bus 27 .

[0110] Those skilled in the art can understand that Figure 3 The structure shown in the figure does not constitute a limitation on the apparatus for maintaining cache data consistency, and may include more or fewer components than those shown in the figure.

[0111] The processor 22 implements the method for maintaining cache data consistency provided by any of the above embodiments by calling instructions stored in the memory 21 .

[0112] The present invention provides a device for maintaining cache data consistency, which includes receiving new data requested by a user to update, storing the new data in a cache of a user-invisible type, judging whether the cache is successfully updated within a preset time, that is, judging whether the new data is successfully written into the cache, and if so, updating the database, and further judging whether the database is successfully updated, and if successful, setting the new data to a user-visible type. The method sets the data structure in the cache so that the data read by the user is a user-visible type of data, and the new data can be set as a user-visible type for the user to read only after the cache update and database update are completed. If the cache update or database update is unsuccessful, the new data cannot be used because it has not been converted to a user-visible type. The user uses user-visible type data from beginning to end, avoiding the problem of inconsistent data read in any cache and database update link in the current situation, and ensuring the consistency of the data read by the user in the cache and database.

[0113] Furthermore, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by the processor 22, the steps of the method for maintaining cache data consistency as described above are implemented.

[0114] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc. Various media that can store program codes.

[0115] For an introduction to a computer-readable storage medium provided by the present invention, please refer to the above method embodiment, which will not be described in detail herein. It has the same beneficial effects as the above method for maintaining cache data consistency.

[0116] In order to enable those skilled in the art to better understand the technical solution of the present invention, the method, device and medium for maintaining cache data consistency provided by the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings.

[0117] Figure 4A flowchart of another method for maintaining cache data consistency provided by an embodiment of the present invention, such as Figure 4 As shown, the method includes:

[0118] S21: receiving a user update request;

[0119] S22: storing the user data in a cache of a type not visible to the user;

[0120] S23: Determine whether the cache is updated successfully within the preset time. If successful, proceed to step S24; if unsuccessful, proceed to step S25;

[0121] S24: Update database data;

[0122] S25: the current data cache update fails, and returns to S22;

[0123] S26: When the number of deposits reaches a preset number, the cache update fails, and the user data is marked as a failure;

[0124] S27: Determine whether the database is updated successfully. If not, proceed to step S28; if successful, proceed to step S29;

[0125] S28: asynchronously execute update cache and delete user data in the cache;

[0126] S29: Determine whether there is a failure mark for updating the cache in the user data. If yes, proceed to step S30; if no, proceed to step S31;

[0127] S30: Try to update the cache and delete the old data, and then go to step S31;

[0128] S31: Store the user data into a user-visible cache.

[0129] Another method for maintaining cache data consistency provided by an embodiment of the present invention is introduced above through a flowchart, which has the same beneficial effects as the above-mentioned method for maintaining cache data consistency.

[0130] The above is a detailed introduction to a method, device and medium for maintaining cache data consistency provided by the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

[0131] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A method for maintaining cache data consistency, characterized in that: include: Receive new data requested by a user for update, and write the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type; the user-visible type is data currently used by the user, and the user-invisible type is new data requested by the user for update; Determine whether the cache is updated successfully within a preset time; wherein the preset time is set with reference to the business time completed by the database and is greater than the time of the database update operation; If the cache update is successful, the new data is written into the database; Determining whether the database is updated successfully; If the database is updated successfully, the new data is sent to the user-visible cache to complete the cache update for user reading; Correspondingly, before writing the new data into the database, the method further includes: When the cache is not updated successfully within the preset time, it is determined that the cache update fails, and the process returns to the step of writing the new data into the user-invisible type cache according to the data structure; Counting the number of times the new data is written; When it is detected that the cache update fails when the number of write times reaches a preset number, the new data is marked and the step of writing the new data into the database is entered; wherein the marked new data is the failed new data; Correspondingly, after the database is updated successfully and before the new data is sent to the cache of the user-visible type, the method further includes: Determining whether the new data is marked data; If so, return to the step of writing the new data into the user-invisible type cache according to the data structure, and delete the data in the user-visible type cache; wherein the judgment process is an asynchronous process.

2. The method for maintaining cache data consistency according to claim 1, characterized in that: Also includes: When the database is not updated successfully, the new data written into the cache is deleted.

3. The method for maintaining cache data consistency according to claim 1 or 2, characterized in that: Also includes: After the new data is sent to the user-visible cache, prompt information is output to facilitate the user to obtain the updated new data.

4. The method for maintaining cache data consistency according to claim 1, characterized in that: The data structure is of Map type.

5. The method for maintaining cache data consistency according to claim 1, characterized in that: Also includes: When the new data is not the marked data, the process proceeds to the step of sending the new data to the user-visible type cache.

6. A device for maintaining cache data consistency, characterized in that: include: A first writing module is used to receive new data requested by a user for update, and write the new data into a cache of a user-invisible type according to a data structure, wherein the data structure includes two types: a user-visible type and a user-invisible type; the user-visible type is data currently used by the user, and the user-invisible type is new data requested by the user for update; A first judgment module is used to judge whether the cache is updated successfully within a preset time, and if the update is successful, trigger the second writing module; wherein the preset time is set with reference to the business time completed by the database and is greater than the time of the database update operation; The second writing module is used to write the new data into the database; A second judgment module is used to judge whether the database is updated successfully, and if the update is successful, trigger the sending module; The sending module is used to send the new data to the user-visible type cache to complete the cache update for user reading; Correspondingly, before writing the new data into the database, the method further includes: When the cache is not updated successfully within the preset time, it is determined that the cache update fails, and the process returns to the step of writing the new data into the user-invisible type cache according to the data structure; Counting the number of times the new data is written; When it is detected that the cache update fails when the number of write times reaches a preset number, the new data is marked and the step of writing the new data into the database is entered; wherein the marked new data is the failed new data; Correspondingly, after the database is updated successfully and before the new data is sent to the cache of the user-visible type, the method further includes: Determining whether the new data is marked data; If so, return to the step of writing the new data into the user-invisible type cache according to the data structure, and delete the data in the user-visible type cache; wherein the judgment process is an asynchronous process.

7. A device for maintaining cache data consistency, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for maintaining cache data consistency as described in any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for maintaining cache data consistency according to any one of claims 1 to 5 are implemented.