Methods, apparatus, electronic devices and storage media for caching data

By differentiating between hot and non-hot data in the caching system and adopting a distributed caching architecture and mapping table, the system instability caused by excessive load on the caching middleware was resolved, achieving fast response and efficient management.

CN115687422BActive Publication Date: 2025-12-02SHENZHEN FULIN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211343028.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-28
Publication Date
2025-12-02
Estimated Expiration
2042-10-28

AI Technical Summary

Technical Problem

In existing caching systems, caching middleware is prone to failure due to excessive load when faced with a large number of simultaneous accesses of both hot and non-hot data, leading to system instability.

Method used

By receiving client requests, the system determines whether the data to be queried is hot or non-hot data, and adopts different caching strategies based on different data types: hot data is randomly queried from cache servers, while non-hot data is queried from multiple cache servers in a round-robin fashion. Data management is carried out by combining a distributed caching architecture and a mapping table.

Benefits of technology

It improves system stability and response efficiency, avoids the problem of excessive load on a single cache server, and enables rapid response to hot data and efficient management of non-hot data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115687422B_ABST
    Figure CN115687422B_ABST
Patent Text Reader

Abstract

This invention relates to the field of data processing and discloses a data caching method, comprising: receiving a request from a client to query data; obtaining a cache key containing the data to be queried in the request; determining whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key; if the data to be queried is determined to be hot data, querying a random cache server based on a first timestamp of the cache key to determine whether the data to be queried has expired, thereby responding to the request; if the data to be queried is determined to be non-hot data, polling each cache server in a round-robin fashion to determine whether the data to be queried has expired, thereby responding to the request. This invention also provides a data caching device, an electronic device, and a storage medium. This invention achieves point-to-point caching, improving the stability of the entire system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing, and more particularly to a method, apparatus, electronic device, and storage medium for caching data. Background Technology

[0002] Existing caching systems include: a database (server-side), a caching middleware (e.g., Redis, Ehcache, etc.), and multiple clients. Typically, the database pre-caches the latest version of the data from the data provider in a single caching middleware. When a client needs to query the latest version of the data, it can directly query the caching middleware.

[0003] However, the above query method can only satisfy a small number of requests accessing the cache middleware at the same time. As people obtain information faster and faster, many hot news or hot data will be generated on the Internet. When faced with a large number of hot data and non-hot data accessing the cache middleware at the same time, the cache middleware is prone to failure due to excessive access load, which will lead to the instability of the entire system. Summary of the Invention

[0004] In view of the above, it is necessary to provide a data caching method, the purpose of which is to solve the problem that the existing caching middleware is prone to failure due to excessive access load, which leads to the instability of the entire system.

[0005] The data caching method provided by this invention includes:

[0006] Receive a request from a client to query data, and obtain the cache key containing the data to be queried in the request;

[0007] Based on the data identifier of the cache key, determine whether the data to be queried is hot data or non-hot data;

[0008] If the data to be queried is determined to be hot data, then a random cache server is queried to check whether the data to be queried has expired based on the first timestamp of the cache key, in order to complete the response to the request;

[0009] If it is determined that the data to be queried is non-hot data, then the cache servers are polled in a round-robin fashion according to the first timestamp to determine whether the data to be queried has expired, so as to complete the response to the request.

[0010] Optionally, before determining whether the data to be queried is hot or non-hot data based on the data identifier of the cache key, the method further includes:

[0011] According to the preset caching strategy, all data in the preset database are classified to obtain the classification results, which include: hot data and non-hot data.

[0012] Optionally, after classifying all the data in the preset database and obtaining the classification results, the method further includes:

[0013] Establish a first mapping table between the data identifier of each data item in the database and the classification result;

[0014] Based on the first mapping table and the data identifier of the data to be queried, determine whether the data to be queried is hot data or non-hot data.

[0015] Optionally, the data caching method further includes:

[0016] Each hot data point is pre-synchronized and stored on a separate cache server;

[0017] The storage type of each cache server is pre-defined based on the cache key of each non-hot data, and each non-hot data is stored in the cache server of the corresponding storage type.

[0018] Optionally, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0019] A10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0020] A20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0021] A30. If the cache server stores the target data, then the target data is returned to the client.

