Resource caching method, device, and electronic device

By adjusting the storage location of the first resource and the second resource of its referenced resource in the cache space, the second resource is placed behind the first resource, and the problem of low cache hit rate in the prior art without considering the resource reference relationship is solved, and the effect of improving the cache hit rate is achieved.

CN119782197APending Publication Date: 2025-04-08NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411620190.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

The existing resource caching technology fails to consider the reference relationship between resources, resulting in a low cache hit rate in resource caching scenarios with reference relationships.

Method used

By responding to an access instruction for the first resource, the first resource is stored or moved to the header position of the cache space, and the second resource is stored or moved to the header position of the cache space, so that the first resource is behind the second resource, and the second resource is a resource referenced by the first resource.

Benefits of technology

This method can increase the cache hit rate because the referenced resource is more likely to be referenced by other resources than the referenced resource.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119782197A_ABST
    Figure CN119782197A_ABST
Patent Text Reader

Abstract

The present application discloses a resource caching method, device, electronic device, and computer-readable storage medium. The method includes: in response to an access instruction for a first resource, storing or moving the first resource to the head position of the cache space; storing or moving the second resource to the head position of the cache space, so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource. The method is a resource caching method for resources with a reference relationship, which solves the technical problem of low cache hit rate in the resource caching scenario with a reference relationship due to failure to consider the reference relationship between resources in the existing resource caching technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a resource caching method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Resource caching is to store loaded resources in the cache space to speed up the access speed when accessing the resource again. Due to the limited cache space, the resources stored in the cache space need to be constantly updated. In order to maximize the probability of accessed resources being cached in the cache space (i.e., cache hit rate), some resource caching technologies are usually used, among which LRU (Least Recently Used) is currently a more commonly used resource caching technology. Its core principle is that the most recently used resources are more likely to be used again.

[0003] At present, LRU has achieved a relatively good cache hit rate in some scenarios, but it only caches independent and non-interfering resources, and does not take into account the reference relationship between resources. However, the existence of a tree-like reference relationship between resources is a common state of resources.

[0004] Therefore, there is an urgent need for a resource caching method that can support resource reference relationships and achieve a high cache hit rate, so as to solve the technical problem of low cache hit rate in resource caching scenarios with reference relationships due to failure to consider the reference relationship between resources in existing resource caching technologies. Summary of the invention

[0005] The present application provides a resource caching method, device, electronic device, and computer-readable storage medium to solve the technical problem of low cache hit rate in resource caching scenarios with reference relationships due to failure to consider reference relationships between resources in existing resource caching technologies.

[0006] In a first aspect, an embodiment of the present application provides a resource caching method, the method comprising: in response to an access instruction for a first resource, storing or moving the first resource to a head position of a cache space, the cache space storing loaded resources in the form of a linked list, the head position being a storage position in the linked list for storing the most recently used resource; storing or moving a second resource to a head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, the second resource being any one of the resources referenced by the first resource.

[0007] In a second aspect, an embodiment of the present application provides a resource caching device, comprising: a parent resource caching unit and a child resource caching unit; the parent resource caching unit is used to respond to an access instruction for a first resource, store or move the first resource to a head position of a cache space, the cache space stores loaded resources in the form of a linked list, and the head position is a storage position in the linked list for storing the most recently used resource; the child resource caching unit is used to store or move a second resource to a head position of the cache space, so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

[0008] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor; the memory is used to store one or more computer instructions; the processor is used to execute the one or more computer instructions to implement the above method.

[0009] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having one or more computer instructions stored thereon, which, when executed by a processor, executes the above method.

[0010] Compared with the prior art, the resource caching method provided by the present application includes: in response to an access instruction for a first resource, storing or moving the first resource to the head position of a cache space, the cache space stores loaded resources in the form of a linked list, the linked list provides multiple storage locations, and the head position is the storage location in the linked list where the most recently used resource is stored; storing or moving the second resource to the head position of the cache space, so that the storage location of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource. This method is a resource caching method for resources with a reference relationship (a first resource references a second resource). When accessing a reference resource (a first resource), both the reference resource (a first resource) and the referenced resource (a second resource) are cached (stored or moved to a storage location), and the storage location of the referenced resource (a second resource) is located before the storage location of the reference resource (a first resource). Since the referenced resource has a higher probability of being referenced by other resources than the referencing resource (other resources can reference the referenced resource alone or reference the referencing resource, and when referencing the referencing resource, the referenced resource is also referenced), using this method for resource caching can increase the cache hit rate. Therefore, the resource caching method provided by the present application solves the technical problem of low cache hit rate in resource caching scenarios with reference relationships due to failure to consider the reference relationship between resources in the existing resource caching technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1is a schematic diagram of the reference relationship between resources provided in the embodiment of the present application;

[0012] Figure 2 is an application system diagram of the resource caching method provided in an embodiment of the present application;

[0013] Figure 3 is a flowchart of a resource caching method provided in the first embodiment of the present application;

[0014] Figure 4 It is a schematic diagram of the process of resource caching provided by the first embodiment of the present application;

[0015] Figure 5 It is a schematic diagram of a structure of a resource with a reference relationship provided in the first embodiment of the present application;

[0016] Figure 6 It is a structural diagram of another resource with a reference relationship provided in the first embodiment of the present application;

[0017] Figure 7 It is a schematic diagram of an access sequence of a resource node tree provided in the first embodiment of the present application;

[0018] Figure 8 It is a schematic diagram of another access sequence of a resource node tree provided in the first embodiment of the present application;

[0019] Fig. 9 is a schematic diagram of a resource node tree provided in the first embodiment of the present application;

[0020] Fig.10 It is a schematic diagram of a flow chart of determining a resource update sequence of a resource node tree provided by the first embodiment of the present application;

[0021] Fig.11 is a schematic diagram of the structure of a resource cache device provided in the second embodiment of the present application;

[0022] Fig.12 It is a schematic diagram of the structure of an electronic device provided in the third embodiment of the present application. DETAILED DESCRIPTION

[0023] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.

[0024] With the development of information technology and the Internet, the access frequency of resources has shown an explosive growth. In order to optimize the access speed of resources, resource caching solutions are usually used. Resource caching is to store the loaded resources in the cache space so that when the resource is accessed again, it can be directly obtained in the cache space without spending time to load the resource again. It is an optimization idea of ​​using space for time. Due to the limited cache space, it is necessary to continuously update the resources stored in the cache space. In order to maximize the probability of accessed resources being cached in the cache space (i.e., cache hit rate), some resource caching technologies are usually used, such as FIFO (First In, First Out), LRU (Least Recently Used), LFU (Least Frequently Used), etc. Among them, LRU is the most commonly used resource caching technology at present. Its core principle is that the most recently used resources have a higher probability of being used again. Therefore, when the cache space is full and new space needs to be vacated to store new resources, the least recently used resources (i.e., the resources with the lowest reuse probability) will be removed to achieve the effect of improving the cache hit rate.

[0025] Exemplarily, it is assumed that the cache space can store three resources, and the accessible resources include resource A, resource B, resource C, and resource D. The steps of resource caching are as follows: first, access resource A and store resource A in the cache space, and the cache space is (A); second, access resource B and store resource B in the cache space. Since resource B is the most recently used resource, the reuse probability of resource B is greater than the reuse probability of resource A. Therefore, resource B is stored in front of resource A. At this time, the cache space is (B, A); third, access resource C and store resource C in the cache space. Since resource C is the most recently used resource, the reuse probability of resource C is greater than the reuse probability of resource B and resource A. Therefore, resource C is stored in front of resource B. At this time, the cache space is (C, B, A). The cache space is full; fourth, access resource A. Since resource A has been stored in the cache space and resource A is the most recently used, the reuse probability of resource A is greater than the reuse probability of resources C and resource B. Therefore, adjust the storage position of resource A in the cache space. At this time, the cache space is (A, C, B); fifth, access resource D. Since the cache space is full and resource B is the resource with the lowest reuse probability in the storage space, and resource D is the most recently used resource with the highest reuse probability, therefore, remove resource B from the cache space and store resource D in the cache space, specifically in front of resource A. At this time, the cache space is (D, A, C).

