Network request processing method and device, equipment and storage medium

By configuring appropriate caching policies for network requests and using cached data to process network requests, the problems of data sharing and delivery delay of web worker threads are solved, the processing speed and efficiency of network requests is improved, and offline functions are provided.

CN119276941APending Publication Date: 2025-01-07CHINA CONSTRUCTION BANK +1
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411161297.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

In the prior art, network request processing speed is slow, mainly because data sharing and data requests between web worker threads need to be passed through the main thread, resulting in increased latency and server load.

Method used

By setting up a cache mechanism, a suitable cache policy is configured for network requests, the frequency of data passing through the main thread is reduced, and the cached data is used to process network requests, thereby avoiding the delay caused by data passing through the main thread and improving the processing speed of network requests.

Benefits of technology

Significantly shortens the response time of network requests, improves processing speed, and provides offline functionality when there is no network connection, reducing server load and data transmission paths.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119276941A_ABST
    Figure CN119276941A_ABST
Patent Text Reader

Abstract

The invention provides a network request processing method and device, equipment and a storage medium. Relates to the technical field of computers. The method comprises the following steps: acquiring a to-be-processed network request initiated for a Web application, and determining a target caching strategy configured for the to-be-processed network request in advance from a plurality of caching strategies; and obtaining target response information corresponding to the to-be-processed network request according to the target caching strategy, and displaying the target response information in the Web application. Wherein the caching strategy is used for acquiring target response information corresponding to the to-be-processed network request from a server and / or a cache corresponding to the Web application. According to the method, the processing speed of the network request is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a network request processing method, device, equipment and storage medium. Background Art

[0002] With the development of network technology and business, World Wide Web (Web) applications need to carry more and more tasks and process more and more data. They not only need to handle the loading and rendering of page information, but also the interaction with users.

[0003] The prior art uses a Web worker thread to create multiple child threads, and puts the specified pending network requests into corresponding child threads respectively. The child threads process the network requests by executing Java scripts, and generate corresponding target response information, and finally return all the target response information to the main thread.

[0004] However, the existing technology still has the problem of slow processing speed of network requests. Summary of the invention

[0005] The present application provides a network request processing method, device, equipment and storage medium to solve the problem of slow processing speed of network requests in the prior art.

[0006] In a first aspect, the present application provides a network request processing method, comprising:

[0007] Get pending network requests initiated for the web application;

[0008] Determine a target cache strategy pre-configured for the network request to be processed from a plurality of cache strategies, the cache strategy being used to instruct to obtain target response information corresponding to the network request to be processed from a server and / or cache corresponding to the Web application;

[0009] According to the target cache strategy, obtaining target response information corresponding to the pending network request;

[0010] The target response information is displayed in the Web application.

[0011] In a possible design, before obtaining the to-be-processed network request initiated by the Web application, the method further includes:

[0012] According to the update frequency and update data volume of response information corresponding to each network request, a cache strategy corresponding to the network request is determined, and the network request is initiated for the Web application.

[0013] In a possible design, determining the cache strategy corresponding to the network request according to the update frequency and update data volume of the response information corresponding to each network request includes:

[0014] If the update frequency of the response information corresponding to the network request is less than or equal to the preset frequency, configuring a first cache strategy for the network request, wherein the first cache strategy indicates obtaining the response information corresponding to the network request from the cache;

[0015] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume exceeds the preset update data volume, a second cache strategy is configured for the network request, wherein the second cache strategy indicates obtaining the response information corresponding to the network request from the server;

[0016] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data amount does not exceed the preset update data amount, a third cache strategy is configured for the network request, and the third cache strategy indicates obtaining the response information corresponding to the network request from the server and the cache.

[0017] In a possible design, when the target cache strategy is the third cache strategy, obtaining the target response information corresponding to the to-be-processed network request according to the target cache strategy includes:

[0018] Obtaining cache response information corresponding to the pending network request from the cache;

[0019] Obtaining target response information corresponding to the to-be-processed network request from the server;

[0020] Accordingly, displaying the target response information in the Web application includes:

[0021] Displaying the cache response information in the Web application;

[0022] The Web application is refreshed according to the target response information, so that the Web application displays the target response information.

[0023] In a possible design, refreshing the Web application by using the target response information includes:

[0024] In the Web application, using the target response information to replace and display the cached response information;

[0025] or,

[0026] Obtaining update data of the target response information relative to the cache response information;

[0027] The Web application is refreshed according to the update data so that the Web application displays the target response information.

[0028] In a possible design, when the target cache strategy is the second cache strategy, obtaining the target response information corresponding to the to-be-processed network request according to the target cache strategy includes:

[0029] Sending the pending network request to the server;

