Data processing method, electronic equipment and storage medium

By verifying the version number of cached data and performing serialization processing, combined with a locking mechanism to retrieve data from an external library, the problem of data errors caused by outdated cached data is solved, thus achieving data accuracy and consistency.

CN120849468APending Publication Date: 2025-10-28BUSINESS LINE COMMERCIAL PTE LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510976979.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-10-28

AI Technical Summary

Technical Problem

Data in the database is not updated to the cache in a timely manner, resulting in outdated or incorrect cached data, making it impossible to retrieve the correct data.

Method used

By verifying the version number of the cached data and performing deserialization of the serialization type, the correct response data is ensured. When the cached data cannot be obtained, an uncached data is retrieved from the second preset library using a locking mechanism, and stored in the first preset library when the conditions are met.

Benefits of technology

This avoids data retrieval errors caused by outdated cached data, solves the cache avalanche problem, and ensures data accuracy and consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120849468A_ABST
    Figure CN120849468A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of data processing, and provides a data processing method, electronic equipment and a storage medium. The method comprises the steps of generating a key name in response to a data query request; if the cached data matched with the key name is obtained from the first preset library, verifying the cached data based on the version number of the cached data; and if the cached data passes the verification, performing deserialization processing on the cached data based on the serialization type of the cached data to obtain response data corresponding to the data query request. According to the method, correct response data can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of data processing, and in particular relates to a data processing method, electronic device and storage medium. Background Technology

[0002] To ensure users can quickly retrieve the data they need, data from the database is typically stored in a cache. However, if the data in the database is not updated to the cache in a timely manner, outdated or incorrect data in the cache will prevent the correct data from being retrieved. Summary of the Invention

[0003] This application provides a data processing method, an electronic device, and a storage medium to solve the technical problem of being unable to obtain correct data.

[0004] The first aspect of this application provides a data processing method, the method comprising: responding to a data query request and generating a key name; if cached data matching the key name is obtained from a first preset library, verifying the cached data based on the version number of the cached data; if the cached data passes the verification, deserializing the cached data based on the serialization type of the cached data to obtain response data corresponding to the data query request.

[0005] According to an embodiment of this application, the method further includes: if cached data matching the key name cannot be obtained from the first preset library, detecting whether the field length of the key name is greater than a preset length; if the field length of the key name is greater than the preset length, locking the key name using a preset thread, and determining a first thread from the preset threads based on the locking result of the key name, wherein the first thread is the thread that successfully locked the key name; and using the first thread, obtaining uncached data matching the key name from a second preset library as the response data.

[0006] According to an embodiment of this application, after obtaining uncached data matching the key name from the second preset library, the method further includes: if the version number corresponding to the uncached data meets a preset condition, storing the uncached data, the version number corresponding to the uncached data, and the serialization type in the first preset library.

[0007] According to an embodiment of this application, the method further includes: determining a second thread from the preset threads based on the locking result of the key name, wherein the second thread is the thread that failed to lock the key name; and obtaining data matching the key name from the first preset library based on preset broadcast information received by the second thread or based on a preset duration.

[0008] According to an embodiment of this application, the method further includes: if no uncached data matching the key name can be obtained from the second preset library, a prompt message is sent, wherein the prompt message is used to indicate that the version number corresponding to the key name is an initial value.

[0009] According to an embodiment of this application, generating the key name includes: obtaining parameter information from the data query request; and generating the key name based on the parameter information.

[0010] According to an embodiment of this application, the step of deserializing the cached data based on the serialization type of the cached data to obtain the response data corresponding to the data query request includes: determining the deserialization rule corresponding to the serialization type; and deserializing the cached data based on the deserialization rule to obtain the response data.

[0011] According to an embodiment of this application, the method further includes: responding to a data update request and obtaining the version number of the data to be updated in the data update request; if the version number of the data to be updated is a first preset value, deleting the data to be updated from the first preset library; if the version number of the data to be updated is greater than a second preset value, updating the corresponding data in the first preset library based on the data to be updated, and updating the version number of the data to be updated to the second preset value.

[0012] A second aspect of this application provides a data processing apparatus, comprising: a generation unit for generating a key name in response to a data query request; a verification unit for verifying cached data based on the version number of the cached data if cached data matching the key name is obtained from a first preset library; and a processing unit for deserializing the cached data based on the serialization type of the cached data if the cached data passes the verification, thereby obtaining response data corresponding to the data query request.

[0013] A third aspect of this application provides an electronic device, the electronic device comprising: a memory for storing computer-readable instructions; and a processor for executing the computer-readable instructions stored in the memory to implement the data processing method.

[0014] A fourth aspect of this application provides a computer-readable storage medium storing computer-readable instructions, which are executed by a processor in an electronic device to implement the data processing method.