[0026] From the above, it can be seen that the process of using LRU cache resources may include: first, when accessing a resource, if the resource is already stored in the cache space, the resource is moved from the original storage position to the head position of the cache space; second, when accessing a resource, if the resource is not stored in the cache space, determine whether the cache space is full. Specifically, if the cache space is not full, the resource is stored at the head position of the cache space; if the cache space is full, the resource at the tail position of the cache space is moved out of the cache space, and the resource is stored at the head position of the cache space.

[0027] LRU is easy to understand and implement. It has achieved a good cache hit rate in some scenarios and is a highly universal resource caching method. However, LRU currently only caches independent and non-interfering resources and does not take into account the reference relationship between resources. Figure 1 The reference relationship in the tree structure shown is the universal existence state of resources. Figure 1 As shown, resource A, resource B, and resource C form a resource node tree. Resource B and resource C referenced by resource A can also be understood as resource A being the root node resource (parent resource), resource B and resource C being child node resources (child resources), and resource B and resource C being sibling node resources (sibling resources). For such resources with a reference relationship, LRU currently does not provide a cache solution. In a possible cache solution, only the parent resource (resource A) is stored in the cache space. Then, when resource A is accessed again, since only resource A is stored in the cache space, and resource B and resource C are not stored, resource A still cannot be directly obtained from the cache space and needs to be reloaded, resulting in a low cache hit rate. Therefore, the existing resource caching technology has a technical problem of low cache hit rate in resource caching scenarios with a reference relationship.

[0028] In view of this, the present application provides a resource caching method, which is a resource caching method for resources with a reference relationship (a first resource references a second resource). When accessing the reference resource (first resource), both the reference resource (first resource) and the referenced resource (second resource) are cached (stored or moved to a storage location), and the storage location of the referenced resource (second resource) is located before the storage location of the reference resource (first resource). Since the referenced resource is more likely to be referenced by other resources than the referencing resource (other resources can reference the referenced resource alone or reference the referencing resource, and when the referencing resource is referenced, the referenced resource is also referenced. Exemplarily, the second resource is the referenced resource of the first resource, the third resource references the second resource, and the fourth resource references the first resource. Since the first resource references the second resource, the fourth resource references the first resource and actually references the second resource. Therefore, the first resource is referenced once by other resources, and the second resource is referenced twice by other resources, and the second resource is referenced more times), using this method for resource caching can increase the cache hit rate.

[0029] The resource caching method, device, electronic device, and computer-readable storage medium described in the present application are further described in detail below in conjunction with specific embodiments and drawings.

[0030] Figure 2 is an application system diagram of the resource caching method provided in the embodiment of the present application. Figure 2 As shown, the system includes a user terminal 201 and a server terminal 202. The user terminal 201 can be any device such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant (PDA), etc. The server terminal 202 can be a processing module inside the user terminal 201, or a processing device electrically connected to the user terminal 201, or a cloud server connected to multiple user terminals 201 in communication. A resource caching method is deployed on the server terminal 202. When a user accesses a resource with a reference relationship through the user terminal 201, the server terminal 202 can cache the resource and the referenced resource in the memory of the user terminal 201 based on the method, so as to increase the probability of directly obtaining the resource or the referenced resource from the memory of the user terminal 201 when the resource or the referenced resource is accessed again.

[0031] The first embodiment of the present application provides a resource caching method, which is deployed in Figure 2 The server 202 is shown as caching resources in the cache space of the client 201. The method provided in this embodiment is particularly suitable for caching resources with reference relationships, such as storing multiple resources with tree-structured reference relationships in the cache space.

[0032] Figure 3 is a flow chart of the resource caching method provided in this embodiment. Figure 3 The resource caching method provided by this embodiment is described in detail. The embodiments described below are used to explain the technical solution of this application and are not intended to be used as limitations for actual use.

[0033] like Figure 3 As shown, the resource caching method provided in this embodiment includes the following steps S310 to S320:

[0034] Step S310, in response to an access instruction for a first resource, the first resource is stored or moved to the head position of a cache space, the cache space stores loaded resources in the form of a linked list, and the head position is the storage position in the linked list where the most recently used resource is stored.

[0035] The cache space can be understood as a memory space in a terminal device for temporarily storing loaded or frequently used resources, which may include web pages, application data, media files, etc. The purpose of caching resources is to increase the access speed of resources and reduce the use of network bandwidth.

[0036] The linked list can be understood as a way of storing resources in the cache space. It is a linear data structure that provides multiple discontinuous storage locations (storage locations can also be understood as storage nodes) for storing loaded or frequently used resources. Normally, the resources stored in the cache space have a certain storage order, which is related to the usage time of the resources. For example, the head position of the linked list is used to store the latest used resources (i.e., the most recently used resources), and the tail position of the linked list is used to store the oldest used resources (i.e., the resources with the earliest usage time among the multiple resources stored in the cache space). It can be understood that the cache space stores resources linearly in the order of the latest use to the oldest use, with the latest use at the head and the oldest use at the tail.

[0037] The access instruction can be understood as the instruction information for accessing a resource generated by the user end in response to a user operation (e.g., a user inputs a query word in a search engine) or a trigger event (e.g., updating the application status at regular intervals). The user end sends the access instruction to the server end, and the server end can execute the corresponding method to achieve access to the resource. Usually, after the access is completed, the server end will send the access result to the user end so that the user can understand the access status of the resource.

[0038] In this embodiment, the first resource can be understood as a parent node resource in a group of multiple resources with a tree structure reference relationship, such as Figure 1Resource A is shown. When the server receives an access instruction to the first resource, since the first resource is the latest resource currently in use, the first resource is stored or moved to the head position of the cache space.

[0039] In an optional implementation, in response to an access instruction for the first resource, storing or moving the first resource to the head position of the cache space may specifically include the following steps S311 to S313:

[0040] Step S311, determining whether the first resource is stored in the cache space.

[0041] Step S312: In response to the first resource not being stored in the cache space, the first resource is loaded and stored at the head position of the cache space.

[0042] Step S313: In response to the first resource being stored in the cache space, the first resource stored in the cache space is moved to a head position.

[0043] When accessing the first resource, if it is found that the first resource has been stored in the cache space, there is no need to reload the first resource, and it can be directly obtained from the cache space. At the same time, since the first resource is the most recently used resource, it is necessary to adjust the position of the first resource in the cache space to the head position; when it is found that the first resource does not exist in the cache space, it is necessary to load the first resource and store the loaded first resource in the cache space. Since the first resource is the most recently used resource, the first resource is stored at the head position of the cache space.

[0044] In an optional implementation, in response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at the head position of the cache space may specifically include the following steps S312-1 to S312-3:

[0045] Step S312-1, determine whether the cache space is full.

[0046] Step S312-2: In response to the cache space being not full, the first resource is stored at the head position of the cache space.

[0047] Step S312-3, in response to the cache space being full, the resource corresponding to the tail position of the cache space is moved out of the cache space, and the first resource is stored in the head position of the cache space.