[0030] If the acquisition failure information returned by the server is received, the target response information corresponding to the to-be-processed network request is acquired from the cache.

[0031] In one possible design, the method further includes:

[0032] If the target response information is obtained from the server, the cache response information corresponding to the to-be-processed network request in the cache is updated using the target response information.

[0033] In one possible design, the method further includes:

[0034] If the cache policy corresponding to any cache response information in the cache is the first cache policy, the cache response information is deleted when the current time is the update time of the cache response information.

[0035] In a second aspect, the present application provides a network request processing device, comprising:

[0036] The acquisition module is used to obtain pending network requests initiated for the Web application;

[0037] A determination module, used to determine a target cache strategy pre-configured for the network request to be processed from a plurality of cache strategies, the cache strategy being used to instruct to obtain target response information corresponding to the network request to be processed from a server and / or cache corresponding to the Web application;

[0038] The acquisition module is further used to acquire target response information corresponding to the to-be-processed network request according to the target cache strategy;

[0039] The display module is used to display the target response information in the Web application.

[0040] In a possible design, the determining module is further used to:

[0041] According to the update frequency and update data volume of response information corresponding to each network request, a cache strategy corresponding to the network request is determined, and the network request is initiated for the Web application.

[0042] In a possible design, the determining module further includes: a configuration module, configured to:

[0043] If the update frequency of the response information corresponding to the network request is less than or equal to the preset frequency, configuring a first cache strategy for the network request, wherein the first cache strategy indicates obtaining the response information corresponding to the network request from the cache;

[0044] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume exceeds the preset update data volume, a second cache strategy is configured for the network request, wherein the second cache strategy indicates obtaining the response information corresponding to the network request from the server;

[0045] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data amount does not exceed the preset update data amount, a third cache strategy is configured for the network request, and the third cache strategy indicates obtaining the response information corresponding to the network request from the server and the cache.

[0046] In a possible design, the acquisition module is further used to:

[0047] Obtaining cache response information corresponding to the pending network request from the cache;

[0048] Obtain target response information corresponding to the to-be-processed network request from the server.

[0049] In a possible design, the display module further includes: a refresh module,

[0050] The display module is further used to display the cache response information in the Web application;

[0051] The refresh module is used to refresh the Web application through the target response information so that the Web application displays the target response information.

[0052] In a possible design, the display module further includes: a processing module, configured to:

[0053] In the Web application, using the target response information to replace and display the cached response information;

[0054] or,

[0055] Obtaining update data of the target response information relative to the cache response information;

[0056] The Web application is refreshed according to the update data so that the Web application displays the target response information.

[0057] In a possible design, the acquisition module further includes: a sending module, configured to:

[0058] Sending the pending network request to the server;

[0059] The acquisition module is further configured to acquire target response information corresponding to the to-be-processed network request from the cache if acquisition failure information returned by the server is received.

[0060] In one possible design, the apparatus further includes: an updating module, configured to:

[0061] If the target response information is obtained from the server, the cache response information corresponding to the to-be-processed network request in the cache is updated using the target response information.

[0062] In a possible design, the apparatus further includes: a deletion module, configured to:

[0063] If the cache policy corresponding to any cache response information in the cache is the first cache policy, the cache response information is deleted when the current time is the update time of the cache response information.

[0064] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor and a memory; the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, so that the at least one processor executes the network request processing method described in the first aspect and various possible designs of the first aspect.

[0065] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the network request processing method described in the first aspect and various possible designs of the first aspect is implemented.

[0066] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the network request processing method described in the first aspect and various possible designs of the first aspect.

[0067] The network request processing method, device, equipment and storage medium provided in the present application obtain the pending network request initiated for the Web application, and determine the target cache strategy pre-configured for the pending network request from multiple cache strategies; wherein the cache strategy is used to indicate that the target response information corresponding to the pending network request is obtained from the service and / or cache corresponding to the Web application. According to the target cache strategy, the target response information corresponding to the pending network request is obtained, and the target response information is displayed in the Web application. By configuring a suitable target cache strategy for the pending network request, it is possible to avoid each request being transmitted through the network, thereby reducing network delays, significantly shortening the response time to the pending network request, and improving the processing speed of the network request. In addition, through the target cache strategy, previously cached data can also be accessed when there is no network connection, providing certain offline functions to process network requests. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0069] Figure 1 Schematic diagram of the process of network request processing method provided in the embodiment of the present application Figure 1 ;

[0070] Figure 2 Schematic diagram of the process of network request processing method provided in the embodiment of the present application Figure 2 ;

[0071] Figure 3 A schematic diagram of the structure of a network request processing device provided in an embodiment of the present application;