[0015] In several embodiments of this application, when cached data matching the key name is obtained from a first preset library, the cached data is verified using its version number. This prevents the inability to obtain correct data due to outdated data in the preset library. After the cached data passes verification, it is deserialized based on its serialization type to ensure that correct response data is obtained. Attached Figure Description

[0016] Figure 1 This is a schematic diagram illustrating an application scenario of the data processing method provided in an embodiment of this application.

[0017] Figure 2 This is a flowchart of a data processing method provided in an embodiment of this application.

[0018] Figure 3 This is a flowchart of a data processing method provided in another embodiment of this application.

[0019] Figure 4 This is a flowchart of a data processing method provided in another embodiment of this application.

[0020] Figure 5 This is a timing diagram of a data processing method provided in an embodiment of this application.

[0021] Figure 6 This is a functional block diagram of a data processing apparatus provided in an embodiment of this application.

[0022] Figure 7 This is a schematic diagram of the structure of an electronic device that implements a data processing method according to an embodiment of this application. Detailed Implementation

[0023] To make the objectives, technical solutions, and advantages of this application clearer, the application will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0024] It should be noted that in this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and drawings of this application are used to distinguish similar objects, not to describe a specific order or sequence.

[0025] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Unless otherwise specified, the following embodiments and features described herein can be combined with each other.

[0026] To ensure users can quickly retrieve the data they need, data from the database is typically stored in a cache. However, if data in the database is not updated to the cache in a timely manner, or if outdated data is written to the cache due to concurrent operations, users will be unable to retrieve the correct data.

[0027] Based on this, embodiments of this application provide a data processing method. When cached data is obtained from a first preset library, the cached data is validated to avoid the inability to obtain correct data due to outdated data in the preset library. After the cached data passes validation, it is deserialized based on its serialization type to ensure that the correct response data is obtained.

[0028] like Figure 1 The diagram shown is an application scenario illustration of a data processing method provided in an embodiment of this application.

[0029] In this embodiment, the data processing method is applied to one or more electronic devices 100. Each electronic device 100 may have a built-in first preset library 10 (also called a "cache"). The first preset library 10 can store cached data, which can be stored in key-value pairs. For example, the data structure of cached data key(data)=key1 can be key1: {v:10,t:'json',d:'{"id":1,"name":"test"}'}. Alternatively, the data structure of cached data key(data)=key1 can also be key1_ver:10.

[0030] Electronic device 100 can be connected to second preset library 200. Electronic device 100 can communicate with second preset library 200 through a network. The network can be a wireless network or a wired network. Wireless networks include, but are not limited to: cellular network, wireless Fidelity (Wi-Fi), infrared network or Bluetooth network. Wired networks include, but are not limited to: Ethernet, universal serial bus (USB) or controller area network.

[0031] The electronic device 100 communicates with the second preset library 200, which can store user information and other data in the second preset library 200. The electronic device 100 can also determine the cached data that matches the data query request from the second preset library 200. The data query request can be triggered by the user.

[0032] In this application embodiment, the electronic device 100 is a device capable of executing computer-readable instructions to automatically perform numerical calculations and / or information processing. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0033] Electronic device 100 can be any electronic product that can interact with a user, such as personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.

[0034] Electronic device 100 may include network devices and / or user devices. Among them, network devices include, but are not limited to, a single network electronic device, a group of electronic devices consisting of multiple network electronic devices, or a cloud based on cloud computing consisting of a large number of hosts or network electronic devices.

[0035] In this embodiment, the second preset library 200 can be an external database of the electronic device 100 (e.g., cloud storage), or it can be a built-in database of the electronic device 100. For example, the second preset library 200 may be built into the storage device of the electronic device 100.

[0036] It should be noted that, Figure 1 The number and connection relationships of the various devices are merely illustrative examples and do not constitute a limitation on the embodiments of this application.

[0037] like Figure 2 The diagram shown is a flowchart of a data processing method provided in an embodiment of this application. The order of the steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements. The data processing method provided in this embodiment includes the following steps.

[0038] S201, respond to the data query request and generate key names.

[0039] In at least one embodiment of this application, a user can operate on a client installed in an electronic device, and the electronic device generates a corresponding data query request based on the user's operation. In this embodiment, the data query request can be a data query request generated by the electronic device using a database operation language to access data in a database, based on the user's operation on the client and business processing logic; for example, the electronic device can generate a data query request based on a structured query statement. The data query request can carry parameter information such as the table and fields that the user expects to query. For example, the data query request can carry the user identifier of the target user that the user expects to query. Another example is that the data query request can carry the version number corresponding to the data that the user expects to query.