[0048] When it is determined that the first resource is not stored in the cache space, since the first resource needs to be stored in the cache space, it is also necessary to perform a step of determining the current storage situation of the cache space. Specifically, it is determined whether the cache space is currently full, that is, whether all storage locations provided by the linked list are fully occupied by resources. When it is found that the cache space is not full, the first resource can be directly stored at the head position of the cache space. When it is found that the cache space is full, it is necessary to remove the oldest used resource from the tail position of the cache space to free up space capacity that can store the first resource, and store the first resource at the head position of the cache space. It should be noted that the resource removed from the tail position of the cache space can be one or more. When one resource is removed, the remaining space capacity of the cache space is greater than or equal to the first resource, and the removal of other resources will be stopped. When one resource is removed, the remaining space capacity of the cache space is still less than the first resource, then the oldest used resource will continue to be removed until the first resource can be stored.

[0049] Step S320: store or move the second resource to the head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

[0050] In this embodiment, the second resource can be understood as a sub-node resource in a group of multiple resources with a tree-structured reference relationship, such as Figure 1 The resource B or resource C shown. When the server receives the access instruction for the first resource and performs the cache operation on the first resource (i.e., stores or moves the first resource to the head position of the cache space), the cache operation on the second resource can be performed. Specifically, the second resource is stored or moved to the head position of the cache space. At this time, the second resource is located before the first resource in the cache space.

[0051] In an optional implementation, after performing a cache operation on a first resource, it will first be determined whether the first resource has a referenced resource. When the first resource has a referenced resource, a cache operation on the referenced resource (such as a second resource) will then be performed. When the first resource does not have a referenced resource, the cache operation will end. Based on this, before the step of storing or moving the second resource to the head position of the cache space, the method provided in this embodiment also includes: determining whether the first resource has a referenced resource. Subsequently, storing or moving the second resource to the head position of the cache space may specifically include: in response to the first resource having a referenced second resource, storing or moving the second resource to the head position of the cache space.

[0052] In an optional implementation, in response to the first resource having a referenced second resource, storing or moving the second resource to the head position of the cache space may specifically include the following steps S321 to S323:

[0053] Step S321, determining whether the second resource is stored in the cache space.

[0054] Step S322: In response to the second resource not being stored in the cache space, the second resource is loaded and stored at the head position of the cache space.

[0055] Step S323: In response to the second resource being stored in the cache space, the second resource stored in the cache space is moved to the head position.

[0056] After executing the cache operation on the first resource and determining that the first resource has a referenced second resource, when it is found that the second resource is already stored in the cache space, there is no need to reload the second resource, and it can be directly obtained from the cache space. At the same time, since the second resource is the most recently used resource, it is necessary to adjust the position of the second resource in the cache space to the head position; when it is found that the second resource does not exist in the cache space, it is necessary to load the second resource and store the loaded second resource in the cache environment. Since the second resource is the most recently used resource, the second resource is stored at the head position of the cache space.

[0057] In an optional implementation, in response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at the head position of the cache space may specifically include the following steps S322-1 to S322-3:

[0058] Step S322-1, determine whether the cache space is full.

[0059] Step S322-2: In response to the cache space being not full, the second resource is stored at the head position of the cache space.

[0060] Step S322-3, in response to the cache space being full, the resource located at the tail position of the cache space is moved out of the cache space, and the second resource is stored at the head position of the cache space.

[0061] When it is determined that the second resource is not stored in the cache space, since the second resource needs to be stored in the cache space, it is also necessary to perform a step of determining the current storage status of the cache space, specifically, determining whether the cache space is currently full, that is, whether all storage locations provided by the linked list are fully occupied by resources. When it is found that the cache space is not full, the second resource can be directly stored at the head position of the cache space. When it is found that the cache space is full, it is necessary to remove the oldest used resource from the tail position of the cache space to free up space capacity for storing the second resource, and store the second resource at the head position of the cache space.

[0062] Figure 4 It is a schematic diagram of the resource caching process provided by this embodiment.

[0063] like Figure 4 As shown, the resource cache provided in this embodiment may include the following steps S401 to S408:

[0064] Step S401, in response to receiving an access operation to a resource, determining whether the resource exists in the cache space.

[0065] Step S402: In response to the resource existing in the cache space, the resource is moved to the head position of the cache space.

[0066] Step S403: In response to the resource not existing in the cache space, determining whether the cache space is full.

[0067] Step S404, in response to the cache space being full, remove the resource at the tail position of the cache space and add the resource to the head position of the cache space.

[0068] Step S405: In response to the cache space being not full, directly add the resource to the head position of the cache space.

[0069] Step S406: determine whether the resource has a referenced sub-resource.

[0070] Step S407, in response to the resource having a referenced sub-resource, return to step S401, and use the sub-resource as the accessed resource.

[0071] Step S408: In response to the resource not having a referenced sub-resource, the resource caching operation ends.

[0072] The resource caching method provided in this embodiment is described below with specific examples.

[0073] Figure 5 It is a schematic diagram of the structure of resources with a reference relationship provided by this embodiment.

[0074] like Figure 5As shown, resource A references resource B and resource C, and resource D references resource B and resource E. Resource A, resource B, and resource C are regarded as a resource node tree, resource A is the parent node resource of the resource node tree, and resource B and resource C are child node resources of the resource node tree. Similarly, in the resource node tree composed of resource D, resource B, and resource E, resource D is the parent node resource, and resource B and resource E are child node resources. When the server receives an access instruction for resource A, it will first store or move resource A to the head position of the cache space, and then store or move resource B or resource C to the head position of the cache space. The resource storage sequence in the cache space is (B, C, A) or (C, B, A). When the server receives another access instruction for resource D, it will first store or move resource D to the head position of the cache space, and then store or move resource B or resource E to the head position of the cache space. The resource storage sequence in the cache space is (B, E, D, C, A) or (E, B, D, C, A). From the above, it can be seen that after accessing resource A, the referenced resource B of resource A has been stored in the cache space. Therefore, when accessing resource D, resource B stored in the cache space can be used directly without reloading resource B, which saves the performance overhead of loading resource B and shortens the access time of resource D. Furthermore, when the server receives an access instruction for resource A again, it will first move resource A to the head position of the cache space. The resource storage sequence in the cache space is (A, B, E, D, C) or (A, E, B, D, C). Then, resource B and resource C will be moved to the head position of the cache space in sequence. The resource storage sequence in the cache space is (B, C, A, E, D) or (C, B, A, E, D).

[0075] Figure 6 This is a schematic diagram of the structure of another resource with a reference relationship provided by this embodiment.

[0076] like Figure 6 As shown, resource A references resource B and resource C, and resource B references resource D and resource E. In the resource node tree composed of resource A, resource B, resource C, resource D, and resource E, there is a sub-resource node tree composed of resource B, resource D, and resource E. From the above resource caching steps, it can be seen that the storage sequence of resource A, resource B, and resource C in the cache space is (B, C, A) or (C, B, A), and the storage sequence of resource B, resource D, and resource E in the cache space is (D, E, B) or (E, D, B). Substituting the storage sequence of resource B, resource D, and resource E in the cache space into the storage sequence of resource A, resource B, and resource C in the cache space, the storage sequence of resource A, resource B, resource C, resource D, and resource E in the cache space can be obtained (D, E, B, C, A) or (E, D, B, C, A) or (C, D, E, B, A) or (C, E, D, B, A).

[0077] It can be seen from the above that: in the resource caching method provided in this embodiment, the newly used resource is located before the old used resource, and the referenced resource (child resource) is located before the referencing resource (parent resource).