[0072] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0073] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0074] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0075] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data involved shall comply with the provisions of relevant laws and regulations and shall not violate public order and good morals.

[0076] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0077] Terminology explanation:

[0078] Service Worker: The full name is Service Worker, which is a script running in the background of a web browser. It provides a new way to intercept and process network requests, including but not limited to caching resources and handling offline access.

[0079] Web Assembly: The full name is WebAssembly (Wasm), which is a binary instruction format that allows developers to compile compiled languages ​​such as C, C++, Rust into binary format. Wasm is used to efficiently execute code in web browsers to improve the performance of web applications and bring it close to the performance level of native applications.

[0080] When developing web applications, processing network requests is a very important part. Network requests usually refer to the data exchange between the client (web browser) and the server. In the traditional network request processing method, the web browser processes network requests by executing Java scripts. Since Java scripts are usually single-threaded in web browsers, this means that all code is executed in one thread. If an operation takes a long time, it will block the main thread, causing the user interface to freeze or become unresponsive.

[0081] In order to overcome the limitation of the single-thread processing mode of Java scripts, the prior art introduces Web worker threads, which can create worker threads independent of the main thread, allowing complex computing tasks to be placed in the background worker threads. These complex computing tasks are processed by running Java code in the worker threads without interfering with the operation of the main thread, thereby avoiding blocking the main thread.

[0082] However, as an interpreted language, Java script needs to be interpreted and executed line by line by the interpreter at runtime. This means that every time a Java script is run, the interpreter needs to convert the source code into machine code before it can be executed. This process adds additional overhead and results in low execution efficiency.

[0083] Since Web worker threads are a mechanism for running Java scripts in the background, the life cycle of Web worker threads is bound to the life cycle of the page or script that created them. Once the page is closed or refreshed, the Web worker thread will also be terminated. It can be understood that Web worker threads cannot continue to run after the web page is closed. If there are network requests being processed in the Web worker thread at this time, these network requests will be interrupted. These network requests can only be reprocessed when the page is reopened, which may cause a certain delay.

[0084] In addition, by default, each Web worker thread cannot directly share memory. If you want to share data between multiple Web worker threads, you usually need to transfer data through the main thread, which increases the complexity and processing time of data operations. At the same time, each time a Web worker thread needs data, it will initiate a new data request to the server. This method may cause high network latency and bandwidth consumption, especially when data is requested frequently. Frequent requests increase the load on the server, resulting in reduced server performance or longer response time.

[0085] It can be seen that the above-mentioned series of problems will slow down the processing speed of network requests.

[0086] In response to the above technical problems, the inventors discovered during their research on processing network requests based on Web worker threads that the main reason why the speed of processing network requests by Web worker threads is still slow is that data sharing between Web worker threads and data requests of Web worker threads need to be transmitted through the main thread. Based on this, the inventors thought of reducing the frequency of data transmission through the main thread by setting up a cache mechanism and configuring corresponding cache strategies for network requests. In some cases, network requests can be processed by caching data without having to transmit data through the main thread, thereby avoiding the delay caused by transmitting data on the main thread and improving the processing speed of network requests.

[0087] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0088] An embodiment of the present application provides a network request method. Figure 1 Schematic diagram of the process of network request processing method provided in the embodiment of the present application Figure 1 .like Figure 1 As shown, the network request processing method includes:

[0089] S101: Obtain a pending network request initiated by a Web application.

[0090] The execution subject of the embodiment of the present application is an electronic device, which can be a terminal device or a server. In practical applications, whether the electronic device is a terminal device or a server can be determined according to actual conditions and is not specifically limited.

[0091] Among them, a web application is an application program accessed through a web browser, which can provide various functions, ranging from simple information display to complex interactive applications, such as email clients, social media platforms, online office suites, etc. For example, a user can interact with a web application through a web browser. When a user enters a web page address in a web browser and accesses a web application, the web browser will initiate a corresponding pending network request.

[0092] In addition, pending network requests can also be automatically initiated by web applications programmatically.

[0093] S102: Determine a target cache strategy pre-configured for the network request to be processed from multiple cache strategies.

[0094] The cache strategy refers to the rules and methods for managing and using response information to improve system performance, reduce latency, reduce server load, and save bandwidth. The cache strategy determines which response information should be cached, how long to cache, when to update the cache, and how to handle cache invalidation.

[0095] Understandably, choosing an appropriate target cache strategy for pending network requests requires comprehensive consideration of multiple factors, such as data characteristics, system performance requirements, user experience, network conditions, and cache storage limitations, etc. Among them, data characteristics are a very important consideration.