[0040] In at least one embodiment of this application, the electronic device obtains parameter information from a data query request. The parameter information may include, but is not limited to, the data version number of the data to be queried and the user identifier of the data to be queried. The electronic device can generate key names based on the parameter information.

[0041] In this embodiment, the electronic device can concatenate parameter information and use the concatenated string as a key name. For example, assuming the user identifier of the data to be queried is 1, the key name can be key1. Or, assuming the parameter information includes the user identifier 1 and the version number of the data to be queried, the key name can be key1_ver.

[0042] In this embodiment of the application, the information that the user expects to query can be obtained through the parameter information in the data query request, and then the key name can be directly generated through the parameter information.

[0043] S202, if cached data matching the key name is obtained from the first preset library, the cached data is verified based on the version number of the cached data.

[0044] In at least one embodiment of this application, to ensure that users can quickly retrieve relevant data, the electronic device may have a built-in first preset library. The data stored in the first preset library may have a hash structure, and the storage information of the first preset library may include, but is not limited to, the data version number, the data serialization type, and the serialized data. The data serialization type may include, but is not limited to, JSON, Protobuf, etc. For example, the data stored in the first preset library may be represented as key1: {v:10,t:'json',d:'{“id”:1,“name”:“test”}'}. The data stored in the first preset library may also have a string structure, and the storage information of the first preset library may include, but is not limited to, the data version number. For example, the data stored in the first preset library may be represented as key1_ver:10.

[0045] In at least one embodiment of this application, the electronic device can retrieve data matching the key name from a first preset library as cached data. For example, the electronic device can retrieve cached data {v:10,t:'json',d:'{“id”:1,“name”:“test”}'} from the first preset library based on the key name key1.

[0046] In at least one embodiment of this application, in order to ensure that the correct data is obtained, the electronic device may verify the cached data based on the version number of the cached data.

[0047] In this embodiment, a configuration value can be set to verify cached data. This configuration value can be set and adjusted according to actual needs; for example, it can be set to 0. The electronic device can compare the version number of the cached data with the configuration value. If the version number of the cached data is less than or equal to the configuration value, it can be determined that the cached data has failed verification. If the version number of the cached data is greater than the configuration value, it can be determined that the cached data has passed verification. This embodiment of the application can quickly detect whether cached data has passed verification by comparing the version number of the cached data with the configuration value.

[0048] In at least one embodiment of this application, if cached data fails verification, a prompt message can be generated based on a comparison between the version number of the cached data and the configuration value.

[0049] In one example, if the version number of cached data is less than the configured value, the electronic device can generate a prompt message indicating that the cached data has been deleted from the first preset library.

[0050] In another example, if the version number of the cached data equals the configuration value, the prompt message generated by the electronic device can indicate that no cached data is stored in the first preset library. This application embodiment can also determine the reason why the cached data failed verification by comparing the version number of the cached data with the configuration value, so that the user can perform data analysis.

[0051] S203, if the cached data passes the verification, deserialize the cached data based on its serialization type to obtain the response data corresponding to the data query request.

[0052] In at least one embodiment of this application, if the cached data passes the verification, in order to obtain more accurate response data, the electronic device can perform deserialization processing on the cached data based on the serialization type of the cached data to obtain the response data corresponding to the data query request.

[0053] During the deserialization process of cached data, the electronic device can determine the deserialization rules corresponding to the serialization type, and based on the deserialization rules, perform deserialization on the cached data to obtain the response data.

[0054] This application embodiment uses the deserialization rules corresponding to the serialization type to deserialize cached data, which can avoid the inability to obtain accurate response data due to format errors, thereby ensuring the accuracy of the response data.

[0055] In several embodiments of this application, when cached data matching the key name is obtained from the first preset library, the cached data is verified using its version number. This prevents the inability to obtain correct data due to outdated data in the preset library. After the cached data passes verification, it is deserialized based on its serialization type to ensure that the correct response data is obtained.

[0056] like Figure 3 The diagram shown is a flowchart of a data processing method according to another embodiment of this application. The order of the steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements. The data processing method provided in this embodiment includes the following steps.

[0057] S301 responds to data query requests and generates key names.

[0058] For details of step S301, please refer to the above text. Figure 2 The detailed description of step S201 is provided in the previous text and will not be repeated here.

[0059] S302, Check whether cached data matching the key name has been obtained from the first preset library.

[0060] In at least one embodiment of this application, if the first preset library stores cached data matching the key name, it is determined that the electronic device can obtain the cached data matching the key name from the first preset library. In this case, the electronic device executes step S303. If the first preset library does not store cached data matching the key name, it is determined that the electronic device cannot obtain the cached data matching the key name from the first preset library. In this case, the electronic device executes step S305.