[0022] Optionally, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0023] B10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0024] B20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0025] B30. If the cache server does not store the target data, then the distributed caching component of the cache server is used to request the database to construct the target data in the cache server.

[0026] B40. Return the constructed target data to the client.

[0027] Optionally, the step of polling each cache server for the expired data based on the first timestamp to complete the response to the request is replaced by the following steps:

[0028] The cache server corresponding to the data to be queried is determined based on the first timestamp of the data to be queried and the second mapping table established with the pre-determined cache server.

[0029] The system queries the cache server to determine whether the data to be queried has expired, thus completing the response to the request.

[0030] To address the above problems, the present invention also provides a data caching device, the device comprising:

[0031] The receiving module is used to receive a request from the client to query data and obtain the cache key containing the data to be queried in the request;

[0032] The judgment module is used to determine whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key;

[0033] The hotspot processing module is used to query a random cache server based on the first timestamp of the cache key to determine whether the data to be queried is hot data, so as to complete the response to the request.

[0034] The non-hotspot processing module is used to, if it is determined that the data to be queried is non-hotspot data, poll each cache server in turn to see if the data to be queried has expired based on the first timestamp, so as to complete the response to the request.

[0035] To address the above problems, the present invention also provides an electronic device, the electronic device comprising:

[0036] At least one processor; and,

[0037] A memory communicatively connected to the at least one processor; wherein,

[0038] The memory stores a cached data program that can be executed by the at least one processor, the cached data program being executed by the at least one processor to enable the at least one processor to perform the cached data method described above.

[0039] To address the aforementioned problems, the present invention also provides a computer-readable storage medium storing a cached data program, which can be executed by one or more processors to implement the aforementioned cached data method.

[0040] Compared to existing technologies, this invention determines whether the data to be queried is hot or non-hot data by using the cache key of the data to be queried. This step accurately and quickly allocates cache servers to the data to be queried based on its data identifier. When the data to be queried is determined to be hot data, it queries a random cache server to see if the data has expired based on the first timestamp of the data. This step avoids all cached messages relying on a single cache server for transmission, enabling point-to-point caching and improving the stability of the entire system. When the data to be queried is determined to be non-hot data, it polls each cache server in turn to see if the data has expired based on the first timestamp of the data, achieving classified management of non-hot data and improving the efficiency of later maintenance. Attached Figure Description

[0041] Figure 1 This is a schematic diagram of the distributed caching system architecture for implementing the data caching method of the present invention;

[0042] Figure 2 This is a flowchart illustrating a data caching method provided in an embodiment of the present invention;

[0043] Figure 3 This is a schematic diagram of a cache data device provided in an embodiment of the present invention;

[0044] Figure 4 This is a schematic diagram of the structure of an electronic device that implements a data caching method according to an embodiment of the present invention;

[0045] The objectives, features, and advantages of this invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without inventive effort are within the scope of protection of this invention.

[0047] It should be noted that the descriptions involving "first," "second," etc., in this invention are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by this invention.

[0048] like Figure 1 The diagram shown is a schematic of the distributed caching system architecture for implementing the data caching method of the present invention.

[0049] The distributed caching system consists of at least one preset database (e.g., a relational database management system) and multiple cache servers, forming a distributed caching architecture. The database communicates with each cache server, and the client communicates with the cache server.

[0050] A relational database management system can refer to a MySQL database; a cache server refers to a stateless server that carries any business logic, and each cache server contains at least one distributed cache component (groupcache).

[0051] Group Cache is a distributed caching library that can replace the mem cached node pool in many scenarios. Unlike other commonly used cache implementations such as Redis, Group Cache does not run on a separate server, but rather as a library running in the same process as the application. Therefore, Group Cache is both a server and a client.

[0052] Compared to commonly used caching middleware (such as Varnish, Nginx, Squid, Memcache, Redis, Ehcache, and other databases), distributed caching components on caching servers offer lower overhead and near-memory access. Stateless servers are also much easier to scale than stateful caching middleware, avoiding single points of failure and the problem of hot data overwhelming the server.

[0053] This invention provides a method for caching data. (Refer to...) Figure 2 The diagram shown is a flowchart illustrating a data caching method according to an embodiment of the present invention. This method is executed by an electronic device.