[0096] Specifically, data characteristics include the frequency of data changes, the importance of data, and the size of data. The frequency of data changes means that if data changes frequently, a shorter cache time or more frequent data validity checks may be required; the importance of data means that key data needs to ensure its accuracy, and a stricter cache strategy may be required; the size of data means that large data may need to be saved more carefully to avoid taking up too much cache space.

[0097] Similarly, before obtaining pending network requests initiated for Web applications, the network requests that have occurred and the response information corresponding to the network requests are analyzed to understand the resource access patterns and data change patterns of the network requests, and then a variety of different caching strategies are formulated based on the analysis results to improve system performance and response speed.

[0098] Specifically, the cache strategy corresponding to the network request can be determined according to the update frequency and update data volume of the response information corresponding to each network request initiated by the Web application. The server returns data to the Web application according to the network request sent by the Web application and displays it on the web page of the Web browser. This process is called response, and the response information is the server's reply to the network request.

[0099] Exemplarily, the formulated cache policies may include, but are not limited to, a cache priority policy, a network priority policy, and an update policy at any time.

[0100] Explanatory, the cache priority strategy means first getting the response information from the cache. If the response information exists in the cache, the response information in the cache is directly returned; if the response information is not found in the cache, the response information is obtained from the network and stored in the cache. This cache strategy is suitable for scenarios with static resources and infrequently updated data. The network priority strategy means first trying to get the response information from the network. If the acquisition is successful, the response information obtained from the network is returned and stored in the cache; if the acquisition fails (such as the user is offline), the response information is obtained from the cache. This cache strategy is suitable for scenarios with data and dynamic content that need to be updated in real time. The update at any time strategy means initiating a cache acquisition request and a network acquisition request at the same time, first returning the response information in the cache, and then updating the cache and returning the latest response information after the network acquisition request is completed; this cache strategy can ensure that the user can quickly see the response information in the cache, while obtaining the latest response information and updating the cache in the background. It is suitable for scenarios that require fast response but also want to keep the data up to date.

[0101] In a possible implementation, determining a cache strategy corresponding to a network request according to the update frequency and update data volume of the response information corresponding to each network request can be implemented by the following steps:

[0102] Step a1: If the update frequency of the response information corresponding to the network request is less than or equal to the preset frequency, a first cache strategy is configured for the network request.

[0103] Among them, the first cache strategy indicates to obtain the response information corresponding to the network request from the cache. The response information in the cache can usually be accessed faster, reducing network latency. The update frequency of the response information is less than or equal to the preset frequency, which means that the data does not need to be updated frequently. Therefore, the first cache strategy can be implemented as a cache priority strategy, and the specific implementation method of the first cache strategy is not limited here.

[0104] Step a2: If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume exceeds the preset update data volume, a second cache strategy is configured for the network request.

[0105] Among them, the second cache strategy indicates to obtain the response information corresponding to the network request from the server, and the response information is obtained from the server first, which can ensure that the user sees the latest data. The update frequency of the response information is greater than the preset frequency, and the amount of updated data exceeds the preset update data amount, which means that the frequency of data changes is high, and the real-time nature of the response information needs to be ensured. Therefore, the second cache strategy can be implemented as a network priority strategy, and the specific implementation method of the second cache strategy is not limited here.

[0106] Step a3: If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume does not exceed the preset update data volume, a third cache strategy is configured for the network request.

[0107] Among them, the third cache strategy indicates to obtain the response information corresponding to the network request from the server and the cache. The user can immediately see the response information in the cache, and the cache will be updated to always ensure that the response information in the cache is the latest. The update frequency of the response information is greater than the preset frequency, and the amount of updated data does not exceed the preset update data amount, which means that it is necessary to respond to the network request quickly, and only update the changed data part each time, instead of obtaining the complete data every time. Therefore, the third cache strategy can be implemented as an update strategy at any time, and the specific implementation method of the third cache strategy is not limited here.

[0108] Furthermore, after formulating a plurality of different cache strategies, a target cache strategy configured for a pending network request may be determined from the plurality of cache strategies.

[0109] S103: Obtain target response information corresponding to the network request to be processed according to the target cache strategy.

[0110] It is understandable that different cache strategies have different processing methods. According to the determined target cache strategy, it is decided how to process the pending network request to obtain the target response data. The specific implementation method will vary according to the different target cache strategies, but the ultimate goal is to obtain the most appropriate target response information.