[0061] If cached data matching the key name is obtained from the first preset library, in S303, the cached data is verified based on the version number of the cached data.

[0062] S304 If the cached data passes the verification, deserialize the cached data based on its serialization type to obtain the response data corresponding to the data query request.

[0063] For details of steps S303-S304, please refer to the above text. Figure 2 The detailed description of steps S202-S203 is not repeated here.

[0064] If cached data matching the key name cannot be obtained from the first preset library, in S305, it is checked whether the field length of the key name is greater than the preset length.

[0065] In at least one embodiment of this application, to avoid invalid queries on key names, a preset length can be set. The preset length can be set and adjusted according to actual needs; for example, the preset length can be set to 0. The electronic device compares the field length of the key name with the preset length. If the field length of the key name is equal to the preset length, step S306 is executed; if the field length of the key name is greater than the preset length, step S307 is executed.

[0066] S306, Do not perform data queries on key names.

[0067] In at least one embodiment of this application, when the field length of the key name is equal to the preset length, the key name can be represented as an empty field. In order to avoid invalid queries on the key name, data queries can be performed directly without querying the key name.

[0068] S307: Lock the key name using a preset thread, and determine the first thread from the preset threads based on the locking result of the key name.

[0069] In at least one embodiment of this application, in order to improve data processing efficiency, the electronic device may use multiple preset threads to perform data processing operations. For example, thread A may be used to perform a data query operation, thread B may be used to perform another data query operation, and thread C may be used to perform a data write operation. This application does not impose any specific limitations on this.

[0070] In at least one embodiment of this application, to avoid resource waste caused by multiple preset threads simultaneously performing data query operations on the same key name, the electronic device can utilize preset threads to lock the key name and obtain the locking result of the preset threads. Based on the locking result of the key name, the electronic device determines a first thread from the preset threads, and the first thread is the thread that successfully locked the key name.

[0071] For example, the preset threads include thread A, thread B, and thread C. Threads A, B, and C can simultaneously acquire the lock on key1. Assuming that thread A successfully acquires the lock on key1, while thread B and C fail to acquire the lock, then thread A can be designated as the first thread.

[0072] In at least one embodiment of this application, the electronic device can determine a second thread from a preset set of threads based on the locking result of the key name. The second thread is the thread that failed to lock the key name. Continuing with the above example, the electronic device can use thread B and thread C as the second thread.

[0073] S308 uses the first thread to retrieve uncached data matching the key name from the second preset library as response data.

[0074] In at least one embodiment of this application, the electronic device can communicate with a second preset library, which can be an external database of the electronic device, for example, an external storage device of the electronic device.

[0075] In at least one embodiment of this application, the electronic device can invoke a first thread to retrieve uncached data matching the key name from a second preset library as response data. By invoking the first thread that successfully locks the key name to retrieve response data from the second preset library, this embodiment avoids multiple threads querying the same key name, thereby saving resources.

[0076] In at least one embodiment of this application, if no uncached data matching the key name can be obtained from the second preset library, the electronic device sends a prompt message. The prompt message is used to indicate that the version number corresponding to the key name is the initial value. The initial value can be set to 0. This application does not limit the setting of the initial value.

[0077] S309, Check whether the version number corresponding to the uncached data meets the preset conditions.

[0078] In at least one embodiment of this application, the electronic device can also obtain the version number corresponding to the uncached data and detect whether the version number corresponding to the uncached data meets a preset condition.

[0079] In this embodiment, a preset version number can be set. The preset version number can be set according to the latest version of the data in the first preset library. The preset version number can also be set according to actual needs, and this application does not impose specific restrictions on it. If the version number corresponding to the uncached data is greater than or equal to the preset version number, it is determined that the version number corresponding to the uncached data meets the preset condition. If the version number corresponding to the uncached data is less than the preset version number, or the version number corresponding to the uncached data is less than the configured value, it is determined that the version number corresponding to the uncached data does not meet the preset condition.

[0080] In at least one embodiment of this application, if the version number corresponding to the uncached data meets the preset conditions, step S310 is executed; if the version number corresponding to the uncached data does not meet the preset conditions, step S311 is executed.

[0081] S310, store the uncached data, the version number corresponding to the uncached data, and the serialization type into the first preset library.

[0082] In at least one embodiment of this application, uncached data, the version number corresponding to the uncached data, and the serialization type are encapsulated, and the encapsulated data is stored in a first preset library. In this embodiment, the encapsulated data can be represented as key1: {v:10,t:'json',d:'{“id”:1,“name”:“test”}'}.

[0083] In at least one embodiment of this application, after storing the uncached data in a first preset library, a first thread in the electronic device can send a preset broadcast message to a second thread. The preset broadcast message is used to indicate that the uncached data has been successfully stored in the first preset library.

