A method, system, device and medium for optimizing request
By implementing a response and request data caching system, duplicate front-end requests are minimized, reducing resource waste and ensuring consistent data responses through queue management and real-time updates.
Patent Information
- Application Number
- CN202211234596.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-10
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2042-10-10
AI Technical Summary
Existing front-end requests often result in duplicate requests, leading to resource waste and data asynchrony due to multiple modules initiating the same request, causing inconsistent response data.
A method involving the creation of a response data resource pool for caching response data and a request data resource pool for caching request data, with steps to analyze requests, check for identical requests, and manage request queues to avoid duplicate requests and unify response data.
This approach reduces resource waste and ensures consistent response data by caching and managing request queues, preventing duplicate requests and synchronously updating pages with real-time data changes.
Smart Images

Figure CN115643308B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of front-end development technology, and in particular to a method, system, device and medium for optimizing requests. Background Art
[0002] The front-end is a rapidly developing field, and in the front-end technology stack, front-end requests are the most common field. Static pages are made dynamic by requesting interface data. Existing front-end requests are initiated individually, but as the size of front-end applications gradually increases, it is common for multiple modules to initiate the same request, which will cause duplicate requests. For dynamic data, multiple identical requests in a short period of time will cause inconsistent response data, resulting in resource waste and data asynchrony. Summary of the invention
[0003] In order to unify response data and avoid repeated requests, the present invention provides a method for optimizing requests, the method comprising the following steps:
[0004] S1. Create a response data resource pool for caching response data and a request data resource pool for caching request data;
[0005] S2. Get the first request;
[0006] S3. Analyze the first request and determine whether to update according to the identifier. If so, execute step S5; if not, execute step S4;
[0007] S4. Determine whether there is response data of the first request in the response data resource pool. If so, return the response data of the first request. If not, execute step S5;
[0008] S5. Determine whether there is a second request in the request data resource pool that is the same as the first request. If so, execute step S6; if not, execute step S7;
[0009] S6. Bind the first preset function to the second request, after the second request is completed, obtain the first response data of the second request, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request;
[0010] S7. storing the first request in the request data resource pool, executing the second preset function bound to the first request in the request data resource pool, and returning the response data of the first request;
[0011] S8. Remove the first request from the request data resource pool, and cache the response data of the first request in the response data resource pool.
[0012] The principle of the present invention is as follows: by creating a response data resource pool to cache response data, by creating a request data resource pool to cache request data, a first request is obtained, and whether to update is determined based on an identifier. The purpose is to determine whether the response data value of the first request is obtained from the response data resource pool or from the first request itself. When an update is required, the response data value of the first request is obtained from the first request itself. When an update is not required, the response data value of the first request is obtained from the response data resource pool. When the response data value of the first request is obtained from the response data resource pool, it is necessary to determine whether there is response data of the first request in the response data resource pool. If there is response data of the first request in the response data resource pool, the response data of the first request is directly returned. If there is no response data of the first request in the response data resource pool, the response data value of the first request needs to be obtained from the first request itself. When the response data value of the first request is obtained from the first request itself, it is necessary to first search whether there is a request identical to the first request in the request data resource pool. If there is a second request identical to the first request, the response data is directly distributed to the first request by means of the first preset function after the second request is completed, so as to avoid instantaneous repeated requests. If there is no request identical to the first request in the request data resource pool, the first request is added to the request queue, the request is completed and the response data is returned by executing the second preset function, and the first request is removed from the request data resource pool after completion to avoid occupying resource space, and the returned response data is cached in the response data resource pool, and when the same request is triggered later, the response data in the response data resource pool is directly returned. The present invention avoids instantaneous multiple identical requests by retrieving the queue in the request before the request, and distributes the response data to other triggerers after the request is completed. At the same time, the response data is cached to avoid repeated requests and unify the response data.
[0013] Preferably, analyzing the first request and determining whether to update according to the identifier includes: calling a forced update parameter, and when the call result is false, obtaining data from the response data resource pool; when the call result is true, obtaining data from the request data resource pool.
[0014] Among them, the principle of the forced update parameter (such as the forceUpdate parameter) is that when some variables in the data are too deep (such as adding attributes to arrays or objects in the data), the view update will not be automatically triggered when the data is updated. At this time, the view update can be automatically triggered by calling the forceUpdate parameter. When the front end processes the first request, by calling the forced update parameter, the default call result is false. At this time, there is no need to force update. The response data of the first request is obtained from the response data resource pool. When the call result is true, a forced update is required at this time. The first request is placed in the request data resource pool, and then the first request is processed and the response data is returned.
[0015] Preferably, obtaining the first response data of the second request, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request includes: obtaining the first response data after the second request is completed, traversing the bound functions in the request data resource pool, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request.
[0016] Among them, a first request is obtained, and a second request that is the same as the first request has been initiated but has not been completed. At this time, a first preset function is bound to the second request, and the first response data is obtained after the second request is completed. Since other requests also occur in the request data resource pool at the same time and are also bound to preset functions, the first response data is passed to the first preset function by traversing the preset functions that have been bound in the request data resource pool, and then the response data of the first request is returned by executing the first preset function. This can avoid making multiple identical requests instantly, and distribute the response data to other triggers of the same request such as the first request after the second request is completed.
[0017] Preferably, removing the first request from the request data resource pool and caching the response data of the first request to the response data resource pool includes: setting a first cache time for the response data of the first request, when the cache time of the response data of the first request in the response data resource pool exceeds the first cache time, determining that the response data of the first request is invalid and removed; when the cache time of the response data of the first request in the response data resource pool is within the first cache time, determining that the response data of the first request is valid and maintained.
[0018] The update frequency of the response data is controlled by setting the cache time. When the cache time of the response data exceeds the preset cache time, the response data is considered invalid and removed. When the cache time of the response data is within the preset cache time, the response data is considered valid and maintained. Since the frequency of use and memory usage of the response data vary, and the capacity of the response data resource pool needs to be considered, the cache time setting will also be different.
[0019] Preferably, the method further comprises: rendering the page according to the response data, and synchronously updating the page by monitoring data changes in the response data resource pool.
[0020] Among them, when the request is completed and the response data is returned, the page is rendered according to the returned response data and presented to the user, and then the page is synchronously updated by monitoring the data changes in the response data resource pool.
[0021] In order to avoid repeated requests and unify response data, the present invention also provides a system for optimizing requests, the system comprising:
[0022] A creation unit, used to create a response data resource pool for caching response data and a request data resource pool for caching request data;
[0023] An acquiring unit, configured to acquire a first request;
[0024] A first determination unit, configured to analyze the first request and determine whether to update according to the identifier, if yes, execute step S5, if no, execute step S4;
[0025] A second judgment unit is used to judge whether there is response data of the first request in the response data resource pool, and if so, return the response data of the first request; if not, execute step S5;
[0026] A third judgment unit is used to judge whether there is a second request identical to the first request in the request data resource pool, if so, execute step S6, if not, execute step S7;
[0027] a first execution unit, configured to bind a first preset function to the second request, obtain first response data of the second request after the second request is completed, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request;
[0028] A second execution unit, configured to store the first request into the request data resource pool, execute a second preset function bound to the first request in the request data resource pool, and return response data of the first request;
[0029] An updating unit is used to remove the first request from the request data resource pool and cache the response data of the first request in the response data resource pool.
[0030] Preferably, the system also includes an analysis unit, which is used to analyze the first request and call forced update parameters. When the call result is false, data is obtained from the response data resource pool, and when the call result is true, data is obtained from the request data resource pool.
[0031] Preferably, the system further comprises a rendering unit, and the rendering unit is used for rendering according to the response data, and performing synchronous update by monitoring data changes in the response data resource pool.
[0032] The present invention also provides a device for optimizing requests, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method for optimizing requests when executing the computer program.
[0033] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for optimizing the request are implemented.
[0034] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:
[0035] By retrieving the request queue before making a request, we can avoid making the same request multiple times instantly, and distribute the response data to other triggers after the request is completed; by caching the response data, we can avoid repeated requests and unify the response data.
[0036] The page is rendered according to the page, and is updated synchronously by monitoring the changes of the response data cached in the response data resource pool;
[0037] Set a cache time for the data in the response data resource pool, update the response data according to the cache time, and reduce the waste of memory resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of the present invention, and do not constitute a limitation on the embodiments of the present invention;
[0039] Figure 1 It is a flowchart of a method for optimizing requests in the present invention;
[0040] Figure 2 It is a schematic diagram of the system composition of an optimization request in the present invention. DETAILED DESCRIPTION
[0041] In order to more clearly understand the above-mentioned purpose, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0042] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those within the scope of this description. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.
[0043] Embodiment 1
[0044] Please refer to Figure 1 , is a flow chart of a method for optimizing requests in the present invention, the method comprising the following steps:
[0045] S1. Create a response data resource pool for caching response data and a request data resource pool for caching request data;
[0046] S2. Get the first request;
[0047] S3. Analyze the first request and determine whether to update according to the identifier. If so, execute step S5; if not, execute step S4;
[0048] S4. Determine whether there is response data of the first request in the response data resource pool. If so, return the response data of the first request. If not, execute step S5;
[0049] S5. Determine whether there is a second request in the request data resource pool that is the same as the first request. If so, execute step S6; if not, execute step S7;
[0050] S6. Bind the first preset function to the second request, after the second request is completed, obtain the first response data of the second request, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request;
[0051] S7. storing the first request in the request data resource pool, executing the second preset function bound to the first request in the request data resource pool, and returning the response data of the first request;
[0052] S8. Remove the first request from the request data resource pool, and cache the response data of the first request in the response data resource pool.
[0053] Among them, analyzing the first request and judging whether to update according to the identifier include: calling the forced update parameter, when the call result is false, obtaining data from the response data resource pool, and when the call result is true, obtaining data from the request data resource pool. Because some variables are not on the state (state variable) or some variables in the state are too deep, the view update is not automatically triggered when updating, but you want to achieve the effect of this variable update, you can manually call forceUpdate (forced update parameter) to automatically trigger the view update. For example, there is a variable name in the data. If it is modified, the page will be automatically updated. However, if the variable in the data is an array or an object, after adding attributes to the array or object, the page cannot be recognized and cannot be automatically updated. Therefore, the view update is automatically triggered by calling forceUpdate (forced update parameter). When analyzing the first request, by calling the forceUpdate parameter, when the call result is false, the data is obtained from the response data resource pool by default. When the call result is true, it means that a forced update is required. At this time, the first request needs to be added to the request data resource pool, and the response data is returned after the first request is completed.
[0054] Among them, obtaining the first response data of the second request, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request include: obtaining the first response data after the second request is completed, traversing the bound functions in the request data resource pool, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request. The premise of binding the first preset function to the second request is that the second request is already in progress but not completed, and the first response data is returned after the second request is completed, by traversing the bound function list in the request data resource pool, passing the first response data to the first preset function, and finally returning the response data of the first request by executing the first preset function. By retrieving the request queue in the request resource pool before the request, it is avoided to make the same request multiple times instantly. In the case of the same request, the response data is distributed to the remaining triggers after the same request in the request queue is completed.
[0055] Wherein, removing the first request from the request data resource pool and caching the response data of the first request in the response data resource pool includes: setting the first cache time of the response data of the first request, when the cache time of the response data of the first request in the response data resource pool exceeds the first cache time, the response data of the first request is determined to be invalid and removed, and when the cache time of the response data of the first request in the response data resource pool is within the first cache time, the response data of the first request is determined to be valid and maintained. For example, if the first cache time is set to one hour, when the cache time of the response data of the first request in the response data resource pool exceeds one hour, the response data of the first request is removed from the response data resource pool, and when the cache time of the response of the first request in the response data resource pool does not exceed one hour, it continues to be maintained. The cache time set may vary depending on the change frequency of the response data, the frequency of use, the memory occupied, and the capacity of the response data resource pool. The cache time may be set by a "timestamp" method (i.e., the cached data is valid before a certain point in time) or a time span method (such as one day, one hour, etc.). The cache time setting method and specific value may be adjusted as needed, and the present invention does not make any specific limitations thereto.
[0056] The method further includes: rendering the page according to the response data, and synchronously updating by monitoring the data changes in the response data resource pool. Page rendering is the process of displaying the data on the page after parsing. For example, there are roughly the following steps from inputting the address to displaying the page in the browser. First, HTML (Hypertext Markup Language) is obtained, and parsing begins after the download is completed. In the process of parsing HTML, if external resources such as css and js are encountered, the browser will immediately download these resources, and then the browser will convert the parsed HTML into a DOM object and assemble a DOM tree (the same is true for css, which will parse css into a css object and assemble it into a CSSOM tree). After the DOM tree and CSSOM tree are constructed, the browser will construct a rendering tree according to the DOM tree and CSSOM tree. After the rendering tree is constructed, the position and style of all elements are determined. The browser then calculates the position, style and size of all elements, and finally presents the page to the user. Therefore, when the response data obtained after the request is completed needs to be presented to the user in the form of a view, the response data needs to be rendered, and the page needs to be updated synchronously by monitoring the data changes in the response data resource pool.
[0057] In an embodiment of the present invention, a request data resource pool for caching request data and a response data resource pool for caching response data are first established, a first request is obtained, the first request is analyzed, and the forceUpdate parameter is called. If the call result is false, a value is taken from the response data resource pool. At this time, it is determined whether there is response data for the first request in the response data resource pool (such as the response data is 1). If there is response data 1 in the response data resource pool at this time, response data 1 is directly returned. If there is no response data 1 in the response data resource pool at this time, the first request is compared with the request queue in the request data resource pool. If the call result is true, the first request is also compared with the request queue in the request data resource pool. If there is a second request identical to the first request in the request queue in the request data resource pool, the first preset function is bound to the second request. At this time, the second request is already in progress but has not been completed. After the second request is completed, the first preset function is obtained. Response data (such as the first response data is 1), traverse the function list bound in the request data resource pool, pass the first response data 1 to the first preset function, and then return the response data of the first request by executing the first preset function. At this time, the response data of the first request is 1. If there is no request identical to the first request in the request queue in the request data resource pool, add the first request to the request queue in the request data resource pool, complete the request in sequence, and return its response data by executing the preset function bound to these request data for the request data in the request queue. When the request in the request queue is completed, remove it from the request data resource pool, and cache the response data returned by the request in the request queue to the response data resource pool. Set the cache time of the first request response data (for example, one day). When the cache time exceeds one day, remove the response data of the first request from the response data resource pool. When the cache time is within one day, keep the response data of the first request in the response data resource pool. Finally, the page renders the response data returned by the first request, and synchronizes and updates it by real-time monitoring the changes of the first request response data in the response data resource pool. The embodiment of the present invention avoids making the same request multiple times instantaneously by retrieving the queue in the request before making the request, and distributes the response data to other triggers after the request is completed; unifies the data value by monitoring the cached data; avoids repeated requests by caching the response data; and determines the update frequency of the response data by setting the cache time to reduce resource waste.
[0058] Embodiment 2
[0059] Please refer to Figure 2 , is a schematic diagram of a system composition of an optimization request in the present invention, the system comprising:
[0060] A creation unit, used to create a response data resource pool for caching response data and a request data resource pool for caching request data;
[0061] An acquiring unit, configured to acquire a first request;
[0062] A first determination unit, configured to analyze the first request and determine whether to update according to the identifier, if yes, execute step S5, if no, execute step S4;
[0063] A second judgment unit is used to judge whether there is response data of the first request in the response data resource pool, and if so, return the response data of the first request; if not, execute step S5;
[0064] A third judgment unit is used to judge whether there is a second request identical to the first request in the request data resource pool, if so, execute step S6, if not, execute step S7;
[0065] a first execution unit, configured to bind a first preset function to the second request, obtain first response data of the second request after the second request is completed, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request;
[0066] A second execution unit, configured to store the first request into the request data resource pool, execute a second preset function bound to the first request in the request data resource pool, and return response data of the first request;
[0067] An updating unit is used to remove the first request from the request data resource pool and cache the response data of the first request in the response data resource pool.
[0068] Among them, the optimization request system also includes an analysis unit, which is used to analyze the first request and call the forced update parameters. When the call result is false, data is obtained from the response data resource pool, and when the call result is true, data is obtained from the request data resource pool.
[0069] The optimization request system further includes a rendering unit, which is used to render according to the response data and perform synchronous updates by monitoring data changes in the response data resource pool.
[0070] Embodiment 3
[0071] Embodiment 3 of the present invention provides an optimization request device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the optimization request method when executing the computer program.
[0072] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors, application-specific integrated circuits, field programmable gate arrays or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0073] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the optimization request device in the invention by running or executing the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory can include a high-speed random access memory and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card, a secure digital card, a flash memory card, at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0074] Embodiment 4
[0075] Embodiment 4 of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for optimizing the request are implemented.
[0076] If the device for optimizing the request is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be stored in a computer-readable storage medium through a computer program. When the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, point carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction.
[0077] The present invention has described the basic concepts. Obviously, for those skilled in the art, the above detailed disclosure is only for example and does not constitute a limitation of this specification. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements and corrections to this specification. Such modifications, improvements and corrections are suggested in this specification, so such modifications, improvements and corrections still belong to the spirit and scope of the exemplary embodiments of this specification.
[0078] At the same time, this specification uses specific words to describe the embodiments of this specification. For example, "one embodiment", "an embodiment", and / or "some embodiments" refer to a certain feature, structure or characteristic related to at least one embodiment of this specification. Therefore, it should be emphasized and noted that "one embodiment" or "an embodiment" or "an alternative embodiment" mentioned twice or more in different positions in this specification does not necessarily refer to the same embodiment. In addition, certain features, structures or characteristics in one or more embodiments of this specification can be appropriately combined.
[0079] In addition, it will be understood by those skilled in the art that various aspects of this specification may be illustrated and described by a number of patentable categories or situations, including any new and useful process, machine, product or combination of substances, or any new and useful improvements thereto. Accordingly, various aspects of this specification may be performed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The above hardware or software may be referred to as "data blocks", "modules", "engines", "units", "components" or "systems". In addition, various aspects of this specification may be represented as a computer product located in one or more computer-readable media, which includes computer-readable program code.
[0080] A computer storage medium may include a propagated data signal containing computer program code, for example, in baseband or as part of a carrier wave. The propagated signal may be in a variety of forms, including electromagnetic, optical, etc., or a suitable combination. A computer storage medium may be any computer-readable medium other than a computer-readable storage medium, which can be connected to an instruction execution system, device or apparatus to communicate, propagate or transmit the program for use. The program code on the computer storage medium may be transmitted via any suitable medium, including radio, cable, fiber optic cable, RF, or similar media, or any combination of the above media.
[0081] The computer program code required for the operation of each part of this specification can be written in any one or more programming languages, including object-oriented programming languages such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB.NET, Python, etc., conventional procedural programming languages such as C language, Visual Basic, Fortran 2003, Perl, COBOL 2002, PHP, ABAP, dynamic programming languages such as Python, Ruby and Groovy, or other programming languages. The program code can be run entirely on the user's computer, or run on the user's computer as an independent software package, or run partially on the user's computer and partially on a remote computer, or run entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer through any network form, such as a local area network (LAN) or a wide area network (WAN), or connected to an external computer (e.g., via the Internet), or in a cloud computing environment, or used as a service such as software as a service (SaaS).
[0082] In addition, unless explicitly stated in the claims, the order of the processing elements and sequences described in this specification, the use of alphanumeric characters, or the use of other names are not intended to limit the order of the processes and methods of this specification. Although the above disclosure discusses some invention embodiments that are currently considered useful through various examples, it should be understood that such details are only for illustrative purposes, and the attached claims are not limited to the disclosed embodiments. On the contrary, the claims are intended to cover all modifications and equivalent combinations that are consistent with the essence and scope of the embodiments of this specification. For example, although the system components described above can be implemented by hardware devices, they can also be implemented only by software solutions, such as installing the described system on an existing server or mobile device.
[0083] Similarly, it should be noted that in order to simplify the description disclosed in this specification and thus help understand one or more embodiments of the invention, in the above description of the embodiments of this specification, multiple features are sometimes combined into one embodiment, figure or description thereof. However, this disclosure method does not mean that the features required by the subject matter of this specification are more than the features mentioned in the claims. In fact, the features of the embodiments are less than all the features of the single embodiment disclosed above.
[0084] Each patent, patent application, patent application publication, and other materials, such as articles, books, specifications, publications, documents, etc., cited in this specification are hereby incorporated by reference in their entirety. Except for application history documents that are inconsistent with or conflicting with the contents of this specification, documents that limit the broadest scope of the claims of this specification (currently or later attached to this specification) are also excluded. It should be noted that if the descriptions, definitions, and / or use of terms in the materials attached to this specification are inconsistent or conflicting with the contents described in this specification, the descriptions, definitions, and / or use of terms in this specification shall prevail.
[0085] Finally, it should be understood that the embodiments described in this specification are only used to illustrate the principles of the embodiments of this specification. Other variations may also fall within the scope of this specification. Therefore, as an example and not a limitation, alternative configurations of the embodiments of this specification may be considered consistent with the teachings of this specification. Accordingly, the embodiments of this specification are not limited to the embodiments explicitly introduced and described in this specification.
[0086] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0087] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for optimizing a request, characterized in that: The method comprises the following steps: S1. Create a response data resource pool for caching response data and a request data resource pool for caching request data; S2. Get the first request; S3. Analyze the first request and determine whether to update according to the identifier. If so, execute step S5; if not, execute step S4; S4. Determine whether there is response data of the first request in the response data resource pool. If so, return the response data of the first request. If not, execute step S5; S5. Determine whether there is a second request in the request data resource pool that is the same as the first request. If so, execute step S6; if not, execute step S7; S6. Bind the first preset function to the second request, after the second request is completed, obtain the first response data of the second request, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request; S7. storing the first request in the request data resource pool, executing the second preset function bound to the first request in the request data resource pool, and returning the response data of the first request; S8. Remove the first request from the request data resource pool, and cache the response data of the first request in the response data resource pool.
2. A method for optimizing requests according to claim 1, characterized in that: Analyzing the first request and determining whether to update according to the identifier includes: calling a forced update parameter, and when the call result is false, obtaining data from the response data resource pool; when the call result is true, obtaining data from the request data resource pool.
3. A method for optimizing requests according to claim 1, characterized in that: Obtaining the first response data of the second request, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request includes: obtaining the first response data after the second request is completed, traversing the bound functions in the request data resource pool, passing the first response data to the first preset function, executing the first preset function, and returning the response data of the first request.
4. The method for optimizing a request according to claim 1, characterized in that: Removing the first request from the request data resource pool and caching the response data of the first request to the response data resource pool includes: setting a first cache time for the response data of the first request; when the cache time of the response data of the first request in the response data resource pool exceeds the first cache time, determining that the response data of the first request is invalid and removed; when the cache time of the response data of the first request in the response data resource pool is within the first cache time, determining that the response data of the first request is valid and maintained.
5. The method for optimizing a request according to claim 1, characterized in that: The method further includes: rendering the page according to the response data, and synchronously updating by monitoring data changes in the response data resource pool.
6. An optimization request system, characterized in that: The system comprises: A creation unit, used to create a response data resource pool for caching response data and a request data resource pool for caching request data; An acquiring unit, configured to acquire a first request; A first determination unit, configured to analyze the first request and determine whether to update according to the identifier, if yes, execute step S5, if no, execute step S4; A second judgment unit is used to judge whether there is response data of the first request in the response data resource pool, and if so, return the response data of the first request; if not, execute step S5; A third judgment unit is used to judge whether there is a second request identical to the first request in the request data resource pool, if so, execute step S6, if not, execute step S7; a first execution unit, configured to bind a first preset function to the second request, obtain first response data of the second request after the second request is completed, pass the first response data to the first preset function, execute the first preset function, and return the response data of the first request; A second execution unit, configured to store the first request into the request data resource pool, execute a second preset function bound to the first request in the request data resource pool, and return response data of the first request; An updating unit is used to remove the first request from the request data resource pool and cache the response data of the first request in the response data resource pool.
7. An optimization request system according to claim 6, characterized in that: The system also includes an analysis unit, which is used to analyze the first request and call the forced update parameter. When the call result is false, data is obtained from the response data resource pool, and when the call result is true, data is obtained from the request data resource pool.
8. An optimization request system according to claim 6, characterized in that: The system further comprises a rendering unit, which is used for rendering according to the response data and performing synchronous update by monitoring data changes in the response data resource pool.
9. An optimization request device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method based on optimization request as claimed in any one of claims 1 to 5 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for optimizing requests as claimed in any one of claims 1 to 5 are implemented.