[0111] Specifically, if the target cache strategy is the first cache strategy mentioned above, the pending network request is sent to the cache through the Web application, and the cache response information returned by the cache to the Web application is the target response information corresponding to the pending network request. If there is currently no cache response information corresponding to the pending network request in the cache. For example, there is no response data in the cache that can process the network request, or the cache response information in the cache has expired, then try to obtain the relevant target response information from the server. After successful acquisition, the target response information obtained from the server is placed in the cache to update the cache. It should be noted that if there is no response data in the cache that can process the network request, the target response information obtained from the server is directly placed in the cache. If the cache response information in the cache has expired, when the target response information is placed in the cache and the previous cache response information is updated to the target response information, the previous cache response information is deleted.

[0112] If the target cache strategy is the second cache strategy, the web application sends a pending network request to the server, and the server returns the corresponding target response information to the web application and puts the target response information into the cache to update the cache data.

[0113] It should be noted that if the pending network request fails, it means that the server cannot currently process the network request, and the Web application will receive the acquisition failure information returned by the server. Further, the Web application will obtain the target response information corresponding to the pending network request from the cache. If there is no relevant response information in the cache, the Web application will inform the user that the data cannot be obtained or the data is loading, and suggest the user to try again later.

[0114] If the target cache strategy is the third cache strategy, then while obtaining the cache response information corresponding to the pending network request from the cache, the target response information corresponding to the pending network request is also obtained from the server. After obtaining the cache response information and the target response information, the cache response information is first returned to the Web application, and then the target response information is placed in the cache to update the cache data, ensuring that the cache response information returned to the Web application is the latest.

[0115] It is worth noting that as long as there is a situation where the target response information is obtained from the server, the cache response information corresponding to the pending network request in the cache is updated using the target response information.

[0116] S104: Display target response information in the Web application.

[0117] It is understandable that displaying the target response information in a Web application involves displaying the target response information on a user interface of the Web application, wherein the target response information is displayed to the user in a certain manner, and the display manner may include various forms, such as text, charts, images, videos, etc.

[0118] Exemplarily, if the target cache strategy is the third cache strategy described above, displaying the target response information in the Web application can be achieved by the following steps:

[0119] Step b1: Obtain cache response information corresponding to the pending network request from the cache.

[0120] It should be understood that this step is to obtain cache response information related to the pending network request from the local cache. The cache is usually used to store previously obtained data for fast access, reduce the number of requests to the server, and improve the response speed of the application.

[0121] Step b2: Obtain target response information corresponding to the pending network request from the server.

[0122] It should be understood that this step is to send a pending network request to the server to obtain the latest target response information. The server will return the latest target response information, which is more accurate and real-time than the cached response information in the cache.

[0123] Step b3: Display cache response information in the Web application.

[0124] It should be understood that this step is to display the cached response information in the cache on the user interface of the Web application before obtaining the target response information returned by the server, thereby providing timely feedback and reducing user waiting time.

[0125] Step b4: Refresh the Web application using the target response information so that the Web application displays the target response information.

[0126] It should be understood that this step is to use the latest target response information to refresh the user interface of the Web application once the latest target response information is obtained from the server, replacing the previously displayed cached response information to ensure that the user ultimately sees the latest and most accurate data, while using the cache to reduce the initial waiting time.

[0127] Among them, refreshing the Web application through the target response information can be achieved in the following two ways: First, use the target response information to replace the cached response information; this method is equivalent to directly replacing the cached response information and refreshing the interface, which is suitable for scenarios where data changes greatly or requires complete updates, such as content updates of news articles. Second, obtain the updated data of the target response information relative to the cached response information, and refresh the Web application according to the updated data; this method only updates the changed part, reduces interface flickering and large changes, and is suitable for scenarios where data changes are small or require frequent updates, such as social media comment updates.

[0128] The network request processing method provided by the present application obtains the pending network request initiated by the Web application, and determines the target cache strategy pre-configured for the pending network request from multiple cache strategies; wherein the cache strategy is determined according to the update frequency and update data volume of the response information corresponding to each network request. According to the target cache strategy, the target response information corresponding to the pending network request is obtained, and the target response information is displayed in the Web application. In some cases, when the target response information corresponding to the pending network request already exists in the cache, the target response information can be obtained directly from the cache without sending a request to the server again, reducing the server load and response time. At the same time, obtaining the target response information from the cache reduces the data transmission path and reduces network latency. Through the target cache strategy, previously cached data can also be accessed when there is no network connection, providing certain offline functions to process network requests. Therefore, by configuring a suitable target cache strategy, the processing speed of network requests can be greatly improved.

[0129] Next, a specific embodiment is used to Figure 1 The network request processing method shown is further explained.

[0130] Considering that Java script is suitable for general Web development tasks, such as Document Object Model (DOM) operation, event processing, simple data processing, etc., the performance of Java script may be limited when facing complex logic processing and computationally intensive tasks. Therefore, this embodiment chooses to use Wasm to process complex logic processing and computationally intensive tasks, and chooses to interoperate Wasm with Java script, that is, using Wasm to process complex logic processing and computationally intensive tasks, and using Java script to process other tasks.