[0084] In at least one embodiment of this application, the electronic device can retrieve data matching the key name from a first preset library based on preset broadcast information received by the second thread or based on a preset time interval. The preset time interval can be set and adjusted according to actual needs, and this application does not impose any restrictions on it. This embodiment of the application can retrieve data matching the key name from the first preset library after receiving the preset broadcast information or after a preset time interval, ensuring that only one thread performs data query at a time, preventing cache avalanche. Furthermore, the second thread can also quickly obtain data matching the key name.

[0085] S311 does not store uncached data.

[0086] In at least one embodiment of this application, if the version number corresponding to the uncached data does not meet the preset conditions, it can be determined that the uncached data is outdated data. Therefore, the electronic device does not store the uncached data, thereby avoiding pollution of the first preset library.

[0087] In several embodiments of this application, when cached data matching the key name is retrieved from the first preset library, the cached data is validated using its version number. This prevents the inability to retrieve correct data due to outdated data in the preset library. After the cached data passes validation, it is deserialized based on its serialization type to ensure the correct response data is retrieved. If cached data matching the key name cannot be retrieved from the first preset library, and the field length of the key name is greater than a preset length, the thread that successfully locks the key name retrieves uncached data matching the key name from the second preset library as response data. This ensures that only the first thread executes data queries at any given time, resolving the cache avalanche problem. When the version number corresponding to the uncached data meets a preset condition, storing the uncached data, its version number, and serialization type in the first preset library effectively prevents outdated data from being written to the first preset library, thus preventing the first preset library from being contaminated. During the process of storing uncached data in the first preset library, the serialization type is also stored in the first preset library, which can easily expand to multiple serialization methods.

[0088] like Figure 4 The diagram shown is a flowchart of a data processing method according to another embodiment of this application. The order of the steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements. The data processing method provided in this embodiment includes the following steps.

[0089] S401, respond to the data update request and obtain the version number of the data to be updated in the data update request.

[0090] In at least one embodiment of this application, the data update request can be an update request generated for data that currently needs to be updated. The data update request can be used to request an update to the current data to be updated. The data update request can carry the key name of the data to be updated, the data to be updated, and the version number of the data to be updated.

[0091] S402, Check if the version number of the data to be updated is the first preset value.

[0092] In at least one embodiment of this application, in order to detect the update type of the data to be updated in the data update request, a first preset value can be set. The first preset value can be set to an integer value less than 0, for example, the first preset value can be set to -1.

[0093] In at least one embodiment of this application, if the version number of the data to be updated is a first preset value, it can be indicated that the update type of the data to be updated is a deletion type. In this case, step S403 is executed; if the version number of the data to be updated is not a first preset value, it can be indicated that the update type of the data to be updated is not a deletion type. In this case, step S404 is executed.

[0094] S403, Delete the data to be updated from the first preset library.

[0095] In at least one embodiment of this application, the electronic device deletes the data to be updated from a first preset library and updates the version number of the data to be updated to a first preset value in the first preset library.

[0096] S404, if the version number of the data to be updated is greater than the second preset value, update the corresponding data in the first preset library based on the data to be updated, and update the version number of the data to be updated to the second preset value.

[0097] In at least one embodiment of this application, to further detect the update type of the data to be updated, a second preset value can be set, which can be set to the latest version number of the data in the first preset library. When the version number of the data to be updated is greater than the second preset value, it indicates that the update type of the data to be updated is a modification type. In this case, the electronic device updates the value corresponding to the key name of the data to be updated in the first preset library based on the data to be updated, and updates the version number of the data to be updated to the second preset value.

[0098] In several embodiments of this application, based on the version number of the data to be updated in the data update request, the update type of the data to be updated can be accurately determined, and the corresponding data in the first preset library can be updated, thereby improving the accuracy of the first preset library. Furthermore, after the data update is completed, updating the version number of the data to be updated in the first preset library ensures that outdated data becomes invalid, thus solving the problems caused by concurrent operations.

[0099] like Figure 5 The diagram shown is a timing diagram of a data processing method provided in an embodiment of this application. The order of steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements. The data processing method provided in this embodiment includes the following steps.

[0100] S501, the application thread of the electronic device receives data query requests sent by the user.

[0101] In at least one embodiment of this application, a user can operate on a client installed in an electronic device, and the electronic device can generate a user's data query request based on the user's operation. The application thread can also be referred to as a preset thread.

[0102] S502, the application thread responds to the data query request and generates the key name.

[0103] For details of step S502, please refer to the above text. Figure 2 The detailed description of step S201 is provided in the previous text and will not be repeated here.

[0104] In S503, the application thread uses the mget_cache script to retrieve cached data that matches the key name from the electronic device's cache.