[0054] In this embodiment, the data caching method includes:

[0055] S1. Receive a request from the client to query data, and obtain the cache key containing the data to be queried in the request.

[0056] In this embodiment, various application software can be installed on the client, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, management software, etc.

[0057] Typically, users interact with the proxy server's database via the network on the client side, or the client interacts with the proxy server's database through a caching middleware. Both of these data interaction methods can easily lead to instability of the entire system when the data access volume is large (e.g., high latency, increased database load, cache avalanche, hotspots, etc.).

[0058] To address these issues, the distributed caching architecture of this invention will be illustrated using an example of a user using management software on a client (this does not limit the application scope of this invention). When a user opens a new page of the management software on the client (e.g., creates a new work item), the configuration query program of the management software automatically sends a request to the cache server to query the data to be queried on that new page. The data to be queried on this new page refers to the current version of the management software stored on the client.

[0059] Typically, application software only requests data from the cache server once during initialization. Initialization occurs at the start of an application's lifecycle and happens only once per lifecycle. During initialization, the application obtains necessary global variables. A lifecycle refers to the period from when an application is launched until it terminates.

[0060] In one embodiment, the cache key includes a business configuration key, a first timestamp, and a data identifier. Before receiving a client request to query the data to be queried, the method further includes:

[0061] The request to obtain the numerical sequence of the business configuration key, the numerical sequence of the first timestamp, and the numerical sequence of the data identifier, package them, and write them into the data to be queried.

[0062] A business configuration key refers to the key-value information between the operation attribute information and the business instruction, which is predefined according to the operation attribute information of different businesses; a timestamp refers to the time elapsed since January 1, 1970 (midnight UTC / GMT). A timestamp is a complete and verifiable label that indicates that a piece of data existed before a specific time. It is usually a character sequence that uniquely identifies a moment in time; a data identifier refers to the identity ID that the database sets for each piece of data to be queried (for example, a data identifier of 1425789).

[0063] After each initialization, the application software packages the business configuration key, first timestamp, and data identifier of the existing version data and writes them into the request for the data to be queried, and sends it to the distributed caching system.

[0064] By including the cache key of the data to be queried in the request, which contains a timestamp that identifies the data at a specific point in time, the application software is guaranteed not to obtain expired data.

[0065] S2. Determine whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key.

[0066] In this embodiment, the database pre-identifies all data (including data from clients, cache servers, and the database itself), and then classifies all data into hot data and non-hot data after identification.

[0067] Database data updates can be caused by various factors. For example, changes in data from the data source (the application software provider) or manual data processing can alter the client's data (existing version), resulting in a new version of the client's data. Upon receiving a request, the distributed caching system retrieves the data identifier of the data to be queried and the corresponding first mapping table. Using the data identifier and the corresponding first mapping table, it can quickly determine whether the queried data is hot or non-hot data.

[0068] After classifying all the data, cache servers are accurately and quickly allocated to the data to be queried based on whether the data is hot or non-hot.

[0069] In one embodiment, before determining whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key, the method further includes:

[0070] According to the preset caching strategy, all data in the preset database are classified to obtain the classification results, which include: hot data and non-hot data.

[0071] The default caching strategy refers to the LRU algorithm, which stands for Least Recently Used. This means that we consider recently used data to be hot data and data that has not been used for a long time to be non-hot data. When memory is full, we prioritize deleting data that has not been used for a long time.

[0072] The LRU (Least Recently Used) algorithm filters data from the database that has been accessed more than or equal to a preset value (e.g., 1000 accesses within 48 hours), as well as data defined by the data provider or administrator, into "hot" data. The LRU algorithm also filters data from the database that has been accessed less than the preset value into "non-hot" data. Furthermore, in other embodiments, the LRU algorithm deletes non-hot data that has not been used for a preset time period (e.g., 4800 hours) to save memory space in the database and on various cache servers.

[0073] In one embodiment, after classifying all the data in the preset database and obtaining the classification results, the method further includes:

[0074] Establish a first mapping table between the data identifier of each data item in the database and the classification result;

[0075] Based on the first mapping table and the data identifier of the data to be queried, determine whether the data to be queried is hot data or non-hot data.