[0131] In addition, since the Web worker thread cannot continue to run after the web page is closed, and each Web worker thread cannot directly share memory, data transfer is usually required through the main thread. In order to avoid delays caused by Web worker threads in processing network requests and increase the processing speed of network requests, this embodiment chooses to use service worker threads for improvement. Specifically, service worker threads can intercept network requests and return response information based on the cache strategy; at the same time, service worker threads have independent life cycles, they run in the background and do not depend on the existence of Web pages, which allows Web applications to work offline.

[0132] It can be seen that the combination of Wasm and service worker threads can improve the processing speed of network requests and effectively utilize resources. Specifically, when Wasm is executed in a service worker thread, network requests can be separated from the main thread to avoid the main thread from stalling. The service worker thread's ability to cache resources can also be used to intercept and process network requests. According to different caching strategies, data extraction efficiency can be optimized, server resource usage can be reduced, and user experience can be improved.

[0133] Figure 2 Schematic diagram of the process of network request processing method provided in the embodiment of the present application Figure 2 ,like Figure 2 As shown in the figure, the network request processing process specifically includes the following steps:

[0134] S201. A Web application initiates a task request.

[0135] For example, the task requests initiated by Web applications are diverse, and common task types include network and system management, file and document processing, real-time communication and writing, e-commerce and recommendation systems, complex logic tasks, and computationally intensive tasks.

[0136] Among them, complex logic tasks usually involve multi-step business processes, rule engines, conditional judgments, and data processing, such as order processing, customer relationship management, financial management, and resource management. Computation-intensive tasks usually require a large amount of computing resources to process large-scale data or complex algorithms, such as data analysis and mining, scientific computing, image and video processing, machine learning, and artificial intelligence.

[0137] S202: The service worker thread background allocates task requests.

[0138] Specifically, in order to improve the performance and offline capabilities of Web applications, register a service worker thread in the main thread: first, you need to create a service worker thread file and add some basic code to it, which may include pre-caching some resources, cleaning up old caches, intercepting task requests and providing cached resources, etc. Secondly, add corresponding code to the core file of the main thread (such as a Java script file) to register the service worker thread so that the Web browser can recognize and install the service worker thread. It should be noted that if the service worker thread registration fails, the developer should check and repair the code in the relevant files (such as the service worker thread file and the core file of the main thread).

[0139] It can be understood that as a background script, the service worker thread can receive, process and assign various task requests, intercept network requests, cache resources, synchronize data, etc. to improve the performance and user experience of Web applications.

[0140] S203: The service worker thread determines whether the task request needs to use the cache.

[0141] If the cache does not need to be used, execute S204; if the cache needs to be used, directly execute S207.

[0142] S204: Send a resource acquisition request to the server.

[0143] S205: The server assembles response data corresponding to the resource acquisition request.

[0144] S206. Send the response data to Wasm through the service worker thread.

[0145] S207, the service worker thread assigns the task request to Wasm.

[0146] For example, when a user visits a web page, the service worker thread can intercept the task request and check whether there is cached response information. If there is, it directly returns the cached response information, otherwise it initiates a request to the server and caches the response information. For example, when a user requests an image resource, the service worker thread first checks the local cache. If the image is in the cache, it returns the image in the cache, otherwise it requests the server and caches the image.

[0147] It is understandable that considering that processing complex logic processing and computationally intensive tasks will take up a lot of resources and require a long time to run, it may cause the user interface to freeze or become unresponsive, seriously affecting the user experience. Therefore, in order to avoid the above situation, this embodiment chooses to process complex logic processing and computationally intensive tasks in the service worker thread. The service worker thread runs in an independent thread and will not block the main thread, thereby maintaining the smoothness and responsiveness of the user interface.

[0148] Since this embodiment uses a combination of Wasm and service worker threads to process task requests, it is also necessary to write a Wasm module and add corresponding code in the service worker thread file to load and instantiate the Wasm module and perform necessary initialization operations for subsequent use.

[0149] Specifically, the steps for designing a Wasm module are as follows:

[0150] (1) Determine requirements and goals: clarify what functions you want to achieve through the Wasm module;

[0151] (2) Select programming language: Wasm supports multiple programming languages, including but not limited to C, C++, Rust, etc.

[0152] (3) Write source code: Write the corresponding source code according to the requirements and goals;

[0153] (4) Configure the compilation environment: Different programming languages ​​have different compilation environment chains;

[0154] (5) Compile to Wasm module: Use the corresponding tool chain to compile the source code into a Wasm module;

