Communication method, device, electronic device and storage medium
By sending request messages carrying indication information to the server during communication with electronic devices, instructing the server to return part of the data, the problem of difficulty in taking into account the real-time cached data and communication efficiency in the prior art is solved, and real-time data updates are realized and communication efficiency.
Patent Information
- Application Number
- CN202211073951.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-02
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-09-02
AI Technical Summary
It is difficult for existing electronic devices to take into account the real-time and communication efficiency of cached data during communication, resulting in low communication efficiency.
After confirming that the cached data with the data link is cached, a request message carrying indication information is sent to the server, instructing the server to return part of the data link corresponding to the request data, thereby updating the cached data, ensuring the real-timeness of data updates, and improving the Communication efficiency.
It realizes that while ensuring real-time data updates, the communication efficiency between electronic devices and servers is improved, and the waste of network resources caused by returning all data without updating is avoided, and the timeliness and communication efficiency of cached data is improved.
Smart Images

Figure CN115442440B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer data processing and network communication, and in particular, to a communication method, device, electronic device and storage medium. Background Art
[0002] At present, before an electronic device communicates, it is usually checked whether the cache data corresponding to the data link is already stored in the local cache. If the cache data corresponding to the data link is already stored in the local cache, no request message will be sent to the server, which makes it difficult to meet the real-time requirements. If the cache data corresponding to the data link is not stored, a request message will be sent to the server to obtain all the data sent by the server to replace the cache data corresponding to the data link. In practice, it was found that most of the cache data did not change, but the server sent all the data, resulting in low communication efficiency. Therefore, it is difficult for the current electronic device communication process to take into account both the real-time performance of the cache data and the communication efficiency. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a communication method, device, electronic device and storage medium for improving the problem of difficulty in balancing the real-time performance and communication efficiency of cached data.
[0004] The embodiment of the present application provides a communication method, including: after determining that the cached data corresponding to the data link is cached, sending a request message for accessing the data link to the server, the request message carries indication information, and the indication information is used to instruct the server to return part of the data in the request data corresponding to the data link; if part of the data in the request data corresponding to the data link is parsed from the response message returned by the server, the cached data corresponding to the data link is updated using part of the data in the request data corresponding to the data link. In the implementation process of the above scheme, after determining that the data link is cached, indication information is still sent to the server to instruct the server to encapsulate part of the data in the request data corresponding to the data link as a response message, thereby ensuring the real-time nature of the data update; further, the indication information is used to tell the server to return only part of the data in the request data, rather than all the data, thereby ensuring the communication efficiency between the electronic device and the server. Therefore, the request response method carrying indication information can effectively take into account the real-time nature of the cached data and the communication efficiency.
[0005] Optionally, in an embodiment of the present application, it further includes: if an empty string of data is parsed out from the response message returned from the server, the timestamp corresponding to the data link is updated to the time when the response message is received. In the implementation process of the above scheme, by directly updating the timestamp corresponding to the data link when an empty string of data is parsed out from the response message returned from the server, the problem of wasting network resources by returning all data when there is no data update is avoided, and the technical effect of saving network resources of the electronic device is effectively improved.
[0006] Optionally, in an embodiment of the present application, it also includes: if the request data corresponding to the data link is parsed from the response message returned by the server, the cache data corresponding to the data link is completely replaced with the request data corresponding to the data link. In the implementation process of the above scheme, when the request data corresponding to the data link is parsed from the response message, the cache data corresponding to the data link is completely replaced with the request data, thereby avoiding the situation where the cache data is not updated in time, and effectively improving the timeliness of the cache data.
[0007] Optionally, in an embodiment of the present application, before sending a request message for accessing a data link to a server, it further includes: determining whether cache data corresponding to the data link is cached in a cache mapping table; if so, generating a request message according to the indication information and the data link. In the implementation process of the above scheme, after determining that a data link is cached, a request message is still generated according to the indication information and the data link, and a request message carrying the indication information is sent to the server to instruct the server to encapsulate part of the data in the request data corresponding to the data link into a response message, thereby ensuring the real-time nature of data updates.
[0008] Optionally, in an embodiment of the present application, the cache mapping table includes: a timestamp and a cache validity period; sending a request message for accessing a data link to a server includes: obtaining a timestamp and a cache validity period corresponding to the data link from the cache mapping table; determining whether the time between the moment corresponding to the timestamp and the current moment is greater than the cache validity period; if not, sending a request message for accessing the data link to the server. In the implementation process of the above scheme, after determining that the cached data has not expired, a request message is still generated based on the indication information and the data link, and a request message carrying the indication information is sent to the server, thereby ensuring the real-time performance of some data in the request data corresponding to the data link (such as active fields that need to be updated in real time).
[0009] The embodiment of the present application also provides a communication method, which is applied to a server, including: receiving a request message for accessing a data link, the request message is sent after determining that the cache has cache data corresponding to the data link; if the indication information is parsed from the request message, and part of the data in the request data corresponding to the data link is obtained, then encapsulating and returning a response message corresponding to the request message according to the part of the data. In the implementation process of the above scheme, after the server parses the indication information from the request message, it only returns part of the data in the request data, rather than all the data, thereby ensuring the communication efficiency between the electronic device and the server.
[0010] Optionally, in an embodiment of the present application, it also includes: if the indication information is parsed from the request message and part of the data in the request data corresponding to the data link cannot be obtained, then an empty string data is obtained, and a response message corresponding to the request message is encapsulated and returned according to the empty string data. In the implementation process of the above scheme, after the server parses the indication information from the request message, even if part of the data in the request data corresponding to the data link cannot be obtained, the empty string data is still returned, so that the electronic device can avoid returning all the data to improve the communication efficiency while ensuring the real-time data update.
[0011] Optionally, in an embodiment of the present application, it also includes: if the indication information is not parsed from the request message, all fields corresponding to the data link are obtained, the data corresponding to all fields are queried in the database, the request data corresponding to the data link is obtained, and the response message corresponding to the request message is encapsulated and returned according to the request data corresponding to the data link.
[0012] Optionally, in an embodiment of the present application, obtaining partial data in the request data corresponding to the data link includes: if there is a preset field identifier, all fields corresponding to the data link are filtered according to the preset field identifier to obtain the filtered field, and the data corresponding to the filtered field is queried in the database to obtain partial data. In the implementation process of the above scheme, the server only returns partial data filtered by the preset field identifier, so that the electronic device can avoid returning all data to improve communication efficiency while ensuring the real-time nature of data update, and effectively takes into account the real-time nature and communication efficiency of cached data.
[0013] Optionally, in an embodiment of the present application, obtaining partial data in the request data corresponding to the data link includes: filtering out the filter fields whose change frequency exceeds the frequency threshold from all the fields corresponding to the data link; querying the data corresponding to the filter fields in the database to obtain partial data. In the implementation process of the above scheme, by filtering out partial data when the change frequency of the server exceeds the frequency threshold, the electronic device can avoid returning all data to improve communication efficiency while ensuring the real-time nature of data update, effectively taking into account both the real-time nature of cached data and communication efficiency.
[0014] Optionally, in an embodiment of the present application, encapsulating part of the data and returning a response message corresponding to the request message includes: determining whether the time between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time; if not, encapsulating part of the data and returning a response message corresponding to the request message. In the implementation process of the above scheme, after determining that the cache data of the electronic device has not expired, the server still encapsulates part of the data in the request data corresponding to the data link and returns a response message, thereby ensuring the real-time nature of data update.
[0015] Optionally, in an embodiment of the present application, after determining whether the time length between the timestamp corresponding to the data link and the current moment is greater than the preset cache validity period, it also includes: if the time length between the timestamp corresponding to the data link and the current moment is greater than the preset cache validity period, obtaining the request data corresponding to the data link, and encapsulating and returning a response message corresponding to the request message according to the request data corresponding to the data link.
[0016] An embodiment of the present application also provides a communication device, including: a request message sending module, which is used to send a request message for accessing a data link to a server after determining that the cache has cache data corresponding to the data link, the request message carrying indication information, and the indication information is used to instruct the server to return part of the data in the request data corresponding to the data link; a partial data updating module, which is used to update the cache data corresponding to the data link using the part of the data in the request data corresponding to the data link if part of the data in the request data corresponding to the data link is parsed from a response message returned by the server.
[0017] Optionally, in an embodiment of the present application, it also includes: a timestamp update module, which is used to update the timestamp corresponding to the data link to the time when the response message is received if an empty string data is parsed from the response message returned from the server.
[0018] Optionally, in an embodiment of the present application, it also includes: a full data update module, which is used to replace all cached data corresponding to the data link with the data link corresponding request data if the data link corresponding request data is parsed from the response message returned by the server.
[0019] Optionally, in an embodiment of the present application, it also includes: a cache data judgment module, used to judge whether cache data corresponding to the data link is cached in the cache mapping table; a request message generation module, used to generate a request message according to the indication information and the data link if cache data corresponding to the data link is cached in the cache mapping table.
[0020] Optionally, in an embodiment of the present application, the cache mapping table includes: a timestamp and a cache valid period; a request message sending module includes: a valid period acquisition submodule, used to obtain the timestamp and cache valid period corresponding to the data link from the cache mapping table; a valid period judgment submodule, used to judge whether the time between the moment corresponding to the timestamp and the current moment is greater than the cache valid period; a request message sending submodule, used to send a request message for accessing the data link to the server if the time between the moment corresponding to the timestamp and the current moment is less than the cache valid period.
[0021] An embodiment of the present application also provides a communication device, which is applied to a server, and includes: a request message receiving module, which is used to receive a request message for accessing a data link, and the request message is sent after it is determined that the cache has cache data corresponding to the data link; a partial data returning module, which is used to parse the indication information from the request message and obtain partial data in the request data corresponding to the data link, and then encapsulate and return a response message corresponding to the request message according to the partial data.
[0022] Optionally, in an embodiment of the present application, it also includes: an empty string return module, which is used to obtain empty string data if the indication information is parsed from the request message and some data in the request data corresponding to the data link cannot be obtained, and encapsulate and return a response message corresponding to the request message based on the empty string data.
[0023] Optionally, in an embodiment of the present application, it also includes: a full data return module, which is used to obtain all fields corresponding to the data link if the indication information is not parsed from the request message, query the data corresponding to all fields in the database, obtain the request data corresponding to the data link, and encapsulate and return the response message corresponding to the request message according to the request data corresponding to the data link.
[0024] Optionally, in an embodiment of the present application, the partial data return module includes: a partial data acquisition sub-module, which is used to filter all fields corresponding to the data link according to the preset field identifier if there is a preset field identifier, obtain the filter field, and query the data corresponding to the filter field in the database to obtain partial data.
[0025] Optionally, in an embodiment of the present application, the partial data return module includes: a filter field acquisition submodule, used to filter out filter fields whose change frequency exceeds a frequency threshold from all fields corresponding to the data link; and a partial data query submodule, used to query the data corresponding to the filter field in the database to obtain partial data.
[0026] Optionally, in an embodiment of the present application, the partial data return module includes: an effective duration judgment submodule, used to judge whether the duration between the timestamp corresponding to the data link and the current moment is greater than the preset cache effective duration; a first message encapsulation submodule, used to encapsulate and return a response message corresponding to the request message according to partial data if the duration between the timestamp corresponding to the data link and the current moment is less than the preset cache effective duration.
[0027] Optionally, in an embodiment of the present application, the partial data return module also includes: a second message encapsulation sub-module, which is used to obtain the request data corresponding to the data link if the duration between the timestamp corresponding to the data link and the current time is greater than the preset cache validity period, and encapsulate and return a response message corresponding to the request message according to the request data corresponding to the data link.
[0028] An embodiment of the present application further provides an electronic device, including: a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method described above is performed.
[0029] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described above is executed.
[0030] Other features and advantages of the embodiments of the present application will be described in the subsequent description, and in part will become apparent from the description, or will be understood by implementing the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 A flow chart of a communication method performed by an electronic device provided in an embodiment of the present application is shown;
[0033] Figure 2 A schematic diagram of the interaction timing between an electronic device and a server provided in an embodiment of the present application is shown;
[0034] Figure 3 A flow chart of a communication method performed by a server provided in an embodiment of the present application is shown;
[0035] Figure 4 A schematic diagram of the structure of a communication device provided in an embodiment of the present application is shown;
[0036] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments in the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the embodiments of the present application claimed for protection, but merely represents the selected embodiments in the embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the embodiments of the present application.
[0038] It is understandable that the "first" and "second" in the embodiments of the present application are used to distinguish similar objects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not necessarily limit the difference.
[0039] It should be noted that the communication method provided in the embodiments of the present application can be executed by an electronic device, where the electronic device refers to a device terminal or server with the function of executing a computer program, such as a smart phone, a personal computer, a tablet computer, a personal digital assistant, or a mobile Internet device. A server refers to a device that provides computing services through a network, such as an x86 server and a non-x86 server, and a non-x86 server includes a mainframe, a minicomputer, and a UNIX server.
[0040] The following introduces application scenarios where the communication method is applicable. The application scenarios here include but are not limited to: traffic saving environments or application scenarios with high real-time requirements. The traffic saving environment here is for example: if the mobile phone does not have a wireless LAN (Wi-Fi) connection and uses a traffic environment, the communication method can be used to tell the server to only return part of the requested data, rather than all of the data, thereby saving traffic and reducing traffic costs. The application scenarios with high real-time requirements here are for example: in the case of shopping festivals to buy goods or countdowns, the number of remaining goods or the remaining seconds need to be refreshed in real time. The communication method can be used to send an indication message to the server after determining that there is a data link in the cache. The indication message is used to instruct the server to return part of the data with high real-time requirements, thereby ensuring the real-time nature of data updates.
[0041] See also Figure 1 The flowchart of the communication method performed by the electronic device provided in the embodiment of the present application is shown; the embodiment of the present application provides a communication method applied to the electronic device, and its implementation may include:
[0042] Step S110: after determining that the cache has cache data corresponding to the data link, a request message for accessing the data link is sent to the server, the request message carries indication information, and the indication information is used to instruct the server to return part of the data in the request data corresponding to the data link.
[0043] It is understandable that the above electronic device can cache cache data corresponding to the data link in a cache mapping table. The cache mapping table refers to a list of data links and cache data correspondingly mapped and stored. The cache mapping table can be set according to specific circumstances, for example, using a hash table Map<URL,Resp> Represents the data structure in the cache mapping table, where URL is the abbreviation of Uniform Resource Locator (URL), URL represents the data link, Resp is the abbreviation of Response, Resp represents the cache data corresponding to the data link,<URL,Resp> Indicates the mapping relationship in the cache mapping table. It is understandable that the cache data may also include the structure of the data table, which can be expressed using Resp.data, where data refers to the name of the data table. If there are two fields in the data table, field A and field B, field A can be expressed using Resp.data.A, and field B can be expressed using Resp.data.B.
[0044] Indication information is information used to instruct the server to return part of the data in the request data corresponding to the data link. For example, Reduce can be used to represent the indication information. For example, assuming that the request data corresponding to the data link is a data record of all fields in the server's data table, and the data table only includes field A and field B. If field A is previously identified as an active field (or a field whose change frequency exceeds a frequency threshold), then when the server receives the indication information with Reduce, it only needs to return the specific value of field A of the data record, without returning the specific value of field A and the specific value of field B.
[0045] Step S120: if part of the data in the request data corresponding to the data link is parsed from the response message returned by the server, the part of the data in the request data corresponding to the data link is used to update the cache data corresponding to the data link.
[0046] An implementation example of the above step S120 is: after the electronic device sends a request message carrying indication information to the server, it can receive a response message returned by the server through Hyper Text Transfer Protocol (HTTP) or Hyper Text Transfer Protocol Secure (HTTPS). If the server parses the indication information (such as Reduce) from the request message and obtains part of the data in the request data corresponding to the data link, it encapsulates the part of the data into a response message corresponding to the request message, and then sends the response message encapsulated with part of the data to the electronic device. If the electronic device parses part of the data in the request data corresponding to the data link from the response message returned by the server, it uses the part of the data in the request data corresponding to the data link to update the cache data corresponding to the data link. Specifically, assuming that the two field values in the cached data are: Resp.data.A=1, and Resp.data.B=2, and the partial data in the request data corresponding to the data link parsed from the response message is data.A=2, then at this time you only need to update the value of the A field. The two field values in the modified cached data are: Resp.data.A=2, and Resp.data.B=2.
[0047] In the above implementation process, after determining that there is a data link in the cache, indication information is still sent to the server to instruct the server to encapsulate part of the data in the request data corresponding to the data link as a response message, thereby ensuring the real-time nature of the data update; further, the indication information is used to tell the server to return only part of the data in the request data, rather than all the data, thereby ensuring the communication efficiency between the electronic device and the server. Therefore, the request response method carrying the indication information can effectively take into account the real-time nature of the cached data and the communication efficiency.
[0048] As an optional implementation of the above communication method, after sending a request message for accessing a data link to a server, an empty string of data may be parsed, which means that although the server can parse the instruction information from the request message, it cannot obtain part of the data in the request data corresponding to the data link (which may be caused by not setting a preset field identifier). This implementation may include:
[0049] Step S130: If an empty string of data is parsed from the response message returned by the server, the timestamp corresponding to the data link is updated to the time when the response message is received.
[0050] An implementation example of the above step S130 is as follows: after the electronic device sends a request message carrying indication information to the server, it can receive a response message returned by the server through the HTTP protocol or the HTTPS protocol. If the server parses the indication information (such as Reduce) from the request message, and cannot obtain part of the data in the request data corresponding to the data link, then it can obtain empty string data (such as "null" or ""), and encapsulate the empty string data into a response message corresponding to the request message, and then send the response message encapsulated with the empty string to the electronic device. After receiving the response message returned by the server, if the electronic device parses the empty string data from the response message returned by the server, it does not need to replace any data in the data table (for example, represented as Resp.data), and only needs to update the timestamp corresponding to the data link (for example, represented as Resp.timestamp) to the timestamp corresponding to the time when the response message is received.
[0051] As an optional implementation of the above communication method, after sending a request message for accessing a data link to a server, it is also possible to parse out data corresponding to all fields. This implementation may include:
[0052] Step S140: if the request data corresponding to the data link is parsed from the response message returned by the server, the cache data corresponding to the data link is completely replaced with the request data corresponding to the data link.
[0053] An implementation example of the above step S140 is: if the electronic device does not need to use traffic (for example, it is connected to WIFI) or the network traffic bandwidth is greater than the bandwidth threshold, it can directly send a request message to the server to request data corresponding to all fields. After receiving the request message sent by the electronic device, if the server does not parse the instruction information (for example, Reduce) from the request message, it obtains all fields corresponding to the data link, queries the data corresponding to all fields in the database, obtains the request data corresponding to the data link, and encapsulates the request data corresponding to the data link into a response message corresponding to the request message, and then sends the response message to the electronic device. After the electronic device receives the response message sent by the server, if the response message parses the request data corresponding to the data link, the cached data corresponding to the data link is completely replaced with the request data corresponding to the data link.
[0054] See also Figure 2 The schematic diagram of the interaction timing between the electronic device and the server provided in the embodiment of the present application is shown; as an optional implementation of the above communication method, before sending the request message for accessing the data link to the server in step S110, a request message including indication information may also be generated, and the implementation may include:
[0055] Step S111: Determine whether cache data corresponding to the data link is cached in the cache mapping table.
[0056] The implementation method of the above step S111 is, for example: when the electronic device (such as a mobile phone) is in an environment without a wireless local area network (Wi-Fi) connection and using traffic, it can first use an executable program compiled or interpreted by a preset programming language to determine whether cache data corresponding to the data link is cached in the cache mapping table. Among them, the programming languages that can be used are, for example, C, C++, Java, BASIC, JavaScript, LISP, Shell, Perl, Ruby, Python and PHP, etc., and the cache mapping table can be implemented based on Memcached or Redis, etc.
[0057] Step S112: If cache data corresponding to the data link is cached in the cache mapping table, a request message is generated according to the indication information and the data link.
[0058] An implementation example of the above step S112 is as follows: the electronic device can determine whether cache data corresponding to the data link is cached in the cache mapping table. If cache data corresponding to the data link is cached in the cache mapping table, the electronic device can obtain the indication information (e.g., Reduce), and generate a request message according to the indication information and the data link, and then send the request message to the server. Specifically, assuming that the request message is an HTTP message, the electronic device can encapsulate the indication information (e.g., Reduce) in the header of the HTTP message, and the server can parse the indication information (e.g., Reduce) from the HTTP message header. Of course, the indication information (e.g., Reduce) can also be encapsulated in the body of the HTTP message, and the server can parse the indication information (e.g., Reduce) from the body of the HTTP message.
[0059] Step S113: If there is no cache data corresponding to the cache data link in the cache mapping table, a request message is generated according to the data link.
[0060] The implementation method of the above step S113 is, for example: the electronic device can determine whether the cache data corresponding to the data link is cached in the cache mapping table. If the cache data corresponding to the data link is not cached in the cache mapping table, a request message is generated according to the data link, and then the request message is sent to the server. Specifically, assuming that the data link (URL) is http: / / www.a.com / data1, which means that a request is made to access all data in the data table data1 on the server, then if no cache data with the URL http: / / www.a.com / data1 is found in the cache mapping table, the data link can be directly accessed, and a request message corresponding to the data link can be generated and sent.
[0061] As an optional implementation of step S110, the cache mapping table includes: a timestamp and a cache validity period, wherein the timestamp can be expressed as Resp.timestamp, and the cache validity period can be expressed as Resp.TTL. The electronic device can act as a client to determine whether the timestamp has timed out (i.e., whether it exceeds the cache validity period), and this implementation may include:
[0062] Step S114: Obtain the timestamp and cache validity period corresponding to the data link from the cache mapping table.
[0063] The implementation method of the above step S114 is, for example: obtaining the timestamp and cache validity period corresponding to the data link from the cache mapping table implemented based on Memcached or Redis, specifically, using URL as the key and Resp as the value.<URL,Resp> Stored in Memcached or Redis, Resp may include data structures such as data table (data), timestamp (timestamp), and cache validity period (TTL). Therefore, after obtaining the cache data (Resp) corresponding to the data link, the timestamp (Resp.timestamp) and cache validity period (Resp.TTL) can also be parsed from the cache data (Resp).
[0064] Step S115: Determine whether the time length between the time corresponding to the timestamp and the current time is greater than the cache validity time length.
[0065] Step S116: If the time length between the time corresponding to the timestamp and the current time is less than the cache validity period, a request message for accessing the data link is sent to the server.
[0066] For example, in the implementation of the above steps S115 to S116, if the time between the time corresponding to the timestamp and the current time is less than the cache validity period, the electronic device sends a request message for accessing the data link to the server via the HTTP protocol or the HTTPS protocol. The cache validity period can be set according to the specific situation, for example, the cache validity period is set to 3000 milliseconds, etc.
[0067] It can be understood that the above description is a process in which an electronic device as a client determines whether the timestamp exceeds the cache validity period. Of course, the service end (i.e., the server) can also determine whether the timestamp exceeds the cache validity period. This process will be described in detail below.
[0068] See also Figure 3 The flow chart of the communication method performed by the server provided in the embodiment of the present application is shown; the embodiment of the present application provides a communication method applied to the server, and returns part of the data when the indication information is parsed. The implementation method may include:
[0069] Step S210: the server receives a request message for accessing a data link, and the request message is sent after determining that cache data corresponding to the data link is cached.
[0070] An example of an implementation of the above step S210 is: after determining that the cached data corresponding to the data link is cached, the electronic device sends a request message for accessing the data link to the server through the HTTP protocol or the HTTPS protocol, and the request message carries the indication information. The server receives the request message sent by the electronic device through the HTTP protocol or the HTTPS protocol, and the request message is used to access the cached data corresponding to the data link.
[0071] Step S220: If the indication information is parsed from the request message, and partial data in the request data corresponding to the data link is obtained, a response message corresponding to the request message is encapsulated and returned according to the partial data.
[0072] It is understandable that after receiving the request message sent by the electronic device, if the server parses the instruction information (such as Reduce) from the request message and obtains part of the data in the request data corresponding to the data link (there are many ways to obtain part of the data, so it will be described in detail below), it will encapsulate the part of the data into a response message corresponding to the request message, and then send the response message encapsulated with the part of the data to the electronic device. If the electronic device parses part of the data in the request data corresponding to the data link from the response message returned by the server, it will use the part of the data in the request data corresponding to the data link to update the cache data corresponding to the data link.
[0073] In the above implementation process, after parsing the indication information from the request message, the server only returns part of the request data instead of all the data, thereby ensuring the communication efficiency between the electronic device and the server.
[0074] As an optional implementation of the communication method applied to the server, when the indication information is parsed and part of the data is not obtained, an empty string data may be returned. The implementation may include:
[0075] Step S230: If the indication information is parsed from the request message and part of the data in the request data corresponding to the data link cannot be obtained, then an empty string data is obtained, and a response message corresponding to the request message is encapsulated and returned according to the empty string data.
[0076] An implementation example of the above step S230 is as follows: after receiving a request message sent by an electronic device, if the server parses the instruction information (such as Reduce) from the request message and cannot obtain part of the data in the request data corresponding to the data link, then it can obtain empty string data (such as "null" or ""), and encapsulate the empty string data into a response message corresponding to the request message, and then send the response message encapsulated with the empty string to the electronic device. After receiving a response message returned by the server, if the electronic device parses the empty string data from the response message returned by the server, it updates the timestamp corresponding to the data link to the time when the response message was received.
[0077] As an optional implementation of the above communication method applied to the server, it is also possible to directly return data corresponding to all fields when the indication information is not parsed. This implementation may include:
[0078] Step S240: If the indication information is not parsed from the request message, all fields corresponding to the data link are obtained, the data corresponding to all fields are queried in the database, the request data corresponding to the data link is obtained, and the response message corresponding to the request message is encapsulated and returned according to the request data corresponding to the data link.
[0079] An implementation example of the above step S240 is: if the electronic device does not need to use traffic (for example, it is connected to WIFI) or the network traffic bandwidth is greater than the bandwidth threshold, it can directly send a request message to the server to request data corresponding to all fields. After receiving the request message sent by the electronic device, if the server does not parse the instruction information (for example, Reduce) from the request message, it obtains all fields corresponding to the data link, queries the data corresponding to all fields in the database, obtains the request data corresponding to the data link, and encapsulates the request data corresponding to the data link into a response message corresponding to the request message, and then sends the response message to the electronic device. After the electronic device receives the response message sent by the server, if the response message parses the request data corresponding to the data link, the cached data corresponding to the data link is completely replaced with the request data corresponding to the data link.
[0080] As a first optional implementation of obtaining partial data in the above step S220, the above step S220 may be to obtain partial data by screening by preset field identifiers, and this implementation may include:
[0081] Step S221: If there is a preset field identifier, all fields corresponding to the data link are filtered according to the preset field identifier to obtain the filtered field, and the data corresponding to the filtered field is queried in the database to obtain partial data.
[0082] An implementation example of the above-mentioned step S221 is as follows: assuming that the preset field identifier is a field identifier marked with the active (Active) keyword, and there are field A (marked by the preset field identifier) and field B (not marked by the preset field identifier) in the data table in the server (for example, data.A=2 and data.B=3), then when all the fields corresponding to the data link are filtered according to the preset field identifier, the fields marked by the preset field identifier (for example, Active) are filtered out, and the filtered field is field A. At this time, only the data corresponding to field A needs to be queried from the database, that is, the partial data obtained is 2 (that is, the specific value of field A).
[0083] As a second optional implementation of obtaining partial data in the above step S220, the above step S220 may be to obtain partial data by screening in which the change frequency exceeds the frequency threshold (i.e., the change is large), and this implementation may include:
[0084] Step S222: Filter out the filter fields whose change frequency exceeds the frequency threshold from all fields corresponding to the data link.
[0085] The change frequency refers to the number of field modifications in the server's data table divided by the preset time. For example, if field A is modified 30 times within 1 minute, and field B is modified 10 times within 1 minute, and the frequency threshold is 20 times within 1 minute, then it can be known that the filter field whose change frequency (30 times per minute) in the server's data table exceeds the frequency threshold (20 times per minute) is field A.
[0086] Step S223: query the database for data corresponding to the screening field to obtain partial data.
[0087] An implementation example of the above steps S222 to S223 is: assuming that the data in the data table in the database in the server includes: data.A=2 and data.B=3, and the filter field is field A, then the data corresponding to the filter field queried in the database is 2, so the partial data obtained is data.A=2.
[0088] As a first optional implementation of returning a response message in the above step S220, when it is determined that the cached data of the electronic device has not timed out, a response message encapsulating part of the data is still returned. This implementation may include:
[0089] Step S224: Determine whether the time length between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time length.
[0090] An implementation example of the above step S224 is: the server uses an executable program compiled or interpreted in a preset programming language to determine whether the time length between the timestamp corresponding to the data link and the current time is greater than the preset cache validity period. The programming languages that can be used are, for example: C, C++, Java, BASIC, JavaScript, LISP, Shell, Perl, Ruby, Python and PHP, etc.
[0091] Step S225: If the time length between the timestamp corresponding to the data link and the current time is less than the preset cache validity time length, a response message corresponding to the request message is encapsulated and returned according to the partial data.
[0092] An implementation example of the above-mentioned step S225 is as follows: since the server determines that the cached data of the electronic device has not timed out (that is, the duration between the timestamp corresponding to the data link and the current time is less than the preset cache validity period), it still encapsulates part of the data into a response message corresponding to the request message, and then sends the response message to the electronic device, so that the electronic device parses part of the data from the response message and only updates part of the data, which can effectively reduce the consumption of network bandwidth resources for data transmission while ensuring the real-time nature of data updates.
[0093] As a second optional implementation of returning a response message in the above step S220, after determining whether the time between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time, a response message corresponding to the request message may be encapsulated and returned according to the data corresponding to all fields. This implementation may include:
[0094] Step S226: If the time length between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time length, the request data corresponding to the data link is obtained, and a response message corresponding to the request message is encapsulated and returned according to the request data corresponding to the data link.
[0095] An implementation example of the above-mentioned step S226 is as follows: since the server determines that the cached data of the electronic device has timed out (i.e., the duration between the timestamp corresponding to the data link and the current time is greater than the preset cache validity period), all the data (i.e., the request data corresponding to the data link) can be directly encapsulated as a response message corresponding to the request message, and the response message is returned to the electronic device, so that the electronic device can parse all the data (i.e., the request data corresponding to the data link) from the response message, thereby ensuring the real-time nature of data updates.
[0096] See also Figure 4 The structure diagram of the communication device provided in the embodiment of the present application is shown; the embodiment of the present application provides a communication device 300, including:
[0097] The request message sending module 310 is used to send a request message for accessing the data link to the server after determining that the cache has cache data corresponding to the data link. The request message carries indication information, and the indication information is used to instruct the server to return part of the data in the request data corresponding to the data link.
[0098] The partial data updating module 320 is used to update the cache data corresponding to the data link using the partial data in the request data corresponding to the data link if the partial data in the request data corresponding to the data link is parsed from the response message returned by the server.
[0099] Optionally, in the embodiment of the present application, it also includes:
[0100] The timestamp update module is used to update the timestamp corresponding to the data link to the time when the response message is received if an empty string data is parsed from the response message returned by the server.
[0101] Optionally, in the embodiment of the present application, it also includes:
[0102] The entire data update module is used to replace all cached data corresponding to the data link with the data corresponding to the request data if the data link corresponding to the request data is parsed from the response message returned by the server.
[0103] Optionally, in the embodiment of the present application, it also includes:
[0104] The cache data judgment module is used to judge whether cache data corresponding to the data link is cached in the cache mapping table.
[0105] The request message generation module is used to generate a request message according to the indication information and the data link if the cache data corresponding to the data link is cached in the cache mapping table.
[0106] Optionally, in an embodiment of the present application, the cache mapping table includes: a timestamp and a cache validity period; the request message sending module includes:
[0107] The effective duration acquisition submodule is used to obtain the timestamp corresponding to the data link and the cache effective duration from the cache mapping table.
[0108] The effective duration judgment submodule is used to judge whether the duration between the moment corresponding to the timestamp and the current moment is greater than the cache effective duration.
[0109] The request message sending submodule is used to send a request message for accessing the data link to the server if the time length between the time corresponding to the timestamp and the current time is less than the cache validity time length.
[0110] The embodiment of the present application further provides a communication device, applied to a server, including:
[0111] The request message receiving module is used to receive a request message for accessing a data link. The request message is sent after it is determined that the cache has cache data corresponding to the data link.
[0112] The partial data returning module is used to parse the indication information from the request message and obtain partial data in the request data corresponding to the data link, and then encapsulate and return the response message corresponding to the request message according to the partial data.
[0113] Optionally, in the embodiment of the present application, it also includes:
[0114] The empty string return module is used to obtain empty string data if the indication information is parsed from the request message and part of the data in the request data corresponding to the data link cannot be obtained, and encapsulate and return the response message corresponding to the request message based on the empty string data.
[0115] Optionally, in the embodiment of the present application, it also includes:
[0116] The full data return module is used to obtain all fields corresponding to the data link if the indication information is not parsed from the request message, query the data corresponding to all fields in the database, obtain the request data corresponding to the data link, and encapsulate and return the response message corresponding to the request message according to the request data corresponding to the data link.
[0117] Optionally, in the embodiment of the present application, the partial data returning module includes:
[0118] The partial data acquisition submodule is used to filter all fields corresponding to the data link according to the preset field identifier if there is a preset field identifier, obtain the filtered field, and query the data corresponding to the filtered field in the database to obtain partial data.
[0119] Optionally, in the embodiment of the present application, the partial data returning module includes:
[0120] The filter field acquisition submodule is used to filter out the filter fields whose change frequency exceeds the frequency threshold from all fields corresponding to the data link.
[0121] The partial data query submodule is used to query the data corresponding to the filter field in the database and obtain partial data.
[0122] Optionally, in the embodiment of the present application, the partial data returning module includes:
[0123] The effective duration judgment submodule is used to judge whether the duration between the timestamp corresponding to the data link and the current time is greater than the preset cache effective duration.
[0124] The first message encapsulation submodule is used to encapsulate and return a response message corresponding to the request message according to part of the data if the time length between the timestamp corresponding to the data link and the current time is less than the preset cache validity time length.
[0125] Optionally, in the embodiment of the present application, the partial data returning module further includes:
[0126] The second message encapsulation submodule is used to obtain the request data corresponding to the data link if the time length between the timestamp corresponding to the data link and the current time is greater than the preset cache validity period, and encapsulate and return the response message corresponding to the request message according to the request data corresponding to the data link.
[0127] It should be understood that the device corresponds to the above-mentioned communication method embodiment and can execute the various steps involved in the above-mentioned method embodiment. The specific functions of the device can be referred to in the above description. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the operating system (OS) of the device.
[0128] See also Figure 5 An electronic device 400 provided in an embodiment of the present application includes: a processor 410 and a memory 420, wherein the memory 420 stores machine-readable instructions executable by the processor 410, and when the machine-readable instructions are executed by the processor 410, the above method is executed.
[0129] The embodiment of the present application further provides a computer-readable storage medium 430 , on which a computer program is stored. When the computer program is executed by the processor 410 , the above method is executed.
[0130] Among them, the computer-readable storage medium 430 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, disk or optical disk.
[0131] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0132] In several embodiments provided by the embodiments of the present application, it should be understood that the disclosed device and method can also be implemented in other ways. The device embodiments described above are only schematic, for example, the flowcharts and block diagrams in the accompanying drawings show the possible implementation architecture, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a part of a module, a program segment or a code, and a part of a module, a program segment or a code includes one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also be different from the order of occurrence marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which is mainly determined by the functions involved.
[0133] In addition, each functional module of each embodiment in the embodiment of the present application can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part. In addition, in the description of this specification, the description of reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiment of the present application. In this specification, the schematic representation of the above terms does not necessarily have to be directed to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples without contradicting each other.
[0134] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0135] The above description is only an optional implementation manner of the embodiments of the present application, but the protection scope of the embodiments of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the embodiments of the present application, which should be covered within the protection scope of the embodiments of the present application.
Claims
1. A communication method, It is characterized in that include: After determining that the cached data corresponding to the data link is cached, sending a request message for accessing the data link to the server, the request message carrying indication information, the indication information being used to instruct the server to return part of the requested data corresponding to the data link; If part of the data in the request data corresponding to the data link is parsed from the response message returned by the server, the part of the data in the request data corresponding to the data link is used to update the cache data corresponding to the data link; The partial data is obtained by the server filtering all fields corresponding to the data link according to a preset field identifier, obtaining the filter field, and querying the data corresponding to the filter field in the database. The preset field identifier is a field identifier for marking active keywords.
2. The method according to claim 1, It is characterized in that Also includes: If an empty string of data is parsed from the response message returned by the server, the timestamp corresponding to the data link is updated to the time when the response message is received.
3. The method according to claim 1, It is characterized in that Also includes: If the request data corresponding to the data link is parsed from the response message returned by the server, the request data corresponding to the data link is used to completely replace the cache data corresponding to the data link.
4. The method according to claim 1, It is characterized in that Before sending the request message for accessing the data link to the server, the method further includes: Determine whether cache data corresponding to the data link is cached in the cache mapping table; If so, the request message is generated according to the indication information and the data link.
5. The method according to claim 4, It is characterized in that The cache mapping table includes: a timestamp and a cache validity period; the request message for accessing the data link to the server includes: Obtaining the timestamp and cache validity period corresponding to the data link from the cache mapping table; Determine whether the time between the time corresponding to the timestamp and the current time is greater than the cache validity period; If not, a request message for accessing the data link is sent to the server.
6. A communication method, It is characterized in that Applicable to servers, including: receiving a request message for accessing a data link, wherein the request message is sent after determining that cache data corresponding to the data link is cached; If the indication information is parsed from the request message and part of the request data corresponding to the data link is obtained, a response message corresponding to the request message is encapsulated and returned according to the part of the data; Among them, the obtaining of part of the data in the request data corresponding to the data link includes: if there is a preset field identifier, all fields corresponding to the data link are filtered according to the preset field identifier to obtain the filtered field, and the data corresponding to the filtered field is queried in the database to obtain the part of the data, and the preset field identifier is a field identifier for marking active keywords.
7. The method according to claim 6, It is characterized in that Also includes: If the indication information is parsed from the request message and part of the data in the request data corresponding to the data link cannot be obtained, then an empty string data is obtained, and a response message corresponding to the request message is encapsulated and returned according to the empty string data.
8. The method according to claim 6, It is characterized in that Also includes: If the indication information is not parsed from the request message, all fields corresponding to the data link are obtained, the data corresponding to all fields are queried in the database, the request data corresponding to the data link is obtained, and the response message corresponding to the request message is encapsulated and returned according to the request data corresponding to the data link.
9. The method according to claim 6, It is characterized in that The obtaining of part of the data in the request data corresponding to the data link includes: Filtering out the filter fields whose change frequency exceeds a frequency threshold from all fields corresponding to the data link; The data corresponding to the screening field is queried in the database to obtain the partial data.
10. The method according to claim 6, It is characterized in that The encapsulating and returning a response message corresponding to the request message according to the partial data includes: Determine whether the time between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time; If not, a response message corresponding to the request message is encapsulated and returned according to the partial data.
11. The method according to claim 10, It is characterized in that After determining whether the time length between the timestamp corresponding to the data link and the current time is greater than the preset cache validity time length, the method further includes: If the duration between the timestamp corresponding to the data link and the current time is greater than the preset cache validity period, the request data corresponding to the data link is obtained, and a response message corresponding to the request message is encapsulated and returned according to the request data corresponding to the data link.
12. A communication device, It is characterized in that include: A request message sending module, used for sending a request message for accessing the data link to a server after determining that the cache has cache data corresponding to the data link, wherein the request message carries indication information, and the indication information is used for instructing the server to return part of the request data corresponding to the data link; A partial data updating module, configured to update cache data corresponding to the data link using the partial data in the request data corresponding to the data link if the partial data in the request data corresponding to the data link is parsed from the response message returned by the server; The partial data is obtained by the server filtering all fields corresponding to the data link according to a preset field identifier, obtaining the filter field, and querying the data corresponding to the filter field in the database. The preset field identifier is a field identifier for marking active keywords.
13. An electronic device, It is characterized in that include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method according to any one of claims 1 to 11 is performed.
14. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 11 is executed.
