Cache miss protection method, system, electronic device and storage medium
By leveraging the collaboration mechanism between Redis and MySQL, the risk of deadlock and data inconsistency caused by cache breakdown is resolved, achieving efficient data querying and consistency protection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INSPUR TIANYUAN COMM INFORMATION SYST CO LTD
- Filing Date
- 2023-08-28
- Publication Date
- 2026-08-04
AI Technical Summary
Existing cache breakdown solutions pose a deadlock risk and cannot guarantee data consistency.
By leveraging the interaction and collaboration between Redis and MySQL, using Redis as a temporary key-value storage location, and combining it with MySQL's query and locking mechanisms, asynchronous data updates and distributed lock management are achieved, reducing the occurrence of cache breakdown.
This effectively prevented server unavailability incidents, ensured data consistency, and reduced the frequency of cache breakdowns.
Smart Images

Figure CN117290374B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a cache breakdown protection method, system, electronic device and storage medium. Background Technology
[0002] Existing solutions for addressing cache breakdown primarily involve using mutexes or logical expiration. However, mutexes and logical expiration not only carry the risk of deadlocks but also fail to guarantee consistency. Summary of the Invention
[0003] This application provides a cache breakdown protection method, system, electronic device, and storage medium, which aims to avoid the risk of deadlock and ensure data consistency.
[0004] Firstly, this application provides a cache breakdown protection method, including:
[0005] Respond to the data request and parse out the requested data from the data request;
[0006] The query is performed in Redis based on the requested data to obtain the query results;
[0007] A query is performed based on the query results and the first MySQL instance; the first MySQL instance is a temporary key-value storage location.
[0008] In one embodiment, the query based on the query result and the first MySQL query includes:
[0009] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0010] If it is determined that the requested data is found in the first MySQL database, the first thread to acquire the lock will change the flag from flag=false to flag=true.
[0011] Update the remaining time in the first MySQL database by multiplying it by 4.
[0012] Update the Remaining Time * 2 to Redis. If the remaining threads check if flag = true or if flag = true during double-check, then directly return the requested data.
[0013] In one embodiment, the query based on the query result and the first MySQL query includes:
[0014] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0015] If it is determined that the requested data is not found in the first MySQL instance, the actual data is queried in the second MySQL instance to obtain the actual data; the second MySQL instance is the actual data storage location.
[0016] In one embodiment, after performing the actual data query in the second MySQL database to obtain the actual data, the method further includes:
[0017] One thread is allowed to enter the second MySQL instance, while the remaining threads are in a waiting state.
[0018] Assign preset values to the key, value, and frequency of the actual data, and store the expiration time of the actual data * 2 in the first MySQL database;
[0019] Store the key, value, and expiration time of the actual data in Redis;
[0020] Release the distributed lock, and the remaining threads will query Redis again.
[0021] In one embodiment, the cache breakdown protection method further includes:
[0022] If the query result is determined to be that the requested data is found in Redis, then the requested data is returned directly.
[0023] Rate limiting is implemented using the Kafka message mechanism, and the number of times the asynchronous key is updated in the first MySQL database is equal to the current count plus 1.
[0024] In one embodiment, the cache breakdown protection method further includes:
[0025] The number of times the key_value_strategy table is checked periodically;
[0026] Determine the target number of attempts and delete the target data corresponding to the target number of attempts; the target number of attempts is greater than a preset value;
[0027] In Redis, set the expiration time of the target data to never expire, and move the key-value pair of the target data to the key_value_save table.
[0028] In one embodiment, the cache breakdown protection method further includes:
[0029] If the query result is determined to be: the requested data is not found in Redis, but the expiration time is never expired, then no operation is performed on the first MySQL database.
[0030] When updating the second MySQL instance, if it is confirmed that the value of the data in the second MySQL instance exists in Redis, then the value is updated in both Redis and the first MySQL instance, and the expiration time is reset.
[0031] Secondly, this application provides a cache breakdown protection system, comprising:
[0032] The response parsing module is used to respond to data requests and parse out the requested data in the data request;
[0033] The first query module is used to query Redis based on the requested data and obtain the query results.
[0034] The second query module is used to perform a query based on the query results and the first MySQL; the first MySQL is a temporary key-value storage location.
[0035] Thirdly, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the cache breakdown protection method described in the first aspect when executing the program.
[0036] Fourthly, this application also provides a non-transitory computer-readable storage medium, which includes a computer program that, when executed by the processor, implements the cache breakdown protection method described in the first aspect.
[0037] Fifthly, this application also provides a computer program product, the computer program product including a computer program, which, when executed by the processor, implements the cache breakdown protection method described in the first aspect.
[0038] The cache breakdown protection method, system, electronic device, and storage medium provided in this application respond to data requests and parse the requested data from the data request; query Redis based on the requested data to obtain the query result; and query the result and a first MySQL instance, which is a temporary key-value storage location. During the cache breakdown protection process, the query is performed through the interaction and cooperation between Redis and MySQL, reducing the frequency of cache breakdowns and avoiding server unavailability incidents, thereby avoiding the risk of deadlocks and ensuring data consistency. Attached Figure Description
[0039] To more clearly illustrate the technical solutions of this application, the drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is a flowchart illustrating the cache breakdown protection method provided in this application;
[0041] Figure 2 This is one of the interactive flow diagrams provided in this application;
[0042] Figure 3 This is the second interactive flow diagram provided in this application;
[0043] Figure 4 This is a schematic diagram of the cache breakdown protection system provided in this application;
[0044] Figure 5 This is a schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0046] This application provides an embodiment of a cache breakdown protection method. It should be noted that although the logical order is shown in the flowchart, under certain data conditions, the steps shown or described may be performed in a different order than that shown here.
[0047] Reference Figure 1 , Figure 1 This is a flowchart illustrating the cache breakdown protection method provided in this application. The cache breakdown protection method provided in this application includes:
[0048] Step 101: Respond to the data request and parse out the requested data in the data request;
[0049] Step 102: Query Redis based on the requested data to obtain the query results;
[0050] Step 103: Perform a query based on the query results and the first MySQL instance; the first MySQL instance is a temporary key-value storage location.
[0051] It should be noted that the embodiments in this application are illustrated using a server as the execution subject, but are not limited to servers.
[0052] It should be noted that when preparing a Redis instance, there are two databases: a first database named mysql and a second database named mysql. The first database mysql can be represented as mysql2, and the second database mysql can be represented as mysql1. Database mysql1 is the actual data storage location, and database mysql2 is the temporary key-value storage location.
[0053] Furthermore, create a table key_value_strategy with four fields: key, value, times, and expire_time. Create an index on key. Then create a table key_value_save with two fields: key and value.
[0054] Specifically, the server responds to the data request and parses out the requested data from the request. Further, the server first queries Redis to determine if the requested data can be found in Redis, obtaining the query result. Therefore, the query result can be either that the requested data can be found in Redis or that it cannot.
[0055] Furthermore, depending on whether the query result shows that the requested data can be found in Redis or not, the server queries the mysql2 database for the requested data.
[0056] The cache breakdown protection method provided in this application responds to a data request and parses the data to be requested in the data request; queries Redis based on the data to be requested to obtain the query result; and queries the first MySQL based on the query result; the first MySQL is a temporary key-value storage location.
[0057] During cache breakdown protection, queries are performed through the interaction and collaboration between Redis and MySQL, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0058] In one embodiment, performing a query based on the query result and the first MySQL query includes:
[0059] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0060] If it is determined that the requested data is found in the first MySQL database, the first thread to acquire the lock will change the flag from flag=false to flag=true.
[0061] Update the remaining time in the first MySQL database by multiplying it by 4.
[0062] Update the Remaining Time * 2 to Redis. If the remaining threads check if flag = true or if flag = true during double-check, then directly return the requested data.
[0063] Specifically, if the query result is that the requested data is not found in Redis, the server will first enter the mysql2 database to perform a key-value query to determine whether the requested data can be found in the mysql2 database.
[0064] Furthermore, if it is determined that the requested data can be found in the mysql2 database, the server will change the flag of the first thread to acquire the lock from flag=false to flag=true. The server will then update the remaining time in the mysql2 database by 4, and update the remaining time by 2 in Redis.
[0065] Furthermore, if the remaining threads check that flag=true or, during a double-check, flag=true, the server will directly return the requested data. See details below. Figure 2 This is one of the interactive flow diagrams provided in this application.
[0066] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0067] In one embodiment, performing a query based on the query result and the first MySQL query includes:
[0068] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0069] If it is determined that the requested data is not found in the first MySQL instance, the actual data is queried in the second MySQL instance to obtain the actual data; the second MySQL instance is the actual data storage location.
[0070] Specifically, if the query result is that the requested data is not found in Redis, the server will first enter the mysql2 database to perform a key-value query to determine whether the requested data can be found in the mysql2 database.
[0071] Furthermore, if it is determined that the requested data cannot be found in the mysql2 database, the server will then query the actual data in the mysql1 database, which requires distributed locking to obtain the actual data.
[0072] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0073] In one embodiment, after retrieving the actual data from the second MySQL database, the process further includes:
[0074] One thread is allowed to enter the second MySQL instance, while the remaining threads are in a waiting state.
[0075] Assign preset values to the key, value, and frequency of the actual data, and store the expiration time of the actual data * 2 in the first MySQL database;
[0076] Store the key, value, and expiration time of the actual data in Redis;
[0077] Release the distributed lock, and the remaining threads will query Redis again.
[0078] Specifically, the server sends one thread into database mysql1, while the remaining threads wait. Further, the server assigns preset values to the key, value, and count of the actual data, and stores the actual data's expiration time multiplied by 2 in database mysql2. In one embodiment, the preset value is 1, so it can be understood that the server stores the actual data's key, value, and count = 1 in database mysql2. Further, the server stores the actual data's key, value, and expiration time in Redis.
[0079] Furthermore, the server releases the distributed lock and sends the remaining threads to query Redis again to retrieve the value. This means the remaining threads need to double-check the value returned from Redis. See details... Figure 3 This is the second interactive flow diagram provided in this application.
[0080] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0081] In one embodiment, the cache breakdown protection method further includes:
[0082] If the query result is determined to be that the requested data is found in Redis, then the requested data is returned directly.
[0083] Rate limiting is implemented using the Kafka message mechanism, and the number of times the asynchronous key is updated in the first MySQL database is equal to the current count plus 1.
[0084] Specifically, if the query result indicates that the requested data is found in Redis, the server will directly return the requested data. Simultaneously, the server uses the Kafka messaging mechanism for rate limiting, and the number of times the key is asynchronously updated in the MySQL database is equal to the current count plus 1. Since this count is used for rough estimation, it is not required to be precise.
[0085] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0086] In one embodiment, the cache breakdown protection method further includes:
[0087] The number of times the key_value_strategy table is checked periodically;
[0088] Determine the target number of attempts and delete the target data corresponding to the target number of attempts; the target number of attempts is greater than a preset value;
[0089] In Redis, set the expiration time of the target data to never expire, and move the key-value pair of the target data to the key_value_save table.
[0090] Specifically, the server starts a scheduled task, such as checking the `key_value_strategy` table every hour. The server determines the target count and deletes the target data corresponding to the target count, where the target count is greater than a preset value. Further, the server sets the expiration time of the target data in Redis to never expire and moves the target data's key-value pair to the `key_value_save` table. This can be understood as follows:
[0091] When the count exceeds a preset value, delete the data entry, set it to never expire in Redis, and move the key-value pair to the key_value_save table. Also, reset the count to 0 for all data at midnight each day.
[0092] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0093] In one embodiment, the cache breakdown protection method further includes:
[0094] If the query result is determined to be: the requested data is not found in Redis, but the expiration time is never expired, then no operation is performed on the first MySQL database.
[0095] When updating the second MySQL instance, if it is confirmed that the value of the data in the second MySQL instance exists in Redis, then the value is updated in both Redis and the first MySQL instance, and the expiration time is reset.
[0096] Specifically, if the query result is determined to be: no data to be requested was found in Redis, but the expiration time is never expired, the server will not perform any operation on the mysql2 database.
[0097] When updating database mysql1, if it is confirmed that the value of the data in database mysql1 exists in Redis, then update the value and reset the expiration time in both Redis and database mysql2.
[0098] This application embodiment uses the interaction and collaboration between Redis and MySQL for querying, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0099] It should be noted that locks always have a timeout mechanism, which is implemented using Redis's setNx method.
[0100] Since no locking is applied to Redis and buffering is provided for databases mysql2 and Kafka, there will be no serious performance degradation issue. While locking at databases mysql1 and mysql2 will affect performance, the impact will only be temporary and will not persist throughout the application's entire lifecycle.
[0101] A scheduled task was used to monitor the access count of each key, which maximizes the extraction of the most valuable cached data. Simultaneously, removing related data from the mysql2 database prevented the database from growing indefinitely.
[0102] Permanent keys are recorded using the key_value_save table, which can be deleted when no longer needed, ensuring traceability. Because of the existence of database mysql2, database mysql1 will never be significantly impacted.
[0103] Therefore, this application uses a database mysql2 as an intermediate database, mainly for buffering purposes, to maximize the stability of the original database mysql1. It should be noted that the database mysql2 does not store complete data, but is used to store key-value pairs, similar to Redis. The values retrieved from Redis each time are asynchronously counted in the database mysql2 via Kafka.
[0104] Furthermore, the cache breakdown protection system and the cache breakdown protection method provided in this application correspond to each other. Figure 4 As shown, Figure 4 This is a schematic diagram of the cache breakdown protection system provided in this application. The cache breakdown protection system includes:
[0105] The response parsing module 401 is used to respond to data requests and parse out the requested data in the data request;
[0106] The first query module 402 is used to perform a query in Redis based on the data to be requested and obtain the query result;
[0107] The second query module 403 is used to perform a query based on the query result and the first mysql; the first mysql is a temporary key-value storage location.
[0108] The cache breakdown protection system provided in this application responds to data requests and parses the data to be requested in the data request; queries Redis based on the data to be requested to obtain query results; and queries a first MySQL database based on the query results; the first MySQL database is a temporary key-value storage location.
[0109] During cache breakdown protection, queries are performed through the interaction and collaboration between Redis and MySQL, which reduces the number of cache breakdowns and avoids server unavailability incidents, thereby avoiding the risk of deadlock and ensuring data consistency.
[0110] Furthermore, the second query module 403 is also used for:
[0111] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0112] If it is determined that the requested data is found in the first MySQL database, the first thread to acquire the lock will change the flag from flag=false to flag=true.
[0113] Update the remaining time in the first MySQL database by multiplying it by 4.
[0114] Update the Remaining Time * 2 to Redis. If the remaining threads check if flag = true or if flag = true during double-check, then directly return the requested data.
[0115] Furthermore, the second query module 403 is also used for:
[0116] If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database.
[0117] If it is determined that the requested data is not found in the first MySQL instance, the actual data is queried in the second MySQL instance to obtain the actual data; the second MySQL instance is the actual data storage location.
[0118] Furthermore, the cache breakdown protection system is also used for:
[0119] One thread is allowed to enter the second MySQL instance, while the remaining threads are in a waiting state.
[0120] Assign preset values to the key, value, and frequency of the actual data, and store the expiration time of the actual data * 2 in the first MySQL database;
[0121] Store the key, value, and expiration time of the actual data in Redis;
[0122] Release the distributed lock, and the remaining threads will query Redis again.
[0123] Furthermore, the cache breakdown protection system is also used for:
[0124] If the query result is determined to be that the requested data is found in Redis, then the requested data is returned directly.
[0125] Rate limiting is implemented using the Kafka message mechanism, and the number of times the asynchronous key is updated in the first MySQL database is equal to the current count plus 1.
[0126] Furthermore, the cache breakdown protection system is also used for:
[0127] The number of times the key_value_strategy table is checked periodically;
[0128] Determine the target number of attempts and delete the target data corresponding to the target number of attempts; the target number of attempts is greater than a preset value;
[0129] In Redis, set the expiration time of the target data to never expire, and move the key-value pair of the target data to the key_value_save table.
[0130] Furthermore, the cache breakdown protection system is also used for:
[0131] If the query result is determined to be: the requested data is not found in Redis, but the expiration time is never expired, then no operation is performed on the first MySQL database.
[0132] When updating the second MySQL instance, if it is confirmed that the value of the data in the second MySQL instance exists in Redis, then the value is updated in both Redis and the first MySQL instance, and the expiration time is reset.
[0133] The specific embodiments of the cache breakdown protection system provided in this application are basically the same as the embodiments of the cache breakdown protection method, and will not be described in detail here.
[0134] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute a cache breakdown protection method, which includes:
[0135] Respond to the data request and parse out the requested data from the data request;
[0136] The query is performed in Redis based on the requested data to obtain the query results;
[0137] A query is performed based on the query results and the first MySQL instance; the first MySQL instance is a temporary key-value storage location.
[0138] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0139] On the other hand, this application also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer is able to execute the cache breakdown protection method provided by the above methods. The method includes:
[0140] Respond to the data request and parse out the requested data from the data request;
[0141] The query is performed in Redis based on the requested data to obtain the query results;
[0142] A query is performed based on the query results and the first MySQL instance; the first MySQL instance is a temporary key-value storage location.
[0143] In another aspect, this application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the cache breakdown protection methods provided above, the method comprising:
[0144] Respond to the data request and parse out the requested data from the data request;
[0145] The query is performed in Redis based on the requested data to obtain the query results;
[0146] A query is performed based on the query results and the first MySQL instance; the first MySQL instance is a temporary key-value storage location.
[0147] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0148] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0149] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for protecting against cache breakdown, characterized in that, include: Respond to the data request and parse out the requested data from the data request; The query is performed in Redis based on the requested data to obtain the query results; Perform a query based on the query results and the first MySQL query; The first MySQL location is a temporary key-value storage location; The query based on the query result and the first MySQL query includes: If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database. If it is determined that the requested data is found in the first MySQL database, the first thread to acquire the lock will change the flag from flag=false to flag=true. Update the remaining time in the first MySQL database by multiplying it by 4. Update the remaining time * 2 to Redis. If the remaining threads check if flag=true or if flag=true during double-check, then directly return the requested data. The double-check refers to the remaining threads returning to Redis to retrieve the value.
2. The buffer breakdown protection method according to claim 1, characterized in that, The query based on the query result and the first MySQL query includes: If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database. If it is determined that the requested data is not found in the first MySQL instance, the actual data is queried in the second MySQL instance to obtain the actual data; the second MySQL instance is the actual data storage location.
3. The buffer breakdown protection method according to claim 2, characterized in that, After retrieving the actual data from the second MySQL database, the process also includes: One thread is allowed to enter the second MySQL instance, while the remaining threads are in a waiting state. Assign preset values to the key, value, and frequency of the actual data, and store the expiration time of the actual data * 2 in the first MySQL database; Store the key, value, and expiration time of the actual data in Redis; Release the distributed lock, and the remaining threads will query Redis again.
4. The buffer breakdown protection method according to claim 1, characterized in that, The cache breakdown protection method also includes: If the query result is determined to be that the requested data is found in Redis, then the requested data is returned directly. Rate limiting is implemented using the Kafka message mechanism, and the number of times the asynchronous key is updated in the first MySQL database is equal to the current count plus 1.
5. The buffer breakdown protection method according to claim 1, characterized in that, The cache breakdown protection method also includes: The number of times the key_value_strategy table is checked periodically; Determine the target number of attempts and delete the target data corresponding to the target number of attempts; the target number of attempts is greater than a preset value; In Redis, set the expiration time of the target data to never expire, and move the key-value pair of the target data to the key_value_save table.
6. The cache breakdown protection method according to claim 1, characterized in that, The cache breakdown protection method also includes: If the query result is determined to be: the requested data is not found in Redis, but the expiration time is never expired, then no operation is performed on the first MySQL database. When updating the second MySQL instance, if it is confirmed that the value of the data in the second MySQL instance exists in Redis, then the value is updated in both Redis and the first MySQL instance, and the expiration time is reset.
7. A buffer breakdown protection system, characterized in that, include: The response parsing module is used to respond to data requests and parse out the requested data in the data request; The first query module is used to query Redis based on the requested data and obtain the query results. The second query module is used to perform a query based on the query results and the first MySQL database; The first MySQL location is a temporary key-value storage location; The query based on the query result and the first MySQL query includes: If the query result is determined to be that the requested data is not found in Redis, then a key-value query is performed in the first MySQL database. If it is determined that the requested data is found in the first MySQL database, the first thread to acquire the lock will change the flag from flag=false to flag=true. Update the remaining time in the first MySQL database by multiplying it by 4. Update the remaining time * 2 to Redis. If the remaining threads check if flag=true or if flag=true during double-check, then directly return the requested data. The double-check refers to the remaining threads returning to Redis to retrieve the value.
8. An electronic device, the electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the cache breakdown protection method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the cache breakdown protection method according to any one of claims 1 to 6.