[0155] (6) Optimization and debugging;

[0156] (7)Integrated into the service worker thread.

[0157] From the above analysis, we can see that complex logic processing and computationally intensive tasks are handled by the Wasm module in the service worker thread. Therefore, the Wasm module should also include necessary functions for complex logic services and computationally intensive tasks.

[0158] S208. Process the task request through Wasm.

[0159] S209, Wasm returns the processing result to the main thread.

[0160] Specifically, after the Wasm module receives the task request assigned by the service worker thread, it calls the pre-set function to process complex logic and computationally intensive tasks, and returns the processing results to the main thread. Wasm is an efficient, portable, and compact binary code format. This format design enables it to be close to native performance, which means that Wasm can handle complex logic and computationally intensive tasks very efficiently and speed up the processing of task requests.

[0161] The network request processing method provided by the present application executes the Wasm module in the service worker thread, which can separate the task request from the main thread and avoid the jamming of the main thread. The service worker thread's ability to cache resources can also be used to intercept and process task requests, transfer some task requests that need to be processed on the back end to the front end, and optimize data extraction efficiency and reduce server resource occupancy rate according to different caching strategies. Furthermore, processing task requests on the front end can reduce network data transmission and improve computing efficiency. Therefore, the high-performance computing capability of Wasm is combined with the background execution of the service worker thread, and its efficiency is obviously improved by using Java scripts to process task requests in the main thread, which significantly improves the processing speed of task requests.

[0162] Figure 3 This is a schematic diagram of the structure of the network request processing device provided in the embodiment of the present application. Figure 3 As shown, the network request processing device includes: an acquisition module 301, a determination module 302, and a display module 303;

[0163] Wherein, the acquisition module 301 is used to acquire the pending network request initiated by the Web application;

[0164] A determination module 302 is used to determine a target cache strategy pre-configured for the network request to be processed from a plurality of cache strategies, the cache strategy being used to instruct to obtain target response information corresponding to the network request to be processed from a server and / or cache corresponding to the Web application;

[0165] The acquisition module 301 is further used to acquire target response information corresponding to the to-be-processed network request according to the target cache strategy;

[0166] The display module 303 is used to display the target response information in the Web application.

[0167] In a possible design, the determining module 302 is further configured to:

[0168] According to the update frequency and update data volume of response information corresponding to each network request, a cache strategy corresponding to the network request is determined, and the network request is initiated for the Web application.

[0169] In a possible design, the determining module 302 further includes: a configuring module 304, configured to:

[0170] If the update frequency of the response information corresponding to the network request is less than or equal to the preset frequency, configuring a first cache strategy for the network request, wherein the first cache strategy indicates obtaining the response information corresponding to the network request from the cache;

[0171] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume exceeds the preset update data volume, a second cache strategy is configured for the network request, wherein the second cache strategy indicates obtaining the response information corresponding to the network request from the server;

[0172] If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data amount does not exceed the preset update data amount, a third cache strategy is configured for the network request, and the third cache strategy indicates obtaining the response information corresponding to the network request from the server and the cache.

[0173] In a possible design, the acquisition module 301 is further used to:

[0174] Obtaining cache response information corresponding to the pending network request from the cache;

[0175] Obtain target response information corresponding to the to-be-processed network request from the server.

[0176] In a possible design, the display module 303 further includes: a refresh module 305, and the display module 303 is further used to display the cache response information in the Web application;

[0177] The refresh module 305 is used to refresh the Web application through the target response information so that the Web application displays the target response information.

[0178] In a possible design, the display module 303 further includes: a processing module 306, configured to:

[0179] In the Web application, using the target response information to replace and display the cached response information;

[0180] or,

[0181] Obtaining update data of the target response information relative to the cache response information;

[0182] The Web application is refreshed according to the update data so that the Web application displays the target response information.

[0183] In a possible design, the acquisition module 301 further includes: a sending module 307, configured to:

[0184] Sending the pending network request to the server;

[0185] The acquisition module is further configured to acquire target response information corresponding to the to-be-processed network request from the cache if acquisition failure information returned by the server is received.

[0186] In one possible design, the apparatus further includes: an updating module 308, configured to:

[0187] If the target response information is obtained from the server, the cache response information corresponding to the to-be-processed network request in the cache is updated using the target response information.

[0188] In a possible design, the apparatus further includes: a deleting module 309, configured to:

[0189] If the cache policy corresponding to any cache response information in the cache is the first cache policy, the cache response information is deleted when the current time is the update time of the cache response information.

[0190] The network request processing device provided in the embodiment of the present application can be used to execute the technical solution of the network request processing method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0191] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the determination module 302 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above determination module 302. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0192] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown, the electronic device may include: a transceiver 41 , a processor 42 , and a memory 43 .