[0105] In at least one embodiment of this application, the mget_cache script can be a Lua script, which can be used to retrieve cached data that matches the key name from the cache.

[0106] In this embodiment, the mget_cache script can carry a list of key names; for example, the mget_cache script can carry a list of KEYS. The application thread uses the GET command to retrieve cached data matching each key name in the key name list from the cache (also known as the first preset library). The electronic device can also use the GET command to retrieve the version number of the cached data from the cache.

[0107] S504, the cache verifies the cached data based on the version number of the cached data.

[0108] For details of step S504, please refer to the above text. Figure 2 The detailed description of step S202 is provided in the previous section and will not be repeated here.

[0109] S505: If the cached data passes the validation, the cached response data corresponding to the data query request is sent to the application thread.

[0110] In at least one embodiment of this application, if the cached data passes verification, it indicates that the cached data is not outdated or invalid. In this case, the cache can deserialize the cached data based on its serialization type to obtain the response data corresponding to the data query request. The method for deserializing the cached data can be found in the description of step S203. Furthermore, the cache can send the response data to the application thread.

[0111] S506, the application thread collects uncached key names.

[0112] In at least one embodiment of this application, "no cached key name" can mean "misskeys" which cannot be obtained from the first preset library and is related to cached data.

[0113] S507: When the length of a field with no cached key name is equal to the preset length, the application thread returns response data to the user.

[0114] In at least one embodiment of this application, in order to avoid invalid queries for non-cached key names, a preset field can be set. When the field length of the non-cached key name is equal to the preset length, it can be indicated that the non-cached key name does not contain any information. In this case, the application thread returns the received response data to the user.

[0115] S508: When the length of a field with an uncached key name is greater than a preset length, the application thread locks the uncached key name.

[0116] In at least one embodiment of this application, the method by which the application thread locks the uncached key name can be referred to Figure 3 The relevant description of step S307 will not be repeated here.

[0117] S509: The cached key name of the successfully locked key is returned to the application thread.

[0118] In at least one embodiment of this application, a successfully locked uncached key name can represent an uncached key name locked by any thread in the application.

[0119] In S510, the first thread in the application thread that successfully locks an uncached key name retrieves the uncached data matching the uncached key name from the database as the response data.

[0120] In at least one embodiment of this application, the method for determining the first thread can be referred to Figure 3 The description of step S307 will not be repeated here. The method by which the first thread retrieves uncached data matching the uncached key name from the database (also known as the second preset database) can be found in [reference needed]. Figure 3 The relevant description of step S308 will not be repeated here.

[0121] S511, the database returns response data to the first thread.

[0122] In S512, the first thread uses the set_cache script to store uncached data that matches the uncached key name into the cache.

[0123] In at least one embodiment of this application, the set_cache script can be used to detect whether the version number corresponding to the uncached data meets a preset condition. If the version number corresponding to the uncached data meets the preset condition, the first thread can store the uncached data, the version number corresponding to the uncached data, and the serialization type in a first preset library.

[0124] In at least one embodiment of this application, after the uncached data is stored in the cache, the first thread can send a preset broadcast message to other threads in the application thread. The preset broadcast message is used to indicate that the uncached data has been successfully stored in the first preset library.

[0125] S513, based on the received preset broadcast information or based on the preset duration, the second thread in the application thread that failed to lock the uncached key name retrieves the data matching the uncached key name from the cache.

[0126] In at least one embodiment of this application, the method for determining the second thread can refer to... Figure 3 The description of step S307 is not repeated here. For the method by which the second thread retrieves data matching the non-cached key name from the cache, please refer to [reference needed]. Figure 3 The relevant description of step S310 will not be repeated here.

[0127] S514, the application thread merges all data retrieved from the cache.

[0128] In at least one embodiment of this application, the application thread can encapsulate all the data obtained from the cache to obtain merged data, which can be a data packet.

[0129] S515, the application thread returns the merged data to the user.

[0130] In at least one embodiment of this application, the application thread returns the merged data to the user in response to a data query request.

[0131] In several embodiments of this application, when cached data matching the key name is retrieved from the cache, the cached data is validated using its version number. This prevents the inability to retrieve correct data due to outdated data in the cache. After the cached data passes validation, it is deserialized based on its serialization type to ensure that the correct response data is obtained. The application can collect non-cached key names that cannot be retrieved from the first preset library. If the field length of the non-cached key name is greater than a preset length, the first thread that successfully locks the non-cached key name retrieves the non-cached data matching the non-cached key name from the database as the response data. This ensures that only the first thread executes the data query at any given time, solving the cache avalanche problem. When the version number corresponding to the non-cached data meets a preset condition, storing the non-cached data, its version number, and serialization type in the cache effectively prevents outdated or invalid data from being written to the cache, thus avoiding cache pollution. In the process of storing uncached data in the cache, the serialization type is also stored in the cache, which can easily extend to multiple serialization methods.