[0078] In an optional implementation provided in this embodiment, in order to further optimize resource access and storage performance, a storage sequence of resources in the cache space can be constructed during the resource access process. Based on this, performing a cache operation on a first resource and a second resource referenced by the first resource may specifically include the following steps S11 to S12:

[0079] Step S11, accessing the resource node tree corresponding to the first resource in a pre-order traversal manner, the first resource is a parent node in the resource node tree, and the second resource is any child node in the resource node tree.

[0080] Step S12: along with the access process, the first resource and the second resource are stored or moved to the head position of the cache space in sequence.

[0081] In a specific implementation, the resource node tree also includes a third resource and a fourth resource, the second resource and the third resource are resources directly referenced by the first resource, and the fourth resource is a resource directly referenced by the second resource, that is, the resource node tree includes multiple levels, the first resource is the first level, the second resource and the third resource are the parallel second levels, and the fourth resource is the third level under the second resource. Along with the access process, the first resource and the second resource are stored or moved to the head position of the cache space in sequence, which may specifically include the following steps S21 to S25:

[0082] Step S21, in response to accessing the first resource, storing or moving the first resource to the head position of the cache space.

[0083] Step S22, in response to accessing the second resource, storing or moving the second resource to the head position of the cache space, with the first resource being located after the second resource.

[0084] Step S23, in response to accessing the fourth resource, storing or moving the fourth resource to the head position of the cache space, and the second resource is located after the fourth resource.

[0085] Step S24, in response to accessing the third resource, storing or moving the third resource to the head position of the cache space, and the fourth resource is located after the third resource.

[0086] Step S25, in response to the completion of the resource node tree access, the cache space stores at least a third resource located at the head position, a fourth resource located at the first position, a second resource located at the second position, and a first resource located at the third position; wherein the first position is a storage position after the head position, the second position is a storage position after the first position, and the third position is a storage position after the second position.

[0087] The access order of the first resource, the second resource, the fourth resource, and the third resource is a pre-order traversal order. In the process of accessing the resource node tree in the pre-order traversal order, each resource is sequentially stored or moved to the head position of the cache space. Of course, the resource node tree can include more levels and resources, and the cache operation can be performed on each resource according to this method.

[0088] Figure 7 This is a schematic diagram of an access sequence of a resource node tree provided by this embodiment.

[0089] like Figure 7 As shown, the resource node tree composed of resource A, resource B, resource C, resource D, and resource E is accessed / loaded in a pre-order traversal manner, and the access order is: first, access resource A; second, access the first sub-resource of resource A, that is, resource B; third, access the first sub-resource of resource B, that is, resource D; fourth, resource D has no sub-resources, access other sub-resources of resource B, that is, resource E; fifth, resource E has no sub-resources, and resource B has no other sub-resources, access other sub-resources of resource A, that is, resource C. Sixth, resource C has no sub-resources, and resource A has no other sub-resources, and the access ends. The access order of the resource node tree obtained thereby is (A, B, D, E, C). In the process of accessing the resource node tree in this access order, resources A, resource B, resource D, resource E, and resource C are stored in the cache space in turn, and the storage sequence of resources A, resource B, resource C, resource D, and resource E in the cache space is obtained as (C, E, D, B, A).

[0090] In some resources with reference relationships, sub-resources are repeatedly referenced. In this regard, in an optional implementation provided in this embodiment, in order to further optimize the resource cache performance, that is, to avoid redundant updates to the positions of repeated sub-resources in the cache space, the resource update sequence can be recorded when the resource is first accessed. Then, when the resource is accessed again, the recorded resource update sequence can be used directly to update the storage location of the resource and the resources referenced by the resource in the cache space, without having to re-traverse the resource node tree corresponding to the resource. This not only solves the problem of redundant updates to duplicate resources, but also solves the additional performance overhead caused by accessing discontinuous cache space. Specifically, after performing resource caching operations on the first resource and the second resource referenced by the first resource, the method provided in this embodiment may also include the following steps S31 to S32:

[0091] Step S31, determining a resource update order corresponding to the first resource according to a pre-order traversal order of a resource node tree corresponding to the first resource.

[0092] Step S32: Record the resource update sequence corresponding to the first resource. The resource update sequence is used to represent the order of updating the first resource and the storage locations of the resources referenced by the first resource in the cache space.

[0093] In an optional implementation, determining the resource update order corresponding to the first resource according to the pre-order traversal order of the resource node tree corresponding to the first resource may specifically include the following steps S41 to S43:

[0094] Step S41, determining a reverse pre-order traversal order of a resource node tree corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource.

[0095] Step S42, based on the reverse first-order traversal order of the resource node tree corresponding to the first resource, delete the second duplicate resource in the duplicate resources, the second duplicate resource is the duplicate resource other than the first duplicate resource in the duplicate resources, and the first duplicate resource is the duplicate resource that is ranked first in the duplicate resources.

[0096] Step S43: Reverse the reverse pre-order traversal order after deleting the second duplicate resource, and use the reversed order as the resource update order corresponding to the first resource.

[0097] The reverse pre-order traversal order is the reverse order of the pre-order traversal order. After the pre-order traversal order is reversed, the resource accessed last will be located at the front, and the resource accessed first will be located at the back. When there are duplicate resources in the sequence, only the duplicate resource at the front can be retained, and the other duplicate resources can be deleted to avoid redundant updates to the resource. It can be understood that the duplicate resource at the front is actually the last one accessed among the duplicate resources, and when the resource storage location in the cache space is updated, the final storage location of the duplicate resource is actually the storage location of the last accessed duplicate resource. Therefore, based on this method, not only redundant updates to duplicate resources are avoided, but also the update results of the duplicate resource storage location in the resource access process are met. In this embodiment, the duplicate resource at the front is defined as the first duplicate resource, and one or more other duplicate resources are defined as the second duplicate resource. In this embodiment, the reverse pre-order traversal order in which the second duplicate resource is deleted is reversed to obtain the resource update order corresponding to the first resource.

[0098] After obtaining the resource update sequence corresponding to the first resource, the resource update sequence can be recorded in the memory space of the terminal device. When an access instruction for the first resource is received again, the resource update sequence can be used to update the storage location of the first resource and all resources referenced by the first resource in the cache space without re-traversing the resource node tree corresponding to the first resource.

[0099] The following is a specific example to illustrate how to calculate the resource update order.

[0100] Figure 8 This is a schematic diagram of another access sequence of a resource node tree provided by this embodiment.

[0101] like Figure 8As shown, the pre-order traversal sequence of the resource node tree is (A, B, C, D, E, F, C, D, E). In the access process to the resource node tree, the storage locations of resources A, B, C, D, E, F, C, D, and E in the cache space are updated sequentially. Since the CDE sub-resource node tree appears twice in the resource node tree, the storage locations of resources C, D, and E in the cache space are also updated twice, and there is a problem of redundant update. In order to solve this problem, so that when the resource node tree is accessed again, there is no redundant update, it is necessary to calculate the resource update sequence of the resource node tree in the first access process. Specifically, the pre-order traversal order of the resource node tree is (A, B, C, D, E, F, C, D, E), and its corresponding reverse pre-order traversal order is (E, D, C, F, E, D, C, B, A). Based on the reverse pre-order traversal order, the second duplicate resource in the duplicate resources is deleted to obtain the order (E, D, C, F, B, A). This order is reversed as the resource update order of the resource node tree (A, B, F, C, D, E). When the resource node tree is accessed again, the resource update order can be directly used to update the storage locations of resource A, resource B, resource F, resource C, resource D, and resource E in the cache space in sequence, without the need to traverse the resource node tree again.