[0193] The processor 42 executes the computer execution instructions stored in the memory, so that the processor 42 executes the scheme in the above embodiment. The processor 42 can be a general-purpose processor, including a central processing unit CPU, a network processor (NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0194] The memory 43 is connected to the processor 42 via a system bus and completes communication between them. The memory 43 is used to store computer program instructions.

[0195] The transceiver 41 may be used to communicate with other devices.

[0196] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.

[0197] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.

[0198] The electronic device provided in the embodiment of the present application is used to execute the technical solution of the network request processing method in the above embodiment.

[0199] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the network request processing method in the above embodiment.

[0200] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the network request processing method in the above embodiment.

[0201] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the network request processing method in the above embodiment.

[0202] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0203] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.

[0204] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0205] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0206] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

[0207] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0208] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0209] The above storage medium 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 memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0210] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.

[0211] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0212] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A network request processing method, characterized in that: include: Get pending network requests initiated for global WAN web applications; Determine a target cache strategy pre-configured for the network request to be processed from a plurality of cache strategies, the cache strategy being used to instruct to obtain target response information corresponding to the network request to be processed from a server and / or cache corresponding to the Web application; According to the target cache strategy, obtaining target response information corresponding to the pending network request; The target response information is displayed in the Web application.

2. The method according to claim 1, characterized in that Before obtaining the pending network request initiated by the Web application, the method further includes: According to the update frequency and update data volume of response information corresponding to each network request, a cache strategy corresponding to the network request is determined, and the network request is initiated for the Web application.

3. The method according to claim 2, characterized in that Determining the cache strategy corresponding to each network request according to the update frequency and update data volume of the response information corresponding to each network request includes: If the update frequency of the response information corresponding to the network request is less than or equal to the preset frequency, configuring a first cache strategy for the network request, wherein the first cache strategy indicates obtaining the response information corresponding to the network request from the cache; If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data volume exceeds the preset update data volume, a second cache strategy is configured for the network request, wherein the second cache strategy indicates obtaining the response information corresponding to the network request from the server; If the update frequency of the response information corresponding to the network request is greater than the preset frequency, and the update data amount does not exceed the preset update data amount, a third cache strategy is configured for the network request, and the third cache strategy indicates obtaining the response information corresponding to the network request from the server and the cache.

4. The method according to claim 3, characterized in that When the target cache strategy is the third cache strategy, obtaining target response information corresponding to the to-be-processed network request according to the target cache strategy includes: Obtaining cache response information corresponding to the pending network request from the cache; Obtaining target response information corresponding to the to-be-processed network request from the server; Accordingly, displaying the target response information in the Web application includes: Displaying the cache response information in the Web application; The Web application is refreshed according to the target response information, so that the Web application displays the target response information.

5. The method according to claim 4, characterized in that The refreshing of the Web application by using the target response information includes: In the Web application, using the target response information to replace and display the cached response information; or, Obtaining update data of the target response information relative to the cache response information; The Web application is refreshed according to the update data so that the Web application displays the target response information.

6. The method according to claim 3, characterized in that When the target cache policy is the second cache policy, obtaining target response information corresponding to the to-be-processed network request according to the target cache policy includes: Sending the pending network request to the server; If the acquisition failure information returned by the server is received, the target response information corresponding to the to-be-processed network request is acquired from the cache.

7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: If the target response information is obtained from the server, the cache response information corresponding to the to-be-processed network request in the cache is updated using the target response information.

8. The method according to any one of claims 3 to 6, characterized in that: The method further comprises: If the cache policy corresponding to any cache response information in the cache is the first cache policy, the cache response information is deleted when the current time is the update time of the cache response information.

9. A network request processing device, characterized in that: include: An acquisition module, used to acquire pending network requests initiated by a global wide area network web application; A determination module, used to determine a target cache strategy pre-configured for the pending network request from a plurality of cache strategies, the cache strategy being used to instruct to obtain target response information corresponding to the pending network request from a server and / or cache corresponding to the Web application; The acquisition module is further used to acquire target response information corresponding to the to-be-processed network request according to the target cache strategy; The display module is used to display the target response information in the Web application.

10. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.

12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 8 when being executed by a processor.

Citation Information

Patent Citations

  • Method and device for data caching and computer processing equipment

    CN107451236A

  • Caching method and device, electronic equipment and computer readable storage medium

    CN112035529A

  • Data acquisition method and device and readable storage medium

    CN113329051A

  • Request response method and device

    CN114531489A

  • Service data acquisition method and device, storage medium and computer equipment

    CN116886771A