[0076] The data identifiers of each data are pre-associated with the corresponding hot or non-hot data and a first mapping relationship table is established. Through the first mapping relationship table, it is possible to quickly determine which data type the data to be queried belongs to, reduce the query time of the system to find out which cache server the data to be queried will be stored in, and improve the cache hit rate of the data to be queried.

[0077] In other embodiments, certain hot data can be redefined as non-hot data, or certain non-hot data can be redefined as hot data, by modifying the first mapping table, thereby achieving rapid switching of data types.

[0078] S3. If it is determined that the data to be queried is hot data, then query a random cache server according to the first timestamp of the cache key to see if the data to be queried has expired, so as to complete the response to the request.

[0079] In this embodiment, the data provider or administrator pre-stores the same hot data synchronously on each cache server, while non-hot data is stored only on a certain cache server. When the data identifier determines that the data to be queried is hot data, the request to query the data to be queried is randomly sent to any cache server. The cache server reads the first timestamp and business configuration key of the data to be queried in the request, and queries the target data (latest version) of the data to be queried from the preset database according to the first timestamp and business configuration key.

[0080] In this invention, the caching server queries the target data of the data to be queried from a preset database, and the following three query results will appear:

[0081] First type of query result:

[0082] In one embodiment, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0083] A10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0084] A20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0085] A30. If the cache server stores the target data, then the target data is returned to the client.

[0086] The process for the first type of query result is as follows: When the second timestamp of the target data (latest version) to be queried in the database is greater than the first timestamp of the data to be queried (the current version on the client), it means that the data to be queried has expired in the current version on the client. Based on the cache key of the target data, the current cache server (i.e., the cache server assigned to the request) is queried to see if the target data is stored. If the cache key of any data on the current cache server is consistent with the cache key of the target data (i.e., the timestamp, business configuration key, and data identifier are consistent), it means that the target data is stored in the current cache server, and the target data of the current cache server is returned to the client for updating.

[0087] The second type of query result:

[0088] In one embodiment, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0089] B10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0090] B20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0091] B30. If the cache server does not store the target data, then the distributed caching component of the cache server is used to request the database to construct the target data in the cache server.

[0092] B40. Return the constructed target data to the client.

[0093] The process for the second type of query result is as follows: the database query finds that the target data (latest version) is available. When the query finds that the current cache server (i.e., the cache server assigned to the request) does not store the target data, the current cache server needs to request the database to build the target data in the distributed caching component of the current cache server, and return the target data built by the cache layer to the client for updating.

[0094] The third type of query result:

[0095] In one embodiment, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0096] If the second timestamp of the target data stored in the database is found to be the same as the first timestamp of the data to be queried, it proves that the data to be queried has not expired, and an empty message is returned to the client.

[0097] The third type of query result process is as follows: When the second timestamp of the target data retrieved from the database is the same as the first timestamp of the data to be queried, it means that the current version of the data to be queried on the client has not expired, or that the database does not have the latest version of the data to be queried. The database returns an empty message to the client and ends the query request. By using the timestamp to determine that the current version of the data to be queried on the client has not expired, the server does not need to return redundant data when the data has not been updated.

[0098] Using the three query methods described above, when the database data is updated and a new version is available, a new timestamp (second timestamp) will be generated. The timestamp of the latest version data is larger than the timestamp of the existing version. The timestamp identifies data after a certain point in time, thus ensuring that expired data is not retrieved. It also ensures that any unique, incrementally increasing sequence number can be used in the database and provides time information when troubleshooting problems.

[0099] In one embodiment, the data caching method further includes:

[0100] C10. Pre-synchronize and store each hot data point to a separate cache server;

[0101] By using a distributed caching architecture composed of multiple caching servers, hot data is stored on each caching server, enabling point-to-point caching. As long as the data to be queried is determined to be hot data, the request is sent to a random caching server for querying, which can quickly respond to requests for hot data. This prevents the problem in existing technologies where middleware accesses a certain key very frequently, and when the key expires, a large number of threads are used to build the cache, leading to increased load and system crashes.

[0102] C20, and pre-classify the storage type of each cache server according to the cache key of each non-hot data, and store each non-hot data in the cache server of the corresponding storage type.