[0132] like Figure 6 The diagram shown is a functional block diagram of a data processing apparatus provided in an embodiment of this application. The data processing apparatus 11 includes a generation unit 110, a verification unit 111, a processing unit 112, a detection unit 113, a determination unit 114, an acquisition unit 115, a storage unit 116, a sending unit 117, a deletion unit 118, and an update unit 119. The module / unit referred to in this application refers to a series of computer-readable instruction segments that can be acquired by the processor 1101 and perform a fixed function, and which are stored in the memory 1102.

[0133] In one embodiment, the generation unit 110 is used to generate a key name in response to a data query request; the verification unit 111 is used to verify the cached data based on the version number of the cached data if cached data matching the key name is obtained from the first preset library; and the processing unit 112 is used to deserialize the cached data based on the serialization type of the cached data if the cached data passes the verification, so as to obtain the response data corresponding to the data query request.

[0134] In one embodiment, the detection unit 113 is used to detect whether the field length of the key name is greater than a preset length if cached data matching the key name cannot be obtained from the first preset library; the determination unit 114 is used to lock the key name using a preset thread if the field length of the key name is greater than the preset length, and to determine the first thread from the preset threads based on the locking result of the key name, wherein the first thread is the thread that successfully locked the key name; and the acquisition unit 115 is used to acquire uncached data matching the key name from the second preset library as response data using the first thread.

[0135] In one embodiment, after obtaining uncached data matching the key name from the second preset library, the storage unit 116 is used to store the uncached data, the version number corresponding to the uncached data, and the serialization type into the first preset library if the version number corresponding to the uncached data meets the preset conditions.

[0136] In one embodiment, the determining unit 114 is further configured to determine a second thread from a preset thread based on the locking result of the key name, wherein the second thread is the thread that failed to lock the key name; the obtaining unit 115 is further configured to obtain data matching the key name from a first preset library based on the preset broadcast information received by the second thread or based on a preset duration.

[0137] In one embodiment, the sending unit 117 is used to send a prompt message if no uncached data matching the key name can be obtained from the second preset library. The prompt message is used to indicate that the version number corresponding to the key name is the initial value.

[0138] In one embodiment, the generation unit 110 is specifically used for: obtaining parameter information from a data query request; and generating a key name based on the parameter information.

[0139] In one embodiment, the processing unit 112 is specifically used to: determine the deserialization rule corresponding to the serialization type; and perform deserialization processing on the cached data based on the deserialization rule to obtain response data.

[0140] In one embodiment, the acquisition unit 115 is further configured to respond to a data update request and acquire the version number of the data to be updated in the data update request; the deletion unit 118 is configured to delete the data to be updated from the first preset library if the version number of the data to be updated is a first preset value; and the update unit 119 is configured to update the corresponding data in the first preset library based on the data to be updated if the version number of the data to be updated is greater than a second preset value, and update the version number of the data to be updated to the second preset value.

[0141] In several embodiments of this application, when cached data matching the key name is obtained from the first preset library, the cached data is verified using its version number. This prevents the inability to obtain correct data due to outdated data in the preset library. After the cached data passes verification, it is deserialized based on its serialization type to ensure that the correct response data is obtained.

[0142] like Figure 7 The diagram shown is a schematic representation of the structure of an electronic device implementing a data processing method according to an embodiment of this application. Optionally, Figure 7 The electronic device 100 shown is used to perform Figures 2-5 The method shown.

[0143] The electronic device 100 includes at least one processor 1101, a memory 1102, and at least one network interface 1103.

[0144] Processor 1101 may be, for example, a general-purpose central processing unit (CPU), a network processor (NP), a graphics processing unit (GPU), a neural-network processing unit (NPU), a data processing unit (DPU), a microprocessor, or one or more integrated circuits for implementing the embodiments of this application. For example, processor 1101 may include an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. A PLD may be, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0145] Memory 1102 may be, for example, read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions; random access memory (RAM) or other types of dynamic storage devices capable of storing information and instructions; electrically erasable programmable read-only memory (EEPROM); compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed discs, laser discs, optical discs, digital universal discs, Blu-ray discs, etc.); magnetic disk storage media or other magnetic storage devices; or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Optionally, memory 1102 exists independently and is connected to processor 1101 via internal connection 1104. Alternatively, memory 1102 and processor 1101 may be integrated together.