[0102] In an optional implementation, the first resource may also be a sub-resource of another resource, that is, a referenced resource. Specifically, the first resource is a referenced resource of the fifth resource, and the resource node tree corresponding to the fifth resource includes a resource node tree corresponding to the first resource and a resource node tree corresponding to the sixth resource. After determining and recording the resource update order corresponding to the first resource through the above steps S41 to S43, the resource update order corresponding to the sixth resource may continue to be determined based on the above method, and finally the resource update order of the parent resource is guided based on the resource update order of the sub-resource, that is, the resource update order corresponding to the fifth resource is determined according to the resource update order corresponding to the first resource and the resource update order corresponding to the sixth resource. The local optimal solution (resource update order of the sub-resource) is guided to the global optimal solution (resource update order of the parent resource). Based on this, after step S43, the method provided in this embodiment may also include the following steps S44 to S47:

[0103] Step S44: Determine a resource update order corresponding to the sixth resource according to a pre-order traversal order of the resource node tree corresponding to the sixth resource.

[0104] Step S45: record the resource update sequence corresponding to the sixth resource.

[0105] Step S46: Determine the resource update sequence corresponding to the fifth resource according to the resource update sequence corresponding to the first resource and the resource update sequence corresponding to the sixth resource.

[0106] Step S47, recording the resource update sequence corresponding to the fifth resource.

[0107] When an access instruction for the sixth resource or the fifth resource is received again, the recorded resource update order can be used to update the storage location of the sixth resource and all sub-resources referenced by the sixth resource, or the fifth resource and all sub-resources referenced by the fifth resource in the cache space, without having to traverse the sixth resource or the fifth resource again.

[0108] In a specific implementation, determining the resource update sequence corresponding to the fifth resource according to the resource update sequence corresponding to the first resource and the resource update sequence corresponding to the sixth resource may specifically include the following steps S51 to S54:

[0109] Step S51: merge the inverse order of the resource update order corresponding to the sixth resource and the inverse order of the resource update order corresponding to the first resource to form a first merged order.

[0110] Step S52: based on the first merging order, delete the fourth repeated resource in the repeated resources, the fourth repeated resource is the repeated resource other than the third repeated resource in the repeated resources, and the third repeated resource is the repeated resource that is ranked first in the repeated resources.

[0111] Step S53: Add the fifth resource to the end of the first merged sequence from which the fourth duplicate resource is deleted, to form a second merged sequence.

[0112] Step S54: Reverse the second merging order, and use the reversed order as the resource update order corresponding to the fifth resource.

[0113] The reverse order of the resource update order corresponding to the first resource can be understood as the reverse pre-order traversal order in which the second duplicate resource is deleted. Similarly, the reverse order of the resource update order corresponding to the sixth resource can be understood as the order obtained by reversing the pre-order traversal order corresponding to the sixth resource to the reverse pre-order traversal order and removing the redundant resources (the duplicate resources ranked later in the duplicate resources). The reverse pre-order traversal order after removing the redundant resources corresponding to the sixth resource is merged with the reverse pre-order traversal order after removing the redundant resources corresponding to the first resource to form a merged order of the two. In this embodiment, the merged order is defined as the first merged order. Further, since the resource update order corresponding to the first resource / sixth resource has removed the duplicate resources inside the resource, but the duplicate resources between the first resource and the sixth resource have not been removed, therefore, after obtaining the first merged order, it is necessary to delete one or more duplicate resources ranked later in the first merged order, and only retain the duplicate resource ranked first. In this embodiment, the duplicate resource ranked first is defined as the third duplicate resource, and the other duplicate resources except the third duplicate resource are defined as the fourth duplicate resource. Furthermore, the fifth resource is added to the end of the first merged sequence from which the fourth duplicate resource is deleted, forming a merged sequence including the fifth resource (parent resource). In this embodiment, this merged sequence is defined as a second merged sequence. Further, after obtaining the second merged sequence, the second merged sequence is reversed to obtain a resource update sequence corresponding to the fifth resource.

[0114] Fig. 9 It is a schematic diagram of a resource node tree provided in this embodiment.

[0115] like Fig. 9 As shown, in the resource node tree, node A is used as the parent node resource, node B is used as a child resource node tree in the resource node tree, and node C is used as another child resource node tree of the resource node tree. The resource update order corresponding to node B and the resource update order corresponding to node C are determined and recorded by the method of steps S41 to S43. Through "reverse pre-order traversal of node C + de-redundancy" + "reverse pre-order traversal of node B + de-redundancy" + "de-redundancy" + node A, the "reverse pre-order traversal + de-redundancy" of resource node tree ABC can be obtained, and the resource update order of resource node tree ABC can be obtained by reversing the order.

[0116] In summary, for any resource node tree, the following conditions can be met:

[0117] First, if a node resource has no child node resources, then the resource update order of the node resource is the node resource itself;

[0118] Second, if a node resource has child node resources, then the resource update order of the child node resources is the inverse of "reverse pre-order traversal + redundancy removal".

[0119] Fig.10 It is a schematic diagram of a flow chart for determining a resource update sequence of a resource node tree provided by this embodiment.

[0120] like Fig.10 As shown, the method for determining the resource update order of the resource node tree provided in this embodiment may include the following steps S1001 to S1008:

[0121] Step S1001, input the root node resource of the resource node tree, and access the node resources in the resource node tree in sequence based on the order of pre-order traversal;

[0122] Step S1002, determine whether the node resource has child node resources.

[0123] Step S1003: When a node resource has no child node resource, the node resource itself is used as the resource update order of the node resource.

[0124] Step S1004: when the node resource has child node resources, access each child node resource one by one.

[0125] Step S1005: All child node resources are out of date, and the reverse order of "reverse pre-order traversal + redundancy removal + node itself" is used as the resource update order of the node resource.

[0126] Step S1006: After determining the resource update order of the node resource, determine whether the node resource has a parent node resource.

[0127] Step S1007: when the node resource has a parent node resource, continue to access other child node resources under the parent node resource;

[0128] Step S1008, when the node resource has no parent node resource, it indicates that the node resource is a root node resource, and the access to the entire resource node tree is completed. The access is ended and the resource update sequence corresponding to the entire resource node tree and the child resource node tree under the resource node tree is recorded.

[0129] The purpose of recording the resource update sequence is to directly update the storage location of the resource in the cache space based on the recorded resource update sequence when the resource is accessed again, so as to reduce the additional performance overhead when the resource is accessed again.

[0130] Based on this, in an optional implementation, after recording the resource update sequence corresponding to the first resource, the resource update sequence corresponding to the sixth resource, and the resource update sequence corresponding to the fifth resource based on steps S41 to S47, the method provided in this embodiment may further include the following steps:

[0131] In response to an access instruction for a first resource, storage locations of the first resource and resources referenced by the first resource in the cache space are updated according to a resource update sequence corresponding to the first resource.

[0132] In response to the access instruction for the sixth resource, the storage locations of the sixth resource and the resources referenced by the sixth resource in the cache space are updated according to the resource update sequence corresponding to the sixth resource.

[0133] In response to the access instruction for the fifth resource, the storage locations of the fifth resource and the resources referenced by the fifth resource in the cache space are updated according to the resource update sequence corresponding to the fifth resource.