[0103] Based on the definition of the operation attribute information of different businesses according to the business configuration keys of each non-hot data, each cache server is divided into different storage types (e.g., creating a work item, editing a work item, viewing a work item, creating a test case, viewing a test case, etc.). Then, different non-hot data are classified and stored in the corresponding cache servers to realize the classified management of non-hot data and improve the efficiency of later maintenance.

[0104] The S3 step synchronizes and stores each hot data point to a separate cache server. The distributed caching architecture, composed of multiple cache servers, eliminates the middleware of existing technologies. In this architecture, multiple cache servers communicate with the database, and hot data is synchronized and stored in each cache server. This avoids the problem that all cached messages rely on message middleware for transmission, and the entire system will be paralyzed if the message middleware fails, thus improving system reliability.

[0105] S4. If it is determined that the data to be queried is non-hot data, then according to the first timestamp, poll each cache server to see if the data to be queried has expired, so as to complete the response to the request.

[0106] In this embodiment, when it is determined that the data to be queried is non-hot data based on the data identifier and the first mapping relationship table, the request will be polled to each cache server to find out which cache server stores the data to be queried. The cache server storing the data to be queried will read the first timestamp and business configuration key of the data to be queried, and query the target data (latest version) of the data to be queried from the preset database according to the first timestamp and business configuration key. The steps and processes of querying the target data (latest version) of the data to be queried are the same as those of the three query results mentioned above, so they will not be described again.

[0107] In one embodiment, step S4 of the data caching method is replaced by the following steps:

[0108] If it is determined that the data to be queried is non-hot data, then the cache server corresponding to the data to be queried is determined according to the second mapping relationship table established between the first timestamp and the pre-determined cache server;

[0109] The system queries the cache server to determine whether the data to be queried has expired, thus completing the response to the request.

[0110] The data provider or administrator pre-establishes a second mapping table between each non-hotspot data item and a pre-determined cache server, and pre-stores the non-hotspot data in the designated cache server. When the data to be queried is determined to be non-hotspot data based on the data identifier, the corresponding cache server is determined according to the second mapping table. This cache server reads the first timestamp and business configuration key of the data to be queried in the request, and queries the preset database for the latest version of the data to be queried based on the first timestamp and business configuration key. The steps and processes for obtaining the target data (latest version) of the data to be queried are the same as those for the three query results mentioned above, and therefore will not be described again.

[0111] The second mapping table can quickly identify the cache server corresponding to the data to be queried, greatly reducing query time and alleviating the load on the cache server.

[0112] In one embodiment, the data caching method further includes:

[0113] Receive a request from a client to update existing version data, the request containing the cache key of the existing version data;

[0114] The third timestamp of the cache key is updated to the fourth timestamp according to the timestamp service component of the cache server;

[0115] Based on the fourth timestamp and the business configuration key of the cache key, update the latest version corresponding to the existing version data stored in the preset database.

[0116] Users can edit the version of the data to be updated (the target data after installation) as needed (for example, modifying or deleting a work item in management software). Then, a third timestamp of the data to be updated is generated. The third timestamp of the data to be updated and the business configuration key are used to generate a request for updating the data and send it to the cache server that stores the target data. The timestamp service component of the cache server generates a fourth timestamp from the third timestamp in the request. The version of the data to be updated in the preset database is then updated based on the fourth timestamp of the data to be updated and the business configuration key.

[0117] Updating data within a transaction on the same cache server ensures that expired data is not retrieved when the cache is subsequently built based on the timestamp, while also ensuring that the data and timestamp are consistent, thus guaranteeing the correctness of the cached data.

[0118] like Figure 3 The diagram shown is a schematic representation of a data caching device according to an embodiment of the present invention.

[0119] The cached data device 100 of this invention can be installed in an electronic device. Depending on the functions implemented, the cached data device 100 may include a receiving module 110, a judging module 120, a hotspot processing module 130, and a non-hotspot processing module 140. The module described in this invention can also be called a unit, which refers to a series of computer program segments that can be executed by the processor of an electronic device and can perform a fixed function, and which are stored in the memory of the electronic device.

[0120] In this embodiment, the functions of each module / unit are as follows:

[0121] The receiving module is used to receive a request from the client to query data and obtain the cache key containing the data to be queried in the request.

[0122] The judgment module is used to determine whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key.

[0123] The hotspot processing module is used to, if it is determined that the data to be queried is hot data, query a random cache server based on the first timestamp of the cache key to see if the data to be queried has expired, so as to complete the response to the request.

[0124] The non-hotspot processing module is used to, if it is determined that the data to be queried is non-hotspot data, poll each cache server in turn to see if the data to be queried has expired based on the first timestamp, so as to complete the response to the request.

[0125] In one embodiment, before determining whether the data to be queried is hot data or non-hot data based on the data identifier of the cache key, the method further includes:

[0126] According to the preset caching strategy, all data in the preset database are classified to obtain the classification results, which include: hot data and non-hot data.

[0127] In one embodiment, after classifying all the data in the preset database and obtaining the classification results, the method further includes:

[0128] Establish a first mapping table between the data identifier of each data item in the database and the classification result;

[0129] Based on the first mapping table and the data identifier of the data to be queried, determine whether the data to be queried is hot data or non-hot data.

[0130] In one embodiment, the data caching method further includes:

[0131] Each hot data point is pre-synchronized and stored on a separate cache server;

[0132] The storage type of each cache server is pre-defined based on the cache key of each non-hot data, and each non-hot data is stored in the cache server of the corresponding storage type.

[0133] In one embodiment, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0134] A10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0135] A20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0136] A30. If the cache server stores the target data, then the target data is returned to the client.

[0137] In one embodiment, after querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes:

[0138] B10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database;

[0139] B20. Based on the cache key of the target data, query whether the cache server stores the target data;

[0140] B30. If the cache server does not store the target data, then the distributed caching component of the cache server is used to request the database to construct the target data in the cache server.

[0141] B40. Return the constructed target data to the client.

[0142] In one embodiment, the step of polling each cache server for the expired data based on the first timestamp to complete the response to the request is replaced by the following steps:

[0143] The cache server corresponding to the data to be queried is determined based on the first timestamp of the data to be queried and the second mapping table established with the pre-determined cache server.

[0144] The system queries the cache server to determine whether the data to be queried has expired, thus completing the response to the request.

[0145] like Figure 4 The diagram shown is a structural schematic of an electronic device that implements a data caching method according to an embodiment of the present invention.

[0146] In this embodiment, the electronic device 1 includes, but is not limited to, a memory 11, a processor 12, and a network interface 13 that can be interconnected via a system bus. The memory 11 stores a cached data program 10, which can be executed by the processor 12. Figure 3 Only the electronic device 1 having components 11-13 and the cache data program 10 is shown. Those skilled in the art will understand that... Figure 3 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0147] The memory 11 includes RAM and at least one type of readable storage medium. The RAM provides a cache for the operation of the electronic device 1; the readable storage medium can be a non-volatile storage medium such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the readable storage medium can be an internal storage unit of the electronic device 1; in other embodiments, the non-volatile storage medium can also be an external storage device of the electronic device 1, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device 1. In this embodiment, the readable storage medium of the memory 11 is typically used to store the operating system and various application software installed on the electronic device 1, such as storing the code of the cache data program 10 in one embodiment of the present invention. Furthermore, the memory 11 can also be used to temporarily store various types of data that have been output or will be output.

[0148] In some embodiments, processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. Processor 12 is typically used to control the overall operation of the electronic device 1, such as performing control and processing related to data interaction or communication with other devices. In this embodiment, processor 12 is used to run program code stored in memory 11 or process data, such as running cached data program 10.

[0149] The network interface 13 may include a wireless network interface or a wired network interface, which is used to establish a communication connection between the electronic device 1 and the terminal (not shown in the figure).

[0150] Optionally, the electronic device 1 may further include a user interface, which may include a display, an input unit such as a keyboard, and optionally, a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the electronic device 1 and to display a visual user interface.

[0151] It should be understood that the embodiments described are for illustrative purposes only and are not limited to this structure in the scope of the patent application.

[0152] The cached data program 10 stored in the memory 11 of the electronic device 1 is a combination of multiple instructions, which, when run in the processor 12, can achieve the following:

[0153] Receive a request from a client to query data, and obtain the cache key containing the data to be queried in the request;

[0154] Based on the data identifier of the cache key, determine whether the data to be queried is hot data or non-hot data;

[0155] If the data to be queried is determined to be hot data, then a random cache server is queried to check whether the data to be queried has expired based on the first timestamp of the cache key, in order to complete the response to the request;

[0156] If it is determined that the data to be queried is non-hot data, then the cache servers are polled in a round-robin fashion according to the first timestamp to determine whether the data to be queried has expired, so as to complete the response to the request.

[0157] Specifically, the processor 12's implementation method for the aforementioned cached data program 10 can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.

[0158] Furthermore, if the modules / units integrated in the electronic device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. The computer-readable medium can be non-volatile or non-combustible. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).

[0159] The computer-readable storage medium stores a cached data program 10, which can be executed by one or more processors. The specific implementation of the computer-readable storage medium of the present invention is basically the same as the embodiments of the cached data method described above, and will not be repeated here.

[0160] In the several embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0161] The modules described as separate components may or may not be physically separate. The components shown as modules 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.

[0162] Furthermore, the functional modules in the various embodiments of the present invention 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 in the form of hardware plus software functional modules.

[0163] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0164] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.

[0165] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a system claim may also be implemented by a single unit or device through software or hardware. The term "second class" is used to indicate names and does not indicate any specific order.

[0166] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. A method for caching data, characterized in that, The method includes: Each hot data point is pre-synchronized and stored in a separate cache server, and the storage type of each cache server is pre-classified according to the cache key of each non-hot data point, and each non-hot data point is stored in a cache server of the corresponding storage type. Receive a request from a client to query data, and obtain the cache key containing the data to be queried in the request; Based on the data identifier of the cache key, determine whether the data to be queried is hot data or non-hot data; If the data to be queried is determined to be hot data, then a random cache server is queried to check whether the data to be queried has expired based on the first timestamp of the cache key, in order to complete the response to the request; If it is determined that the data to be queried is non-hot data, then the cache servers are polled in a round-robin fashion according to the first timestamp to determine whether the data to be queried has expired, so as to complete the response to the request.

2. The data caching method as described in claim 1, characterized in that, Before determining whether the data to be queried is hot or non-hot data based on the data identifier of the cache key, the method further includes: According to the preset caching strategy, all data in the preset database are classified to obtain the classification results, which include: hot data and non-hot data.

3. The data caching method as described in claim 2, characterized in that, After classifying all the data in the preset database and obtaining the classification results, the method further includes: Establish a first mapping table between the data identifier of each data item in the database and the classification result; Based on the first mapping table and the data identifier of the data to be queried, determine whether the data to be queried is hot data or non-hot data.

4. The data caching method as described in claim 1, characterized in that, After querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes: A10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database; A20. Based on the cache key of the target data, query whether the cache server stores the target data; A30. If the cache server stores the target data, then the target data is returned to the client.

5. The data caching method as described in claim 1, characterized in that, After querying a preset database based on the first timestamp to determine whether the data to be queried corresponding to the first timestamp has expired, the method further includes: B10. If the data to be queried is found to be expired from the database, then obtain the cache key of the target data corresponding to the data to be queried in the database; B20. Based on the cache key of the target data, query whether the cache server stores the target data; B30. If the cache server does not store the target data, then the distributed caching component of the cache server is used to request the database to construct the target data in the cache server. B40. Return the constructed target data to the client.

6. The data caching method as described in claim 1, characterized in that, The step of polling each cache server for the data to be queried based on the first timestamp to complete the response to the request is replaced by the following steps, including: The cache server corresponding to the data to be queried is determined based on the first timestamp of the data to be queried and the second mapping table established with the pre-determined cache server. The system queries the cache server to determine whether the data to be queried has expired, thus completing the response to the request.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a cached data program that can be executed by the at least one processor, the cached data program being executed by the at least one processor to enable the at least one processor to perform the cached data method as described in any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a cached data program, which can be executed by one or more processors to implement the cached data method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • System and method for managing hotspot data

    CN113778660A

  • Data acquisition method based on local cache and distributed cache, and application server

    WO2022022105A1