[0146] Network interface 1103 uses any transceiver-like device for communicating with other devices or communication networks. Network interface 1103 includes at least one of a wired network interface or a wireless network interface. The wired network interface is, for example, an Ethernet interface. The Ethernet interface is, for example, an optical interface, an electrical interface, or a combination thereof. The wireless network interface is, for example, a wireless local area network (WLAN) interface, a cellular network interface, or a combination thereof.

[0147] In some embodiments, processor 1101 includes one or more CPUs, such as Figure 7 CPU0 and CPU1 are shown in the diagram.

[0148] In some embodiments, the electronic device 100 may optionally include a plurality of processors, such as Figure 7 The processors 1101 and 1105 shown are illustrated. Each of these processors is, for example, a single-core processor (CPU) or a multi-core processor (CPU). Here, "processor" may optionally refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0149] In some embodiments, the electronic device 100 further includes an internal connection 1104. The processor 1101, memory 1102, and at least one network interface 1103 are connected via the internal connection 1104. The internal connection 1104 includes pathways for transmitting information between the aforementioned components. Optionally, the internal connection 1104 is a single board or a bus. Optionally, the internal connection 1104 may be divided into an address bus, a data bus, a control bus, etc.

[0150] In some embodiments, the electronic device 100 further includes an input / output interface 1106. The input / output interface 1106 is connected to the internal connection 1104.

[0151] Optionally, the processor 1101 implements the method in the above embodiments by reading the program code 910 stored in the memory 1102, or the processor 1101 implements the method in the above embodiments by internally stored program code. When the processor 1101 implements the method in the above embodiments by reading the program code 910 stored in the memory 1102, the memory 1102 stores program code that implements the method provided in the embodiments of this application.

[0152] For more details on how processor 1101 implements the above functions, please refer to the descriptions in the previous method embodiments, which will not be repeated here.

[0153] This embodiment also provides a computer storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the aforementioned method steps to implement the data processing method described in the above embodiment.

[0154] This embodiment also provides a computer program product that, when run on an electronic device, causes the electronic device to perform the aforementioned related steps to implement the data processing method described in the above embodiment.

[0155] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the data processing methods in the above-described method embodiments.

[0156] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.

[0157] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0158] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0159] The unit described as a separate component may or may not be physically separate. The component shown as a unit can be one physical unit or multiple physical units, that is, it can be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of the solution in this embodiment according to actual needs.

[0160] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0161] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of 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.

[0162] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A data processing method, characterized in that, The method includes: Respond to data query requests and generate key names; If cached data matching the key name is obtained from the first preset library, the cached data is verified based on the version number of the cached data; If the cached data passes the verification, the cached data is deserialized based on its serialization type to obtain the response data corresponding to the data query request.

2. The data processing method according to claim 1, characterized in that, The method further includes: If no cached data matching the key name can be obtained from the first preset library, check whether the field length of the key name is greater than the preset length. If the field length of the key name is greater than the preset length, the key name is locked using a preset thread, and based on the locking result of the key name, a first thread is determined from the preset threads, the first thread being the thread that successfully locked the key name; Using the first thread, uncached data matching the key name is retrieved from the second preset library as the response data.

3. The data processing method according to claim 2, characterized in that, After retrieving uncached data matching the key name from the second preset library, the method further includes: If the version number corresponding to the uncached data meets the preset conditions, the uncached data, the version number corresponding to the uncached data, and the serialization type are stored in the first preset library.

4. The data processing method according to claim 2 or 3, characterized in that, The method further includes: Based on the locking result of the key name, a second thread is determined from the preset threads. The second thread is the thread that failed to lock the key name. Based on the preset broadcast information received by the second thread, or based on the preset duration, data matching the key name is retrieved from the first preset library.

5. The data processing method according to any one of claims 2 to 3, characterized in that, The method further includes: If no uncached data matching the key name can be obtained from the second preset library, a prompt message is sent, which indicates that the version number corresponding to the key name is the initial value.

6. The data processing method according to claim 1, characterized in that, The generated key name includes: Obtain parameter information from the data query request; The key name is generated based on the parameter information.

7. The data processing method according to claim 1, characterized in that, The step of deserializing the cached data based on its serialization type to obtain the response data corresponding to the data query request includes: Determine the deserialization rules corresponding to the serialization type; Based on the deserialization rules, the cached data is deserialized to obtain the response data.

8. The data processing method according to claim 1, characterized in that, The method further includes: In response to a data update request, obtain the version number of the data to be updated in the data update request; If the version number of the data to be updated is a first preset value, delete the data to be updated from the first preset library; If the version number of the data to be updated is greater than the second preset value, based on the data to be updated, update the corresponding data in the first preset library, and update the version number of the data to be updated to the second preset value.

9. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the data processing method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor of an electronic device, implement the data processing method as described in any one of claims 1 to 8.