[0134] The first embodiment of the present application provides an optional resource caching method, which is a caching method for resources with a reference relationship (a first resource references a second resource). When accessing the reference resource (first resource), the reference resource (first resource) and the referenced resource (second resource) are both cached (stored or moved to a storage location), and the storage location of the referenced resource (second resource) is located before the storage location of the reference resource (first resource). Since the probability of the referenced resource being referenced by other resources is higher than that of the referenced resource, the use of this method for resource caching can increase the cache hit rate. In some optional implementations provided in this embodiment, in order to reduce the performance consumption of resource access and resource caching, the storage location of each resource in the cache space is updated in sequence according to the resource access order in the resource access process. In some other optional implementations provided in this embodiment, in order to reduce the performance consumption of resource caching, in the first access process of the resource, the resource update order corresponding to the resource is calculated and recorded, so that when the resource is accessed again, the resource update order can be directly used to update the storage location of the resource in the cache space, and the resource does not need to be accessed and traversed again.

[0135] It should be noted that the examples in the first embodiment are only for explaining the method described in this application and are not intended to be limiting for actual use. The resource caching method provided in this application includes but is not limited to the method described in the first embodiment.

[0136] A second embodiment of the present application provides a resource caching device. Fig.11 It is a schematic diagram of the structure of the resource cache device provided in this embodiment.

[0137] like Fig.11As shown, the resource caching device provided in this embodiment includes: a parent resource caching unit 1101 and a child resource caching unit 1102.

[0138] The parent resource cache unit 1101 is used to respond to an access instruction for a first resource and store or move the first resource to the head position of a cache space. The cache space stores loaded resources in the form of a linked list, and the head position is the storage position in the linked list where the most recently used resource is stored.

[0139] Optionally, the responding to the access instruction for the first resource to store or move the first resource to the head position of the cache space includes:

[0140] Determining whether the first resource is stored in the cache space;

[0141] In response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at a head position of the cache space;

[0142] In response to the first resource being stored in the cache space, the first resource stored in the cache space is moved to a head position.

[0143] Optionally, in response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at a head position of the cache space includes:

[0144] Determining whether the cache space is full;

[0145] In response to the cache space being not full, storing the first resource at a head position of the cache space;

[0146] In response to the cache space being full, the resource corresponding to the tail position of the cache space is moved out of the cache space, and the first resource is stored at the head position of the cache space.

[0147] The sub-resource cache unit 1102 is used to store or move the second resource to the head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

[0148] Optionally, before the step of storing or moving the second resource to the head position of the cache space, it is also used to:

[0149] Determine whether the first resource has a referenced resource;

[0150] The storing or moving the second resource to the head position of the cache space includes:

[0151] In response to the first resource having the second resource being referenced, the second resource is stored or moved to a head position of the cache space.

[0152] Optionally, in response to the first resource having the referenced second resource, storing or moving the second resource to the head position of the cache space includes:

[0153] Determining whether the second resource is stored in the cache space;

[0154] In response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at a head position of the cache space;

[0155] In response to the second resource being stored in the cache space, the second resource stored in the cache space is moved to a head position.

[0156] Optionally, in response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at a head position of the cache space includes:

[0157] Determining whether the cache space is full;

[0158] In response to the cache space being not full, storing the second resource at a head position of the cache space;

[0159] In response to the cache space being full, the resource located at the tail position of the cache space is moved out of the cache space, and the second resource is stored at the head position of the cache space.

[0160] Optionally, in response to an access instruction to a first resource, storing or moving the first resource to a head position of a cache space, and storing or moving a second resource to a head position of the cache space, includes:

[0161] Accessing a resource node tree corresponding to the first resource in a pre-order traversal manner, wherein the first resource is a parent node in the resource node tree, and the second resource is any child node in the resource node tree;

[0162] Along with the access process, the first resource and the second resource are sequentially stored or moved to the head position of the cache space.

[0163] Optionally, the resource node tree further includes a third resource and a fourth resource, the second resource and the third resource are resources directly referenced by the first resource, and the fourth resource is a resource directly referenced by the second resource;

[0164] The accompanying access process sequentially stores or moves the first resource and the second resource to the head position of the cache space, including:

[0165] In response to accessing the first resource, storing or moving the first resource to a head position of the cache space;

[0166] In response to accessing the second resource, storing or moving the second resource to a head position of the cache space, the first resource being located after the second resource;

[0167] In response to accessing the fourth resource, storing or moving the fourth resource to a head position of the cache space, the second resource being located after the fourth resource;

[0168] In response to accessing the third resource, storing or moving the third resource to the head position of the cache space, and the fourth resource is located after the third resource;

[0169] In response to the completion of the access to the resource node tree, the cache space stores at least the third resource located at the header position, the fourth resource located at the first position, the second resource located at the second position, and the first resource located at the third position; wherein the first position is a storage position after the header position, the second position is a storage position after the first position, and the third position is a storage position after the second position.

[0170] Optionally, the device further includes an update sequence determining unit; the update sequence determining unit is configured to:

[0171] Determining a resource update order corresponding to the first resource according to a pre-order traversal order of a resource node tree corresponding to the first resource;

[0172] Recording a resource update sequence corresponding to the first resource;

[0173] The resource update sequence is used to represent the order of updating the storage locations of the first resource and the resources referenced by the first resource in the cache space.

[0174] Optionally, also used for:

[0175] In response to an access instruction for the first resource, storage locations of the first resource and resources referenced by the first resource in the cache space are updated according to a resource update sequence corresponding to the first resource.

[0176] Optionally, determining a resource update order corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource includes:

[0177] Determining a reverse pre-order traversal order of the resource node tree corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource;

[0178] Based on the reverse first-order traversal order of the resource node tree corresponding to the first resource, delete the second duplicate resource in the duplicate resources, the second duplicate resource is the duplicate resource other than the first duplicate resource in the duplicate resources, and the first duplicate resource is the duplicate resource that is ranked first in the duplicate resources;

[0179] The reverse pre-order traversal order after deleting the second duplicate resource is reversed, and the reversed order is used as the resource update order corresponding to the first resource.

[0180] Optionally, the first resource is a referenced resource of a fifth resource, and the resource node tree corresponding to the fifth resource includes the resource node tree corresponding to the first resource and the resource node tree corresponding to the sixth resource; and is further used for:

[0181] Determining a resource update order corresponding to the sixth resource according to a pre-order traversal order of a resource node tree corresponding to the sixth resource;

[0182] Recording a resource update sequence corresponding to the sixth resource;

[0183] Determine a resource update sequence corresponding to the fifth resource according to a resource update sequence corresponding to the first resource and a resource update sequence corresponding to the sixth resource;

[0184] Record the resource update sequence corresponding to the fifth resource.

[0185] Optionally, determining the resource update sequence corresponding to the fifth resource according to the resource update sequence corresponding to the first resource and the resource update sequence corresponding to the sixth resource includes:

[0186] Merging the inverse order of the resource update order corresponding to the sixth resource and the inverse order of the resource update order corresponding to the first resource to form a first merged order;

[0187] Based on the first merging order, delete a fourth repeated resource in the repeated resources, the fourth repeated resource being a repeated resource other than the third repeated resource in the repeated resources, and the third repeated resource being a repeated resource that is ranked first in the repeated resources;

[0188] adding the fifth resource to the end of the first merged sequence from which the fourth duplicate resource is deleted, to form a second merged sequence;

[0189] The second merging order is reversed, and the reversed order is used as the resource update order corresponding to the fifth resource.

[0190] A third embodiment of the present application provides an electronic device, Fig.12 It is a schematic diagram of the structure of the electronic device provided in this embodiment.

[0191] like Fig.12 As shown, the electronic device provided in this embodiment includes: a memory 1201 and a processor 1202;

[0192] The memory 1201 is used to store computer instructions for executing the resource caching method;

[0193] The processor 1202 is configured to execute computer instructions stored in the memory 1201 to perform the following operations:

[0194] In response to an access instruction for a first resource, the first resource is stored or moved to a head position of a cache space, the cache space stores loaded resources in the form of a linked list, and the head position is a storage position in the linked list where the most recently used resource is stored;

[0195] The second resource is stored or moved to the head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

[0196] Optionally, the responding to the access instruction for the first resource to store or move the first resource to the head position of the cache space includes:

[0197] Determining whether the first resource is stored in the cache space;

[0198] In response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at a head position of the cache space;

[0199] In response to the first resource being stored in the cache space, the first resource stored in the cache space is moved to a head position.

[0200] Optionally, in response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at a head position of the cache space includes:

[0201] Determining whether the cache space is full;

[0202] In response to the cache space being not full, storing the first resource at a head position of the cache space;

[0203] In response to the cache space being full, the resource corresponding to the tail position of the cache space is moved out of the cache space, and the first resource is stored at the head position of the cache space.

[0204] Optionally, before the step of storing or moving the second resource to the head position of the cache space, the following steps are further performed:

[0205] Determine whether the first resource has a referenced resource;

[0206] The storing or moving the second resource to the head position of the cache space includes:

[0207] In response to the first resource having the second resource being referenced, the second resource is stored or moved to a head position of the cache space.

[0208] Optionally, in response to the first resource having the referenced second resource, storing or moving the second resource to the head position of the cache space includes:

[0209] Determining whether the second resource is stored in the cache space;

[0210] In response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at a head position of the cache space;

[0211] In response to the second resource being stored in the cache space, the second resource stored in the cache space is moved to a head position.

[0212] Optionally, in response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at a head position of the cache space includes:

[0213] Determining whether the cache space is full;

[0214] In response to the cache space being not full, storing the second resource at a head position of the cache space;

[0215] In response to the cache space being full, the resource located at the tail position of the cache space is moved out of the cache space, and the second resource is stored at the head position of the cache space.

[0216] Optionally, in response to an access instruction to a first resource, storing or moving the first resource to a head position of a cache space, and storing or moving a second resource to a head position of the cache space, includes:

[0217] Accessing a resource node tree corresponding to the first resource in a pre-order traversal manner, wherein the first resource is a parent node in the resource node tree, and the second resource is any child node in the resource node tree;

[0218] Along with the access process, the first resource and the second resource are sequentially stored or moved to the head position of the cache space.

[0219] Optionally, the resource node tree further includes a third resource and a fourth resource, the second resource and the third resource are resources directly referenced by the first resource, and the fourth resource is a resource directly referenced by the second resource;

[0220] The accompanying access process sequentially stores or moves the first resource and the second resource to the head position of the cache space, including:

[0221] In response to accessing the first resource, storing or moving the first resource to a head position of the cache space;

[0222] In response to accessing the second resource, storing or moving the second resource to a head position of the cache space, the first resource being located after the second resource;

[0223] In response to accessing the fourth resource, storing or moving the fourth resource to a head position of the cache space, the second resource being located after the fourth resource;

[0224] In response to accessing the third resource, storing or moving the third resource to the head position of the cache space, and the fourth resource is located after the third resource;

[0225] In response to the completion of the access to the resource node tree, the cache space stores at least the third resource located at the header position, the fourth resource located at the first position, the second resource located at the second position, and the first resource located at the third position; wherein the first position is a storage position after the header position, the second position is a storage position after the first position, and the third position is a storage position after the second position.

[0226] Optionally, also execute:

[0227] Determining a resource update order corresponding to the first resource according to a pre-order traversal order of a resource node tree corresponding to the first resource;

[0228] Recording a resource update sequence corresponding to the first resource;

[0229] The resource update sequence is used to represent the order of updating the storage locations of the first resource and the resources referenced by the first resource in the cache space.

[0230] Optionally, also execute:

[0231] In response to an access instruction for the first resource, storage locations of the first resource and resources referenced by the first resource in the cache space are updated according to a resource update sequence corresponding to the first resource.

[0232] Optionally, determining a resource update order corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource includes:

[0233] Determining a reverse pre-order traversal order of the resource node tree corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource;

[0234] Based on the reverse first-order traversal order of the resource node tree corresponding to the first resource, delete the second duplicate resource in the duplicate resources, the second duplicate resource is the duplicate resource other than the first duplicate resource in the duplicate resources, and the first duplicate resource is the duplicate resource that is ranked first in the duplicate resources;

[0235] The reverse pre-order traversal order after deleting the second duplicate resource is reversed, and the reversed order is used as the resource update order corresponding to the first resource.

[0236] Optionally, the first resource is a referenced resource of a fifth resource, and the resource node tree corresponding to the fifth resource includes the resource node tree corresponding to the first resource and the resource node tree corresponding to the sixth resource; further executing:

[0237] Determining a resource update order corresponding to the sixth resource according to a pre-order traversal order of a resource node tree corresponding to the sixth resource;

[0238] Recording a resource update sequence corresponding to the sixth resource;

[0239] Determine a resource update sequence corresponding to the fifth resource according to a resource update sequence corresponding to the first resource and a resource update sequence corresponding to the sixth resource;

[0240] Record the resource update sequence corresponding to the fifth resource.

[0241] Optionally, determining the resource update sequence corresponding to the fifth resource according to the resource update sequence corresponding to the first resource and the resource update sequence corresponding to the sixth resource includes:

[0242] Merging the inverse order of the resource update order corresponding to the sixth resource and the inverse order of the resource update order corresponding to the first resource to form a first merged order;

[0243] Based on the first merging order, delete a fourth repeated resource in the repeated resources, the fourth repeated resource being a repeated resource other than the third repeated resource in the repeated resources, and the third repeated resource being a repeated resource that is ranked first in the repeated resources;

[0244] adding the fifth resource to the end of the first merged sequence from which the fourth duplicate resource is deleted, to form a second merged sequence;

[0245] The second merging order is reversed, and the reversed order is used as the resource update order corresponding to the fifth resource.

[0246] A fourth embodiment of the present application provides a computer-readable storage medium, where the computer-readable storage medium includes computer instructions. When the computer instructions are executed by a processor, they are used to implement the methods described in the embodiments of the present application.

[0247] It should be noted that the relational terms such as "first" and "second" in this article are only used to distinguish one entity or operation from another entity or operation, and do not require or imply any actual relationship or order between these entities or operations. In addition, the words "include", "have", "include" and "includes" and other similar forms are the same in meaning, and the end of any one or more items after any of the above words is open-ended, and any of the above nouns does not mean that the one or more items have been exhaustively listed or are limited to the one or more items listed.

[0248] As used herein, unless expressly stated otherwise, the term "or" includes all possible combinations, except those that are not feasible. For example, if it is expressed that a database may include A or B, then unless otherwise specifically stated or not feasible, it may include database A, or B, or A and B. As a second example, if it is expressed that a database may include A, B, or C, then unless otherwise specifically stated or not feasible, the database may include database A, or B, or C, or A and B, or A and C, or B and C, or A, B, and C.

[0249] It is worth noting that the above embodiments can be implemented by hardware or software (program code), or a combination of hardware and software. If implemented by software, it can be stored in the above-mentioned computer-readable medium. When the software is executed by a processor, it can execute the above-mentioned disclosed method. The computing unit and other functional units described in the present disclosure can be implemented by hardware or software, or a combination of hardware and software. Those of ordinary skill in the art will also understand that the above-mentioned multiple modules / units can be combined into one module / unit, and each of the above-mentioned modules / units can be further divided into multiple sub-modules / sub-units.

