An assembly instance caching method, apparatus, device, storage medium and product
Patent Information
- Application Number
- CN202410423084.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2044-04-09
AI Technical Summary
[0004]本发明实施例提供一种组件实例缓存方法、装置、设备、存储介质及产品,解决了无法实时响应网页中的变化的问题,提高了组件更新效率和响应速度
[0016]本发明实施例中,通过在网页中组件的节点树发生变化的情况下,根据所述节点树的参数确定所述组件的节点复杂度和属性复杂度;根据所述节点复杂度和所述属性复杂度,确定所述组件的节点树复杂度;在所述节点树复杂度满足条件的情况下,根据所述节点树复杂度缓存所述组件的实例。本发明的技术方案利用节点复杂度和属性复杂度评估组件的节点树复杂度,并缓存复杂度较高的组件的实例供后续调用和更新,解决了无法实时响应网页中的变化的问题,可适应网页变化,及时更新网页组件,避免重复创建组件实例的开销,提高了组件更新效率和响应速度,达到了优化网页性能的效果。
Smart Images

Figure CN118227909B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of Internet technology, and in particular to a component instance caching method, apparatus, device, storage medium and product. Background Technology
[0002] With the development of the internet, web pages have become an indispensable part of people's daily lives and work, with increasingly diverse functions and ever-increasing demands on web page response speed. However, in many cases, web page performance is poor, mainly manifested in the untimely response of components or elements after user interaction. For example, images or animations in a link may not display promptly after a user opens it, or the loading process may be lengthy, leading to a poor user experience and potentially causing users to abandon the website. Therefore, web page performance optimization has become an increasingly important issue.
[0003] Traditional webpage performance optimization solutions mainly include compression and lazy loading. While these solutions can improve webpage performance to some extent, they still have some drawbacks. For example, compression requires code packaging beforehand, making it impossible to modify the logic to flexibly adapt to changes in the webpage during actual use; and it requires periodic scanning and processing of the entire webpage, making it unable to respond to webpage changes in real time. In summary, existing webpage optimization methods are slow because they cannot update webpage components in a timely manner, cannot flexibly adapt to changes in the webpage, and have slow response times. Summary of the Invention
[0004] This invention provides a component instance caching method, apparatus, device, storage medium, and product, which solves the problem of not being able to respond to changes in web pages in real time and improves component update efficiency and response speed.
[0005] In a first aspect, embodiments of the present invention provide a component instance caching method, including:
[0006] When the node tree of a component in a webpage changes, the node complexity and attribute complexity of the component are determined based on the parameters of the node tree.
[0007] The node tree complexity of the component is determined based on the node complexity and the attribute complexity.
[0008] If the node tree complexity meets the condition, cache the instance of the component according to the node tree complexity.
[0009] Secondly, embodiments of the present invention also provide a component instance caching device, the device comprising:
[0010] The node complexity and attribute complexity determination module is used to determine the node complexity and attribute complexity of a component based on the parameters of the node tree when the node tree of a component in a webpage changes.
[0011] A node tree complexity determination module is used to determine the node tree complexity of the component based on the node complexity and the attribute complexity.
[0012] A caching module is used to cache instances of the component based on the node tree complexity, provided that the node tree complexity meets the required conditions.
[0013] Thirdly, embodiments of the present invention also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the component instance caching method as described in any of the embodiments of the present invention.
[0014] Fourthly, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the component instance caching method as described in any of the embodiments of the present invention.
[0015] Fifthly, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the component instance caching method as described in any of the embodiments of the present invention.
[0016] In this embodiment of the invention, when the node tree of a component in a webpage changes, the node complexity and attribute complexity of the component are determined based on the parameters of the node tree; the node tree complexity of the component is determined based on the node complexity and the attribute complexity; and if the node tree complexity meets a certain condition, an instance of the component is cached based on the node tree complexity. The technical solution of this invention utilizes node complexity and attribute complexity to evaluate the node tree complexity of a component and caches instances of components with higher complexity for subsequent calls and updates. This solves the problem of not being able to respond to changes in the webpage in real time, adapts to webpage changes, updates webpage components promptly, avoids the overhead of repeatedly creating component instances, improves component update efficiency and response speed, and achieves the effect of optimizing webpage performance. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A flowchart illustrating a component instance caching method provided in an embodiment of the present invention;
[0019] Figure 2 A flowchart for calculating the complexity of a node tree provided in an embodiment of the present invention;
[0020] Figure 3 A flowchart illustrating the implementation of a component instance caching method provided in an embodiment of the present invention;
[0021] Figure 4 This is a schematic diagram of the structure of a component instance caching device provided in an embodiment of the present invention;
[0022] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement embodiments of the present invention is provided. Detailed Implementation
[0023] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0024] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0025] The acquisition, storage, use, and processing of data in this application all comply with the relevant provisions of national laws and regulations.
[0026] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the relevant content of the solution.
[0027] Figure 1 This is a flowchart illustrating a component instance caching method provided in an embodiment of the present invention. This embodiment is applicable to situations where component instances are cached. The method can be executed by a component instance caching device, which can be implemented in hardware and / or software and can be configured in an electronic device. Electronic devices include, but are not limited to, computers, terminals, and servers, and other devices with data processing capabilities. Figure 1As shown, the method includes:
[0028] S110. When the node tree of a component in a webpage changes, determine the node complexity and attribute complexity of the component based on the parameters of the node tree.
[0029] In this embodiment, a component can be understood as an entity that encapsulates the data and methods of a webpage. In a webpage, it can be presented as an element in the interface. Commonly used components include tables, trees, or linked dropdown lists. The Document Object Model Tree (DOM tree) is used to describe the hierarchical structure of all elements of a component. Each HTML tag, text node, and attribute can be represented as a node in the DOM tree.
[0030] When changes are detected in the node tree of a component on a webpage, such as when nodes are added, deleted, or modified, the node tree of the component can be traversed and the parameters of the node tree can be counted.
[0031] Optionally, the parameters of the node tree may include at least one of the following: number of nodes, node type, nesting level, number of tags, number of dynamic attributes, and character length. The number of nodes may be the total number of nodes contained in the node tree; the node type may be the specific type of each node in the node tree, for example, node types may include: element nodes, attribute nodes, text nodes, comment nodes, and / or document nodes, etc.; the nesting level may be the depth of the node tree; the number of tags may be the specific number of tags contained in the node tree; the number of dynamic attributes may be the number of nodes in the node tree whose attributes can dynamically change; and the character length may be the length of the characters contained in the node tree. Optionally, each parameter corresponds to a specific weight.
[0032] Following the above description, after obtaining the parameters of the node tree, the node complexity and attribute complexity of the component can be calculated using these parameters. Node complexity reflects the distribution of nodes in the node tree and can be related to the number of nodes, node types, nesting levels, and / or character length. For example, node complexity can be related to the number of nodes, node types, and nesting levels; the more nodes, node types, and nesting levels there are, the higher the node complexity. Node complexity can be obtained by adding, multiplying, or performing other forms of mathematical operations on the relevant factors.
[0033] As described above, attribute complexity reflects the attributes of a node tree. Attribute complexity can be related to the number of nodes, node types, nesting levels, number of tags, number of dynamic attributes, and / or character length in the node tree. For example, attribute complexity is related to the node type, number of tags, and number of dynamic attributes of each node in the node tree. The more node types, tags, and dynamic attributes there are, the higher the attribute complexity. Attribute complexity can be obtained by adding, multiplying, or performing mathematical operations with different weights on the relevant factors, or through other forms of mathematical operations.
[0034] As one implementation method, determining the node complexity of the component based on the parameters of the node tree includes:
[0035] a1) Traverse the node tree of the component and count the number of nodes and the nesting level of the node tree;
[0036] Specifically, you can traverse the node tree of the component and count the number of nodes and the nesting level. For example, the number of nodes can be denoted as x1 and the nesting level can be denoted as y1.
[0037] b1) Add the number of nodes and the number of nesting levels to obtain the node complexity of the component.
[0038] Specifically, the number of nodes and the number of nesting levels of the statistically obtained node tree can be added together to obtain the node complexity of the component, thus realizing a comprehensive and accurate evaluation of the node complexity of the node tree from the perspective of node tree depth.
[0039] For example, if the number of nodes is x1 and the nesting level is y1, the node complexity can be represented as A, then: A = x1 + y1. It should be noted that the node complexity can also be calculated based on the weights of the number of nodes and the nesting level. For example, the weight of the number of nodes can be w1, and the weight of the nesting level can be w2, so the node complexity can be represented as A = w1x1 + w2y1.
[0040] As one implementation method, determining the attribute complexity of the component based on the parameters of the node tree includes:
[0041] a2) Traverse the node tree of the component and count the number of tags and dynamic attributes in the node tree;
[0042] For example, the number of tags can be denoted as x2, and the number of dynamic attributes can be denoted as y2.
[0043] b2) Add the node complexity, the number of tags, and the number of dynamic attributes to obtain the attribute complexity of the component.
[0044] Specifically, the component's attribute complexity can be obtained by adding the node complexity, the number of tags, and the number of dynamic attributes. For example, the number of tags can be x², the number of dynamic attributes can be y², and the attribute complexity can be represented as B, then: B = A + x² + y². This achieves a comprehensive and accurate evaluation of component complexity from the perspectives of node tree depth and width. It should be noted that node complexity can also be calculated based on the weights of node complexity, the number of tags, and the number of dynamic attributes. For example, the weight of node complexity can be w³, the weight of the number of tags can be w⁴, and the weight of the number of dynamic attributes can be w⁵, and the node complexity can be represented as B = w³A + w⁴x² + w⁵y².
[0045] In some embodiments, the attribute complexity can also be calculated by the sum of the number of tags and the dynamic attribute complexity, i.e.: B = x² + y².
[0046] Optionally, the attribute complexity of the component is obtained by adding the node complexity, the number of tags, and the number of dynamic attributes, including:
[0047] The attribute complexity of the component is obtained by calculating the weighted sum of the node complexity, the number of tags, and the number of dynamic attributes based on the first weight of the node complexity, the second weight of the number of tags, and the third weight of the number of dynamic attributes.
[0048] It should be noted that when weight values for node complexity, number of tags, and dynamic attributes exist, the attribute complexity of the component can be obtained by calculating a weighted sum of these three factors based on the first weight of node complexity, the second weight of the number of tags, and the third weight of the number of dynamic attributes. Here, the first weight is the weight value of node complexity, the second weight is the weight value of the number of tags, and the third weight is the weight value of the number of dynamic attributes. Each weight value represents the degree of influence of the corresponding factor on the attribute complexity and can be set according to the actual business scenario and requirements. By assigning different weight values to node complexity, number of tags, and dynamic attributes, the solution can be applied to different business scenarios and meet different needs, improving the applicability and flexibility of the technical solution.
[0049] S120. Determine the node tree complexity of the component based on the node complexity and attribute complexity.
[0050] It is known that after calculating the node complexity and attribute complexity, the node tree complexity of the component can be obtained using these two factors. The node tree complexity reflects the complexity of the node tree. For example, the node tree complexity can be obtained by adding, multiplying, or performing other mathematical operations on the node complexity and attribute complexity.
[0051] For example, Figure 2 A flowchart for calculating the complexity of a node tree provided in an embodiment of the present invention is shown below. Figure 2 As shown, the node tree is traversed, the node complexity is calculated by the number of nodes and the nesting level of the component, the dynamic attribute complexity is calculated by the number of tags and the number of dynamic attributes of the component, and the complexity of the node tree is calculated based on the node complexity and the dynamic attribute complexity. By comprehensively evaluating the component complexity algorithm, the component complexity can be adjusted in a timely manner. In subsequent steps, the caching logic can be dynamically updated to better adapt to changes in user and business scenarios.
[0052] Optionally, the node tree complexity of the component is determined based on the node complexity and the attribute complexity, including:
[0053] The node complexity and the attribute complexity are added together to obtain the node tree complexity of the component.
[0054] Specifically, the node complexity and attribute complexity can be added together to obtain the node tree complexity of the component, thus achieving a comprehensive and accurate assessment of component complexity from the perspectives of node tree depth and width. For example, the node tree complexity can be represented as C, the node complexity as A, and the attribute complexity as B, then: C = A + B.
[0055] S130. If the node tree complexity meets the requirements, cache the component instance based on the node tree complexity.
[0056] It is known that after calculating the complexity of the node tree, it is determined whether the node tree complexity meets certain conditions. These conditions can be that the node tree complexity is within a pre-defined numerical range, or that the node tree complexity is greater than or less than a pre-defined threshold. When the node tree complexity meets these conditions, an instance of the component is cached based on the node tree complexity. An instance can be understood as the result of instantiating the component, or simply an instantiated component. Instantiated components are reusable, and each component has definite data and logic after instantiation. By caching component instances, the component instance can be directly called during subsequent use.
[0057] As described above, when the node tree complexity does not meet the condition, it can be understood that the current component instance is already cached and its complexity is too high to be cached, or the current component's structure is simple, and the resources required to rebuild it are lower than the resources required to cache it. Therefore, when the node tree complexity does not meet the condition, the instance of that node component is not cached. This achieves the technical effect that simple components can be rebuilt and complex components can be directly called when using components, providing convenience for the reuse of complex components while avoiding excessive resource consumption by caching.
[0058] This embodiment provides a component instance caching method, comprising: when the node tree of a component in a webpage changes, determining the node complexity and attribute complexity of the component based on the parameters of the node tree; determining the node tree complexity of the component based on the node complexity and the attribute complexity; and caching the component instance based on the node tree complexity when the node tree complexity meets a certain condition. The technical solution provided by this embodiment achieves the effect of optimizing webpage performance, avoiding the overhead of repeatedly creating component instances, and improving response speed.
[0059] Optionally, if the node tree complexity meets the condition, cache instances of the component based on the node tree complexity, including:
[0060] If the node tree complexity of the component reaches a first threshold and the instance of the component is not cached, then the instance of the component and the node tree complexity are cached.
[0061] Specifically, in order to cache components more efficiently, when caching components, the calculated node complexity of the component is judged. When the node complexity reaches the first threshold and the instance of the component is not cached, the instance of the component and the node tree complexity can be cached so that they can be directly called later, avoiding the overhead of repeatedly creating instances and improving the response speed and performance of the webpage.
[0062] The first threshold can be set according to the actual business scenario and needs. For example, for web pages with high real-time requirements or frequent changes, the first threshold can be set relatively low, so that more complex component instances are more likely to be cached for subsequent calls to respond to web page changes in a timely manner. On the other hand, for web pages with low real-time requirements or high stability (i.e., web pages do not change frequently), the first threshold can be set relatively high, so that sufficiently complex component instances are cached, while other component instances can be temporarily rebuilt to reduce unnecessary cache resources.
[0063] As an optional implementation method, the component instance caching method provided in this embodiment may further include:
[0064] If the node tree complexity of the component reaches a first threshold and the instance of the component and the node tree complexity are cached, the cached node tree complexity is updated according to the node tree complexity determined when the node tree changes.
[0065] Specifically, changes to a component's DOM tree can invalidate its cached information. To ensure component correctness and consistency, the cached information needs to be updated promptly. Specifically, when the component's node tree complexity reaches a first threshold, and the component instance and node tree complexity are already cached, the cached component information can be used to update the cache with recalculated DOM complexity and exposure based on the changes in the node tree. This simplifies the creation process of complex components and avoids the overhead of repeated creation and complexity recalculation.
[0066] As an optional implementation method, the component instance caching method provided in this embodiment may further include:
[0067] When invoking the target component, if an instance of the target component is already cached, the cached instance of the target component is read; otherwise, an instance of the target component is created.
[0068] Specifically, when invoking a target component, the system can check if an instance of that component already exists in the cache. If it does, the cached instance can be retrieved. If not, a new instance of the target component can be created, stored in the cache, and then returned. By first checking if the component is cached, and then directly retrieving it, the overhead of repeatedly creating component instances is avoided, thus improving response speed.
[0069] As one implementation method, creating an instance of the target component includes:
[0070] a3) Determine the exposure of the target component;
[0071] Specifically, we can first determine the exposure of the target component being created, where exposure can refer to the degree of the component's external visibility and accessibility. In software architecture, the exposure of a component can be used to determine whether and how other components or systems can interact with it without breaking encapsulation.
[0072] As described above, the exposure rate of a component can be determined by factors such as the number of page views, the number of times the component is accessed (views), the click-through rate of the component, and / or the time users spend on the page.
[0073] b3) If the exposure reaches the second threshold, create an instance of the target component and render the target component.
[0074] It's important to note that when creating a new instance of a target component, it's also necessary to determine whether the component needs to be rendered based on its exposure. Specifically, this can be determined by considering the target component's exposure and caching strategy. The caching strategy can include how to effectively store and retrieve data to reduce server requests and improve application performance and response speed. If the target component's exposure reaches the second threshold and there is no instance of that target component in the cache, then a new instance of the target component needs to be created and rendered.
[0075] The second threshold can be a threshold for judging the exposure of the created target component. The second threshold can be set according to the actual business scenario and needs. For example, for web pages with high traffic, the second threshold can be set relatively low, so that more component instances that meet the conditions are more likely to be cached for subsequent calls and timely response to web page changes. For web pages with low traffic, the second threshold can be set relatively high, so that frequently accessed component instances that meet the conditions are cached, while other component instances can be temporarily rebuilt to reduce unnecessary caching resources.
[0076] As described above, if the exposure of the target component is lower than the second threshold, the target component instance does not need to be created, thus avoiding unnecessary computation and rendering overhead.
[0077] As an optional implementation method, the component instance caching method provided in this embodiment may further include:
[0078] Register a listener event, in which a callback function is specified. The callback function is used to obtain information about the node tree when a node in the node tree sends a change.
[0079] Specifically, registering a listener event involves specifying a callback function. This callback function can be used to retrieve information about the node tree when a node in the DOM tree changes. For example, when a node in the DOM tree is added, deleted, or modified, this callback function will be called to retrieve the information about the node tree, enabling timely capture of DOM changes on the webpage and thus allowing for real-time and efficient optimization of webpage performance.
[0080] Figure 3 A flowchart illustrating the implementation of a component instance caching method provided in an embodiment of the present invention is shown below. Figure 3 As shown, the process includes the following steps:
[0081] Listening to DOM changes in a webpage can be achieved using event delegation: Event delegation can effectively listen to changes in the DOM tree. By registering a listener event, a callback function can be specified. When a node in the DOM tree is added, deleted, or modified, the callback function will be called, thereby capturing DOM changes in the webpage in a timely manner and achieving webpage optimization.
[0082] When the DOM changes, complexity calculations are performed on the components involved in the change: specifically, when a node in the DOM tree changes, the complexity of the affected component is calculated using methods such as... Figure 2 The complexity of the given computation node tree is calculated. This allows for a comprehensive evaluation of component complexity algorithms, enabling timely adjustments to component complexity and dynamic updates to caching logic in subsequent steps, better adapting to changes in user and business scenarios.
[0083] When caching components, the DOM complexity of the component can be calculated based on the depth and width of the component's DOM tree to more accurately reflect the component's complexity. Then, it is determined whether the component's DOM complexity has reached the threshold (i.e., the first threshold). If it has, the component instance is cached; otherwise, it is not cached. In addition, the DOM complexity is stored in the cache along with cache information, which may include information such as the component instance and node tree complexity.
[0084] When using a component, you can first check if there is already an instance of the component in the cache. If there is, return the component instance in the cache directly. Otherwise, create a new component instance and store it in the cache, and then return the new component instance.
[0085] When creating a new component instance, the decision to render the component can be based on its exposure. Specifically, the component's exposure and caching strategy can be used to determine whether it needs to be rendered. If the component's exposure reaches a certain threshold (i.e., the second threshold) and there is no instance of the component in the cache, then a new component instance needs to be created and the component rendered; otherwise, if the component's exposure is below the threshold, no instance needs to be created to avoid unnecessary computation and rendering overhead.
[0086] In addition, when the DOM tree of a component changes, the component's cached information may become invalid. In this case, the component's cached information can be updated in a timely manner. Specifically, the component's DOM complexity and exposure can be recalculated and updated in the cache to ensure the correctness and consistency of the component.
[0087] Building upon the above, caching component instances avoids the overhead of repeatedly creating component instances and recalculating component DOM complexity, thereby improving webpage responsiveness and performance. Simultaneously, caching component instances also reduces memory usage, enhancing webpage performance and stability.
[0088] The technical solution provided by this invention comprehensively considers multiple factors, including the number of nodes, nesting levels, number of tags, number of dynamic attributes, and weight values, to more comprehensively evaluate the complexity of components. Through the above processes and steps, event delegation can be used to promptly monitor DOM changes in web pages, cache and reuse component instances, thereby further improving the efficiency of web page performance optimization and enhancing web page performance and response speed.
[0089] This invention provides a component instance caching device. Figure 4 This is a schematic diagram of the structure of a component instance caching device provided in an embodiment of the present invention, as shown below. Figure 4 As shown, the device includes: a node complexity and attribute complexity determination module 210, a node tree complexity determination module 220, and a caching module 230.
[0090] The node complexity and attribute complexity determination module 210 is used to determine the node complexity and attribute complexity of a component based on the parameters of the node tree when the node tree of a component in the webpage changes.
[0091] The node tree complexity determination module 220 is used to determine the node tree complexity of the component based on the node complexity and the attribute complexity.
[0092] The caching module 230 is used to cache instances of the component based on the node tree complexity when the node tree complexity meets the conditions.
[0093] The component instance caching device provided in this embodiment of the invention can adapt to changes in web pages, update web page components in a timely manner, optimize web page performance, avoid the overhead of repeatedly creating component instances, and improve response speed.
[0094] Furthermore, the node complexity and attribute complexity determination module 210 includes:
[0095] Traverse the node tree of the component and count the number of nodes and the nesting level of the node tree;
[0096] The node complexity of the component is obtained by adding the number of nodes and the number of nesting levels.
[0097] Furthermore, the node complexity and attribute complexity determination module 210 includes:
[0098] The tag count and dynamic attribute count counting unit is used to traverse the node tree of the component and count the tag count and dynamic attribute count of the node tree.
[0099] The attribute complexity acquisition unit is used to add the node complexity, the number of tags, and the number of dynamic attributes to obtain the attribute complexity of the component.
[0100] Furthermore, the node tree complexity determination module 220 can be used for:
[0101] The node complexity and the attribute complexity are added together to obtain the node tree complexity of the component.
[0102] Furthermore, the attribute complexity acquisition unit can be used for:
[0103] The attribute complexity of the component is obtained by calculating the weighted sum of the node complexity, the number of tags, and the number of dynamic attributes based on the first weight of the node complexity, the second weight of the number of tags, and the third weight of the number of dynamic attributes.
[0104] Furthermore, the cache module 230 can be used for:
[0105] If the node tree complexity of the component reaches a first threshold and the instance of the component is not cached, then the instance of the component and the node tree complexity are cached.
[0106] Furthermore, the device also includes:
[0107] An update module is used to update the cached node tree complexity based on the node tree complexity determined when the node tree changes, provided that the node tree complexity of the component reaches a first threshold and the instance of the component and the node tree complexity are cached.
[0108] Furthermore, the device also includes:
[0109] The reading module is used to read the cached instance of the target component when the target component is invoked, if the instance of the target component is already cached; otherwise, an instance of the target component is created.
[0110] Furthermore, the read module can also be used for:
[0111] Determine the exposure of the target component;
[0112] When the exposure reaches the second threshold, an instance of the target component is created and the target component is rendered.
[0113] Furthermore, the device may also include:
[0114] The registration listener module is used to register listener events, wherein the listener event specifies a callback function, and the callback function is used to obtain information about the node tree when a node in the node tree sends a change.
[0115] Furthermore, the parameters of the node tree include at least one of the following: number of nodes, node type, nesting level, number of tags, number of dynamic attributes, and character length; each of the parameters corresponds to a corresponding weight.
[0116] The component instance caching device provided in this embodiment of the invention can execute the component instance caching method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method execution.
[0117] Figure 5 A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is provided. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the embodiments of the invention described and / or claimed herein.
[0118] like Figure 5 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0119] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0120] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as a component instance caching method.
[0121] In some embodiments, a component instance caching method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the component instance caching method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform a component instance caching method by any other suitable means (e.g., by means of firmware).
[0122] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0123] Computer programs for implementing the methods of embodiments of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0124] In the context of embodiments of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. Examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0125] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0126] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0127] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0128] It should be understood that the various forms of processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the embodiments of the present invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of the embodiments of the present invention can be achieved, and this document does not impose any restrictions.
[0129] The specific embodiments described above do not constitute a limitation on the scope of protection of the embodiments of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the embodiments of the present invention should be included within the scope of protection of the embodiments of the present invention.
[0130] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the component instance caching method provided in any embodiment of this application.
[0131] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0132] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. A component instance caching method, characterized in that, include: When the node tree of a component in a webpage changes, the node complexity and attribute complexity of the component are determined based on the parameters of the node tree. The node tree complexity of the component is determined based on the node complexity and the attribute complexity. If the node tree complexity meets the condition, cache instances of the component according to the node tree complexity; The node complexity is used to reflect the distribution of nodes in the node tree. The node complexity is related to the number of nodes, node type, nesting level and / or character length in the node tree. The attribute complexity is used to reflect the attribute status of the node tree. The attribute complexity is related to the number of nodes, node types, nesting levels, number of tags, number of dynamic attributes, and / or character length in the node tree. The condition includes that the numerical value of the node tree complexity is within a preset range.
2. The method according to claim 1, characterized in that, The node complexity of the component is determined based on the parameters of the node tree, including: Traverse the node tree of the component and count the number of nodes and the nesting level of the node tree; The node complexity of the component is obtained by adding the number of nodes and the number of nesting levels.
3. The method according to claim 1, characterized in that, The attribute complexity of the component is determined based on the parameters of the node tree, including: Traverse the node tree of the component and count the number of tags and dynamic attributes in the node tree; The component's attribute complexity is obtained by adding the node complexity, the number of tags, and the number of dynamic attributes.
4. The method according to claim 1, characterized in that, The node tree complexity of the component is determined based on the node complexity and the attribute complexity, including: The node complexity and the attribute complexity are added together to obtain the node tree complexity of the component.
5. The method according to claim 3, characterized in that, The attribute complexity of the component is obtained by adding the node complexity, the number of tags, and the number of dynamic attributes, including: The attribute complexity of the component is obtained by calculating the weighted sum of the node complexity, the number of tags, and the number of dynamic attributes based on the first weight of the node complexity, the second weight of the number of tags, and the third weight of the number of dynamic attributes.
6. The method according to claim 1, characterized in that, If the node tree complexity meets the condition, cache instances of the component according to the node tree complexity, including: If the node tree complexity of the component reaches a first threshold and the instance of the component is not cached, then the instance of the component and the node tree complexity are cached.
7. The method according to claim 1, characterized in that, Also includes: If the node tree complexity of the component reaches a first threshold and the instance of the component and the node tree complexity are cached, the cached node tree complexity is updated according to the node tree complexity determined when the node tree changes.
8. The method according to claim 1, characterized in that, Also includes: When invoking the target component, if an instance of the target component is cached, the cached instance of the target component is read. Otherwise, create an instance of the target component.
9. The method according to claim 8, characterized in that, The creation of an instance of the target component includes: Determine the exposure of the target component; When the exposure reaches the second threshold, an instance of the target component is created and the target component is rendered.
10. The method according to any one of claims 1-9, characterized in that, Also includes: Register a listener event, in which a callback function is specified. The callback function is used to obtain information about the node tree when a node in the node tree changes.
11. The method according to any one of claims 1-9, characterized in that, The parameters of the node tree include at least one of the following: number of nodes, node type, nesting level, number of tags, number of dynamic attributes, and character length; Each parameter corresponds to a specific weight.
12. A component instance caching device, characterized in that, include: The node complexity and attribute complexity determination module is used to determine the node complexity and attribute complexity of a component based on the parameters of the node tree when the node tree of a component in a webpage changes. A node tree complexity determination module is used to determine the node tree complexity of the component based on the node complexity and the attribute complexity. A caching module is used to cache instances of the component based on the node tree complexity when the node tree complexity meets the condition. The node complexity is used to reflect the distribution of nodes in the node tree. The node complexity is related to the number of nodes, node type, nesting level and / or character length in the node tree. The attribute complexity is used to reflect the attribute status of the node tree. The attribute complexity is related to the number of nodes, node types, nesting levels, number of tags, number of dynamic attributes, and / or character length in the node tree. The condition includes that the numerical value of the node tree complexity is within a preset range.
13. An electronic device, characterized in that, The invention includes 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, it implements the component instance caching method as described in any one of claims 1-11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the component instance caching method as described in any one of claims 1-11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the component instance caching method as described in any one of claims 1-11.
Citation Information
Patent Citations
Page loading method and system based on user permission
CN113609460A
Component multiplexing implementation method and device, terminal equipment and readable storage medium
CN115809056A