[0250] In the above detailed description, the embodiments have been described with reference to many specific details, which may vary from implementation to implementation. Certain adaptations and modifications may be made to the embodiments. For those skilled in the art, other embodiments may be readily apparent from the specific embodiments disclosed in the present application. This specification and examples are for exemplary purposes only, and the true scope and essence of the present application are described by the claims. The sequence of steps shown in the diagrams is also for the purpose of explanation only and is not intended to be limited to any particular steps or sequence. Therefore, those skilled in the art will appreciate that these steps may be performed in different orders when implementing the same method.

[0251] In the drawings and detailed description of the present application, exemplary embodiments are disclosed. However, many variations and modifications may be made to these embodiments. Accordingly, although specific terms are used, these terms are only general and descriptive and not for the purpose of limitation.

Claims

1. A resource caching method, characterized in that: The method comprises: In response to an access instruction for a first resource, the first resource is stored or moved to a head position of a cache space, the cache space stores loaded resources in the form of a linked list, and the head position is a storage position in the linked list where the most recently used resource is stored; The second resource is stored or moved to the head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

2. The method according to claim 1, characterized in that: The step of responding to the access instruction for the first resource and storing or moving the first resource to the head position of the cache space includes: Determining whether the first resource is stored in the cache space; In response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at a head position of the cache space; In response to the first resource being stored in the cache space, the first resource stored in the cache space is moved to a head position.

3. The method according to claim 2, characterized in that In response to the first resource not being stored in the cache space, loading the first resource and storing the first resource at the head position of the cache space includes: Determining whether the cache space is full; In response to the cache space being not full, storing the first resource at a head position of the cache space; In response to the cache space being full, the resource corresponding to the tail position of the cache space is moved out of the cache space, and the first resource is stored at the head position of the cache space.

4. The method according to claim 1, characterized in that: Before the step of storing or moving the second resource to the head position of the cache space, the method further includes: Determine whether the first resource has a referenced resource; The storing or moving the second resource to the head position of the cache space includes: In response to the first resource having the second resource being referenced, the second resource is stored or moved to a head position of the cache space.

5. The method according to claim 4, characterized in that In response to the first resource having the referenced second resource, storing or moving the second resource to the head position of the cache space includes: Determining whether the second resource is stored in the cache space; In response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at a head position of the cache space; In response to the second resource being stored in the cache space, the second resource stored in the cache space is moved to a head position.

6. The method according to claim 5, characterized in that In response to the second resource not being stored in the cache space, loading the second resource and storing the second resource at the head position of the cache space includes: Determining whether the cache space is full; In response to the cache space being not full, storing the second resource at a head position of the cache space; In response to the cache space being full, the resource located at the tail position of the cache space is moved out of the cache space, and the second resource is stored at the head position of the cache space.

7. The method according to claim 1, characterized in that The step of responding to an access instruction to a first resource, storing or moving the first resource to a head position of a cache space, and storing or moving a second resource to a head position of the cache space, comprises: Accessing a resource node tree corresponding to the first resource in a pre-order traversal manner, wherein the first resource is a parent node in the resource node tree, and the second resource is any child node in the resource node tree; Along with the access process, the first resource and the second resource are stored or moved to the head position of the cache space in sequence.

8. The method according to claim 7, characterized in that The resource node tree further includes a third resource and a fourth resource, the second resource and the third resource are resources directly referenced by the first resource, and the fourth resource is a resource directly referenced by the second resource; The accompanying access process sequentially stores or moves the first resource and the second resource to the head position of the cache space, including: In response to accessing the first resource, storing or moving the first resource to a head position of the cache space; In response to accessing the second resource, storing or moving the second resource to a head position of the cache space, the first resource being located after the second resource; In response to accessing the fourth resource, storing or moving the fourth resource to a head position of the cache space, the second resource being located after the fourth resource; In response to accessing the third resource, storing or moving the third resource to the head position of the cache space, and the fourth resource is located after the third resource; In response to the completion of the access to the resource node tree, the cache space stores at least the third resource located at the header position, the fourth resource located at the first position, the second resource located at the second position, and the first resource located at the third position; wherein the first position is a storage position after the header position, the second position is a storage position after the first position, and the third position is a storage position after the second position.

9. The method according to claim 7, characterized in that: The method further comprises: Determining a resource update order corresponding to the first resource according to a pre-order traversal order of a resource node tree corresponding to the first resource; Recording a resource update sequence corresponding to the first resource; The resource update sequence is used to represent the order of updating the storage locations of the first resource and the resources referenced by the first resource in the cache space.

10. The method according to claim 9, characterized in that The method further comprises: In response to an access instruction for the first resource, storage locations of the first resource and resources referenced by the first resource in the cache space are updated according to a resource update sequence corresponding to the first resource.

11. The method according to claim 9, characterized in that The determining, according to the pre-order traversal order of the resource node tree corresponding to the first resource, a resource update order corresponding to the first resource comprises: Determining a reverse pre-order traversal order of the resource node tree corresponding to the first resource according to a pre-order traversal order of the resource node tree corresponding to the first resource; Based on the reverse first-order traversal order of the resource node tree corresponding to the first resource, delete the second duplicate resource in the duplicate resources, the second duplicate resource is the duplicate resource other than the first duplicate resource in the duplicate resources, and the first duplicate resource is the duplicate resource that is ranked first in the duplicate resources; The reverse pre-order traversal order after deleting the second duplicate resource is reversed, and the reversed order is used as the resource update order corresponding to the first resource.

12. The method according to claim 9, characterized in that The first resource is a referenced resource of a fifth resource, and the resource node tree corresponding to the fifth resource includes a resource node tree corresponding to the first resource and a resource node tree corresponding to a sixth resource; The method further comprises: Determining a resource update order corresponding to the sixth resource according to a pre-order traversal order of a resource node tree corresponding to the sixth resource; Recording a resource update sequence corresponding to the sixth resource; Determine a resource update sequence corresponding to the fifth resource according to a resource update sequence corresponding to the first resource and a resource update sequence corresponding to the sixth resource; Record the resource update sequence corresponding to the fifth resource.

13. The method according to claim 12, characterized in that The determining, according to the resource update sequence corresponding to the first resource and the resource update sequence corresponding to the sixth resource, the resource update sequence corresponding to the fifth resource includes: Merging the inverse order of the resource update order corresponding to the sixth resource and the inverse order of the resource update order corresponding to the first resource to form a first merged order; Based on the first merging order, delete a fourth repeated resource in the repeated resources, the fourth repeated resource being a repeated resource other than the third repeated resource in the repeated resources, and the third repeated resource being a repeated resource that is ranked first in the repeated resources; adding the fifth resource to the end of the first merged sequence from which the fourth duplicate resource is deleted, to form a second merged sequence; The second merging order is reversed, and the reversed order is used as the resource update order corresponding to the fifth resource.

14. A resource cache device, characterized in that: The device comprises: a parent resource cache unit and a child resource cache unit; The parent resource cache unit is used to respond to an access instruction for a first resource and store or move the first resource to a head position of a cache space, wherein the cache space stores loaded resources in the form of a linked list, and the head position is a storage position in the linked list where the most recently used resource is stored; The sub-resource cache unit is used to store or move the second resource to the head position of the cache space so that the storage position of the first resource in the cache space is located after the second resource, and the second resource is any one of the resources referenced by the first resource.

15. An electronic device, characterized in that: include: Memory, processor; The memory is used to store one or more computer instructions; The processor is used to execute the one or more computer instructions to implement the method according to any one of claims 1-13.

16. A computer-readable storage medium having one or more computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the method according to any one of claims 1 to 13 is performed.