Method, device, equipment and system for cleaning picture cache based on life cycle

By establishing reference mapping relationships during the lifecycle of Flutter components and monitoring and cleaning up cached resources in real time, the memory leak problem in traditional caching solutions is solved, achieving more efficient cache management.

CN121880587APending Publication Date: 2026-04-17SHENZHEN GREEN CONNECTION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHENZHEN GREEN CONNECTION TECH CO LTD
Filing Date
2025-12-19
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

In traditional image caching solutions, the LRU algorithm can cause memory leaks, especially because the timing of memory cleanup is not flexible enough and invalid memory cannot be released in time, leading to memory leaks.

Method used

By establishing a reference mapping relationship between image cache references and Flutter component Widget instances, the component lifecycle is monitored in real time, and a cache cleanup mechanism is triggered based on the lifecycle state, including multiple judgments on memory, disk, and network request conditions, to flexibly clean up cache resources.

Benefits of technology

It improves the timeliness and flexibility of cache cleanup, reduces memory leaks, ensures the accuracy and timeliness of image cache resources, and avoids the shortcomings of traditional solutions that only trigger cleanup when memory is extremely large.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121880587A_ABST
    Figure CN121880587A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a method, a device, equipment and a system for cleaning a picture cache based on a life cycle, the method comprises the following steps: establishing a reference mapping relationship between a picture cache reference and a Widget instance of a Flutter component by establishing a basic cache architecture; generating a cache key according to the picture loading request to judge whether the picture loading request meets a preset cache resource condition or not; if yes, displaying a target picture corresponding to a picture cache resource based on the picture cache resource corresponding to the cache key in the memory cache space; if not, determining that the component life cycle is in a component abnormal state; and if the life cycle of the component is in the preset state, executing a cache cleaning operation matched with the current state of the component. Visibly, by implementing the method and the device, the matched cache cleaning operation can be executed through the monitored component state change, so that the cache cleaning timeliness and flexibility can be improved, and the occurrence of memory leakage can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and system for cleaning up image cache based on its lifecycle. Background Technology

[0002] Currently, in order to reduce the time spent repeatedly loading images, Flutter components are usually configured to implement image caching, such as using the ImageCache built into the Flutter framework to cache images in memory.

[0003] However, in practice, it has been found that traditional caching schemes typically use the LRU (Least Recently Used) algorithm to manage memory caches. Its default memory cache size limit is relatively loose (usually 100MB or 1000 images). This algorithm simply detects memory size and only triggers the cleanup mechanism when it detects extreme memory pressure. This results in invalid memory not being released in a timely manner, and the memory cleanup timing is not flexible enough, leading to memory leaks. Therefore, proposing a new image caching scheme to reduce memory leaks is particularly important. Summary of the Invention

[0004] This invention provides a method, apparatus, device, and system for cleaning up image cache based on its lifecycle, which can improve the timeliness and flexibility of cache cleaning and reduce the occurrence of memory leaks.

[0005] To address the aforementioned technical problems, the first aspect of this invention discloses a method for clearing image cache based on a lifecycle. This method is applied to an electronic device with an installed application, and the electronic device is communicatively connected to a network attached storage device (NETS), accessing the NETS through the application. The method is used to clear any image cache resource in the electronic device or the NETS; wherein the method includes: By building a basic caching architecture, a reference mapping relationship is established between image cache references and Widget instances of Flutter components; When an image loading request is received, a cache key corresponding to the image loading request is generated based on the image loading request. Based on the cache key corresponding to the image loading request, determine whether the image loading request meets at least one preset cache resource condition; When it is determined that the image loading request meets at least one of the cached resource conditions, the target image corresponding to the image cached resource is displayed based on the image cached resource corresponding to the cache key in the memory cache space. When it is determined that the image loading request does not meet all the cached resource conditions, the component lifecycle of the Widget instance of the Flutter component is determined, indicating that the current state of the Flutter component is the abnormal state of the component. The component lifecycle can be transformed into the cached resource lifecycle of the image cache reference through the reference mapping relationship. If the component lifecycle indicates that the current state of the Flutter component is a preset state, then a cache cleanup operation matching the current state of the Flutter component is executed, wherein the preset state includes the component destruction state or the component abnormal state.

[0006] As an optional implementation, in the first aspect of the present invention, all of the cache resource conditions include at least one of memory cache resource conditions, disk cache resource conditions, and network request resource conditions; And, the step of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request includes: Based on the cache key corresponding to the image loading request, a pre-determined memory cache space is detected; and when the image cache resource corresponding to the cache key is detected in the memory cache space, it is determined that the image loading request meets the memory cache resource condition. When it is detected that the image cache resource corresponding to the cache key does not exist in the memory cache space, the pre-determined disk cache space is detected; and when it is detected that the image cache resource corresponding to the cache key exists in the disk cache space, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and it is determined that the image loading request meets the disk cache resource condition. When it is detected that there is no image cache resource corresponding to the cache key in either the memory cache space or the disk cache space, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained by performing the network download operation is saved to the disk cache space, and the operation of loading the image cache resource corresponding to the cache key in the disk cache space to the memory cache space is triggered, and it is determined that the image loading request meets the network request resource conditions. When an anomaly is detected in the network request, it is determined that the image loading request does not meet all the cached resource conditions.

[0007] As an optional implementation, in the first aspect of the present invention, before determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request, the method further includes: Based on network layer detection of pre-built file services, it is used to detect whether the status code corresponding to the image loading request is a preset target status code; When the status code is the target status code, the operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request is triggered. When the status code is not the target status code, the component lifecycle indicates that the current state of the Flutter component is the abnormal state of the component.

[0008] As an optional implementation, in the first aspect of the invention, performing a cache cleanup operation matching the current state includes: Based on the current state of the Flutter component, determine the objects to be cleaned up, which are storage containers that need to be cleaned up in the current state; Perform cache cleanup operations on the objects to be cleaned up; The step of determining the objects to be cleaned up based on the current state of the Flutter component includes: If the current state is the component destruction state, then the rendering layer corresponding to the image cache reference is determined as the object to be cleaned up; If the current state is an abnormal state of the component, then the disks corresponding to the rendering layer and the image cache reference are identified as the objects to be cleaned up.

[0009] As an optional implementation, in the first aspect of the present invention, performing a cache cleanup operation on the object to be cleaned includes: When the current state of the Flutter component is the destroyed state, the memory cache space of the rendering layer is released, and the disk cache space is retained; When the current state of the Flutter component is the abnormal state of the component, the failure cache resource corresponding to the abnormal state of the component is determined, and the failure cache resource in the memory cache space of the rendering layer and the failure cache resource in the disk cache space are released.

[0010] As an optional implementation, in the first aspect of the present invention, establishing a reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture includes: By building a basic caching architecture, we create a component management layer corresponding to the Widget instance of a Flutter component and a cache management layer corresponding to the image cache reference. Based on the component management layer and the cache management layer, a reference mapping relationship is established between the image cache reference and the Widget instance.

[0011] A second aspect of the present invention discloses an apparatus for cleaning up image cache based on a lifecycle. The apparatus is applied to an electronic device with an application installed, and the electronic device is communicatively connected to a network attached storage device (NETS) and accesses the NETS through the application. The apparatus is used to clean up any image cache resource in the electronic device or the NETS; wherein the apparatus includes: A module is created to establish a reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture; The generation module is used to generate a cache key corresponding to the image loading request when an image loading request is received. The judgment module is used to determine whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. The display module is used to display the target image corresponding to the image cache resource based on the image cache resource corresponding to the cache key in the memory cache space when the judgment module determines that the image loading request meets at least one of the cache resource conditions; The determination module is used to determine the component lifecycle of the Widget instance of the Flutter component when the judgment module determines that the image loading request does not meet all the cache resource conditions, indicating that the current state of the Flutter component is the abnormal state of the component, and the component lifecycle can be transformed into the cache resource lifecycle of the image cache reference through the reference mapping relationship; The cleanup module is used to perform a cache cleanup operation that matches the current state of the Flutter component if the component lifecycle indicates that the current state of the Flutter component is a preset state. The preset state includes the component destruction state or the component abnormal state.

[0012] As an optional implementation, in the second aspect of the present invention, all of the said cache resource conditions include at least one of memory cache resource conditions, disk cache resource conditions, and network request resource conditions; Furthermore, the specific method by which the judgment module determines whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request includes: Based on the cache key corresponding to the image loading request, a pre-determined memory cache space is detected; and when the image cache resource corresponding to the cache key is detected in the memory cache space, it is determined that the image loading request meets the memory cache resource condition. When it is detected that the image cache resource corresponding to the cache key does not exist in the memory cache space, the pre-determined disk cache space is detected; and when it is detected that the image cache resource corresponding to the cache key exists in the disk cache space, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and it is determined that the image loading request meets the disk cache resource condition. When it is detected that there is no image cache resource corresponding to the cache key in either the memory cache space or the disk cache space, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained by performing the network download operation is saved to the disk cache space, and the operation of loading the image cache resource corresponding to the cache key in the disk cache space to the memory cache space is triggered, and it is determined that the image loading request meets the network request resource conditions. When an anomaly is detected in the network request, it is determined that the image loading request does not meet all the cached resource conditions.

[0013] As an optional implementation, in a second aspect of the invention, the apparatus further includes: The detection module is used to detect a pre-built file service based on the network layer before the judgment module determines whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request, so as to detect whether the status code corresponding to the image loading request is a preset target status code; when the status code is the target status code, the judgment module is triggered to perform the operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. The determining module is further configured to determine that the component lifecycle indicates the current state of the Flutter component as the component abnormal state when the status code is not the target status code.

[0014] As an optional implementation, in a second aspect of the present invention, the specific manner in which the cleanup module performs a cache cleanup operation matching the current state includes: Based on the current state of the Flutter component, determine the objects to be cleaned up, which are storage containers that need to be cleaned up in the current state; Perform cache cleanup operations on the objects to be cleaned up; The specific methods by which the cleanup module determines the objects to be cleaned up based on the current state of the Flutter component include: If the current state is the component destruction state, then the rendering layer corresponding to the image cache reference is determined as the object to be cleaned up; If the current state is an abnormal state of the component, then the disks corresponding to the rendering layer and the image cache reference are identified as the objects to be cleaned up.

[0015] As an optional implementation, in the second aspect of the present invention, the specific manner in which the cleanup module performs cache cleanup operations on the object to be cleaned includes: When the current state of the Flutter component is the destroyed state, the memory cache space of the rendering layer is released, and the disk cache space is retained; When the current state of the Flutter component is the abnormal state of the component, the failure cache resource corresponding to the abnormal state of the component is determined, and the failure cache resource in the memory cache space of the rendering layer and the failure cache resource in the disk cache space are released.

[0016] As an optional implementation, in the second aspect of the present invention, the specific method by which the establishing module establishes the reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture includes: By building a basic caching architecture, we create a component management layer corresponding to the Widget instance of a Flutter component and a cache management layer corresponding to the image cache reference. Based on the component management layer and the cache management layer, a reference mapping relationship is established between the image cache reference and the Widget instance.

[0017] A third aspect of the present invention discloses an electronic device, the electronic device comprising: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for clearing image cache based on lifecycle disclosed in the first aspect of the present invention.

[0018] The fourth aspect of the present invention discloses a system for cleaning up image cache based on lifecycle. The system includes at least an apparatus for cleaning up image cache based on lifecycle as described in the second aspect of the present invention, and a network attached storage device communicatively connected to the apparatus for cleaning up image cache based on lifecycle. The network attached storage device stores image cache resources. When the apparatus for cleaning up image cache based on lifecycle processes any image cache resource, the apparatus for cleaning up image cache based on lifecycle performs a cleaning operation on the image cache resource according to the method for cleaning up image cache based on lifecycle as described in any of the first aspects of the present invention and based on the image cache resource. Alternatively, the system may include at least an electronic device as described in the third aspect of the present invention, and a network-attached storage device communicatively connected to the electronic device, wherein the network-attached storage device stores image cache resources, and when the electronic device processes any image cache resource, the electronic device performs a cleanup operation on the image cache resource based on the image cache resource according to the lifecycle-based image cache cleanup method as described in any of the first aspects of the present invention.

[0019] The fifth aspect of the present invention discloses a computer storage medium storing computer instructions, which, when invoked, are used to execute the lifecycle-based image cache clearing method disclosed in the first aspect of the present invention.

[0020] Compared with the prior art, the embodiments of the present invention have the following beneficial effects: Implementing this invention establishes a reference mapping relationship between image cache references and Flutter component Widget instances, and transforms the lifecycle of Flutter components into the lifecycle of cache resources through the reference mapping relationship. Thus, when the lifecycle of a Flutter component indicates that the component state meets the preset state, the corresponding automatic image cache cleanup mechanism is triggered, which helps to improve the timeliness and flexibility of cache cleanup. Compared with traditional cache solutions that only trigger the cleanup mechanism when memory is extremely high, this solution triggers cleanup in a timely manner by sensing changes in component state in real time, which helps to reduce the occurrence of memory leaks. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1This is a flowchart illustrating a method for clearing image cache based on lifecycle as disclosed in an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall architecture of an image caching system disclosed in an embodiment of the present invention; Figure 3 This is a flowchart of an automatic cache release process based on an embodiment of the present invention; Figure 4 This is a flowchart of a cache management process disclosed in an embodiment of the present invention; Figure 5 This is a schematic diagram of an exception handling memory release process disclosed in an embodiment of the present invention; Figure 6 This is a flowchart illustrating another method for clearing image cache based on lifecycle disclosed in an embodiment of the present invention; Figure 7 This is a schematic diagram of a device for cleaning up image cache based on lifecycle, as disclosed in an embodiment of the present invention. Figure 8 This is a schematic diagram of another device for cleaning up image cache based on lifecycle disclosed in an embodiment of the present invention; Figure 9 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention; Figure 10 This is a schematic diagram of the structure of a system for cleaning up image cache based on lifecycle, as disclosed in an embodiment of the present invention; Figure 11 This is a schematic diagram of another system for cleaning up image cache based on lifecycle, as disclosed in an embodiment of the present invention. Detailed Implementation

[0023] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0024] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or ends.

[0025] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0026] This invention discloses a method, apparatus, device, and system for clearing image cache based on its lifecycle. It establishes a reference mapping relationship between image cache references and Flutter component Widget instances, and converts the lifecycle of the Flutter component into the lifecycle of the cached resource through this reference mapping. Therefore, when the Flutter component's lifecycle indicates that the component state meets a preset state, an automatic image cache clearing mechanism is triggered. This improves the timeliness and flexibility of cache clearing. Compared to traditional caching solutions that only trigger clearing mechanisms when memory usage is extremely high, this solution triggers clearing promptly by sensing changes in component state in real time, which helps reduce memory leaks. Detailed explanations follow.

[0027] Example 1 Please see Figure 1 , Figure 1 This is a flowchart illustrating a method for clearing image cache based on lifecycle, as disclosed in an embodiment of the present invention. Figure 1 The described method for clearing image cache based on lifecycle can be applied to electronic devices with installed applications, where the electronic device is communicatively connected to a network attached storage device (NETS) and accesses the NETS through the application. The method is used to clear any image cache resource in the electronic device or the NETS. This method can also be applied to a device for clearing image cache based on lifecycle, wherein the device may include a clearing device or a clearing server, where the clearing server may include a cloud server or a local server; this embodiment of the invention does not impose limitations. Figure 1 As shown, this method for clearing image cache based on lifecycle can include the following operations: 101. By building a basic caching architecture, establish a reference mapping relationship between image cache references and Flutter component Widget instances.

[0028] In this embodiment of the invention, Flutter components represent independent functional units that constitute the user interface. They can be described using declarative syntax to describe the appearance and behavior of UI elements, have immutability, and form a complete interface tree structure through nested combination.

[0029] In this embodiment of the invention, a Widget instance refers to a Widget object entity that is concretely created in memory. Each instance carries specific configuration parameters (such as color and size) and serves as a configuration blueprint for the Flutter framework to build the Element tree. It will be rebuilt when the interface is refreshed, but the configuration values ​​remain unchanged.

[0030] In this embodiment of the invention, the image cache reference represents an access credential to the image data object in the cache. By holding this reference, the decoded bitmap resource can be quickly obtained without repeated loading. It also has a reference counting function, and the system determines whether the memory data can be safely released based on the number of references held.

[0031] In this embodiment of the invention, the cache key strategy refers to the algorithm rules for generating unique identifiers based on multi-dimensional parameters such as image URL, size, and scaling mode. Through normalization processing, it ensures that image requests with the same visual effect hit the same cache entry, and different parameter combinations generate different keys to avoid resource conflicts.

[0032] In this embodiment of the invention, the reference mapping relationship refers to establishing a bidirectional association record between the image cache key and the Widget instance. For example, when the image data is used by a Widget instance, the count is incremented by 1, and when the Widget instance is destroyed, the count is decremented by 1. This mapping helps to accurately track the usage of cached resources and thus trigger an automatic cleanup mechanism.

[0033] 102. When an image loading request is received, generate a cache key corresponding to the image loading request based on the image loading request.

[0034] In this embodiment of the invention, specifically, based on the cache key strategy, a cache key corresponding to the image loading request is generated according to the image loading request.

[0035] 103. Based on the cache key corresponding to the image loading request, determine whether the image loading request meets at least one preset cache resource condition.

[0036] In this embodiment of the invention, optionally, all cache resource conditions may include at least one of memory cache resource conditions, disk cache resource conditions, and network request resource conditions. Memory cache resource conditions may be used to indicate the condition that memory cache space is detected, disk cache resource conditions may be used to indicate the condition that disk cache space is detected, and network request resource conditions may be the condition that an image cache resource matching the image loading request is detected by a network request and downloaded over the network. This embodiment of the invention does not impose any limitations on these conditions.

[0037] In this embodiment of the invention, when the judgment result in step 103 is yes, that is, when it is determined that the image loading request meets at least one cached resource condition, step 104 is triggered; when the judgment result in step 103 is no, that is, when it is determined that the image loading request does not meet all cached resource conditions, step 105 is triggered.

[0038] 104. Based on the image cache resource corresponding to the cache key in the memory cache space, display the target image corresponding to the image cache resource.

[0039] 105. Determine the component lifecycle of the Widget instance of the Flutter component, indicating that the current state of the Flutter component is an abnormal component state.

[0040] In this embodiment of the invention, the component lifecycle can be transformed into the cache resource lifecycle of the image cache reference through a reference mapping relationship. Taking the above example of incrementing the count by 1 when image data is used by a Widget instance and decrementing the count by 1 when the Widget instance is destroyed, this method can determine the count of image data represented by the cache resource lifecycle of the image cache reference based on the specific situation of the Widget instance represented by the component lifecycle.

[0041] 106. If the component lifecycle indicates that the current state of the Flutter component is a preset state, then perform a cache clearing operation that matches the current state of the Flutter component.

[0042] In this embodiment of the invention, the preset state includes a component destruction state or a component abnormal state. Specifically, when a Widget instance is destroyed, or when a Flutter component is destroyed (such as when the page exits, a list item slides off the screen, etc.), it is determined that the Flutter component is in a component destruction state; or, when the UI layer is abnormal, it can be indirectly determined that the Flutter component is in a component abnormal state.

[0043] It is evident that implementation Figure 1The described lifecycle-based image cache cleanup method establishes a reference mapping between image cache references and Flutter component Widget instances. It automatically generates a cache key corresponding to each received image loading request, thereby determining whether the memory cache space meets preset cache resource conditions. If the conditions are met, the target image is displayed directly based on the image cache resource corresponding to the cache key in the memory cache space, improving the accuracy and timeliness of image cache resource identification, and consequently, the accuracy and timeliness of target image display. Only when all cache resource conditions are not met is the Flutter component's lifecycle deemed abnormal, improving the accuracy and reliability of component anomaly monitoring. Furthermore, by converting the Flutter component's lifecycle into the cache resource lifecycle through a reference mapping, an automatic image cache cleanup mechanism is triggered when the Flutter component's lifecycle indicates that the component state meets preset conditions. This improves the timeliness and flexibility of cache cleanup. Compared to traditional caching solutions that only trigger cleanup when memory usage is extremely high, this solution triggers cleanup promptly by sensing changes in component state in real time, reducing the likelihood of memory leaks.

[0044] In an optional embodiment, step 101 above, which establishes a reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture, includes: By building a basic caching architecture, we create a component management layer corresponding to the Widget instance of a Flutter component and a cache management layer corresponding to the image cache reference. Based on the component management layer and the cache management layer, establish a reference mapping relationship between image cache references and Widget instances.

[0045] In this embodiment of the invention, the basic caching architecture can be the overall architecture of the image caching system, and as follows: Figure 2 As shown, Figure 2 This is a schematic diagram of the overall architecture of an image caching system disclosed in an embodiment of the present invention. The architecture may include a UI presentation layer, a component management layer, and a caching management layer. Specifically: The UI presentation layer can realize the function of displaying and controlling the widget tree. Optionally, the image processing range that the UI presentation layer can control can include at least one of ordinary images, SVG images, and placeholder processing. Among them, ordinary images can be images that are different from SVG formats, such as JPG and PNG formats. This embodiment of the invention does not limit the scope of the images. The component management layer can achieve automatic lifecycle management. Specifically, it can achieve intelligent component refresh, memory release of image cache, etc. through at least one of the following code: initState(), didUpdateWidget(), dispost(), setState(). This embodiment of the invention does not limit this. The cache management layer can implement the hierarchical storage function of cache strategy, and it is implemented through the image cache manager. Specifically, the image cache manager can also implement at least one of the functions of singleton mode, memory caching, disk caching, etc., which are not limited in this embodiment of the invention. Furthermore, such as Figure 2 As shown, the architecture can also include a network service layer. By combining the network service layer with the UI presentation layer, component management layer, and cache management layer, at least one of the following file service functions can be implemented: HTTPS support, certificate processing, anomaly detection, and proactive cleanup.

[0046] In specific embodiments of the present invention, such as... Figure 3 As shown, Figure 3 This invention discloses a flowchart of an automatic cache release process throughout its lifecycle, which may include the following steps: Build and initialize the basic caching architecture; Construct the configuration tree (i.e., the state object) corresponding to the Widget instance, generate the cache key, calculate the cache size, and register callback listeners; During the process of building the configuration tree corresponding to the Widget instance, didUpdateWidget(), which is the lifecycle callback function of the state object, is called to check whether the old and new cache keys have changed; If the old and new cache keys are found to be the same, continue the above process. When a difference is detected between the old and new cache keys, an operation to rebuild the configuration tree corresponding to the Widget instance is triggered. After completing the operation of building the configuration tree corresponding to the Widget instance, the system detects lifecycle events such as page switching and Flutter component dispose to select operations such as precisely releasing memory cache, retaining disk cache, and automatically whether to cache memory.

[0047] As can be seen, this optional embodiment can accurately create the component management layer corresponding to the Widget instance of the Flutter component and the cache management layer corresponding to the image cache reference by building a basic caching architecture, thereby quickly and accurately establishing the reference mapping relationship between the image cache reference and the Widget instance.

[0048] In another optional embodiment, step 103 above, determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request, includes: Based on the cache key corresponding to the image loading request, the pre-determined memory cache space is detected; and when the image cache resource corresponding to the cache key is detected in the memory cache space, it is determined that the image loading request meets the memory cache resource condition. When it is detected that there is no image cache resource corresponding to the cache key in the memory cache space, the pre-determined disk cache space is checked; and when it is detected that there is an image cache resource corresponding to the cache key in the disk cache space, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and it is determined that the image loading request meets the disk cache resource conditions. When it is detected that there is no image cache resource corresponding to the cache key in either the memory cache space or the disk cache space, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained from the network download operation is saved to the disk cache space, and the operation of loading the image cache resource corresponding to the cache key in the disk cache space into the memory cache space is triggered, and the image loading request is determined to meet the network request resource conditions. When an abnormal network request is detected, it is determined that the image loading request does not meet all cached resource conditions.

[0049] Specifically, such as Figure 4 As shown, Figure 4 This is a cache management flowchart disclosed in an embodiment of the present invention. The cache management flowchart may include the following steps: receiving an image loading request and generating a cache key corresponding to the image loading request; Based on the cache key corresponding to the image loading request, the pre-determined memory cache is detected; and when a cache key is detected in the memory cache, the target image corresponding to the image loading request is displayed based on the image cache resource corresponding to the cache key in the memory cache. When a cache key is not found in the memory cache, the pre-determined disk cache is checked; and when a cache key is found in the disk cache, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and the operation of displaying the target image corresponding to the image loading request is triggered based on the image cache resource corresponding to the cache key in the memory cache. When it is detected that the cache key does not exist in either the memory cache or the disk cache, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained from the network download operation is saved to the disk cache, and the operation of loading the image cache resource corresponding to the cache key in the disk cache into the memory cache is triggered, as well as the operation of displaying the target image corresponding to the image loading request based on the image cache resource corresponding to the cache key in the memory cache is triggered. When an abnormal network request is detected, the component lifecycle is determined to indicate that the current state of the Flutter component is an abnormal state.

[0050] As can be seen, this optional embodiment can improve the accuracy and reliability of judging whether a Flutter component is abnormal by combining multiple conditions such as memory cache resource conditions, disk cache resource conditions, and network request resource conditions, based on the cache key corresponding to the image loading request. This improves the accuracy and reliability of component lifecycle monitoring, and further improves the accuracy and reliability of cache resource lifecycle monitoring.

[0051] In yet another optional embodiment, before determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request, the method may further include: Based on network layer detection, a pre-built file service is used to detect whether the status code corresponding to the image loading request is the preset target status code; When the status code is the target status code, an operation is triggered to determine whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. When the status code is not the target status code, determining the component lifecycle indicates that the current state of the Flutter component is an abnormal state.

[0052] In embodiments of the present invention, such as Figure 5 As shown, Figure 5 This is a schematic diagram of an exception handling memory release process disclosed in an embodiment of the present invention, wherein the exception handling memory release process may include the following steps: It receives image loading requests and detects pre-built file services based on the network layer to check whether the status code corresponding to the image loading request is the preset target status code, such as whether it is 200. If the status code is 200, the operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request will be triggered directly. Alternatively, as shown in the figure, a Content-Type check will be performed first to obtain the check result. If the check result indicates that it is normal, the above operation will be triggered to display the image normally. If the status code is not 200, or if the status code is 200 and the check result indicates that it contains JSON format, the exception response handling process is triggered. Specifically, this process may include: immediately clearing the disk cache, recording detailed logs, throwing an HttpException exception, performing UI layer exception handling, clearing the cache again, and displaying an error placeholder.

[0053] As can be seen, this optional embodiment can, after receiving an image loading request, first detect the pre-built file service based on the network layer to accurately detect whether the status code is the preset target status code. If so, it triggers the subsequent operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. This improves the accuracy and timeliness of the cache resource condition determination operation. If not, it directly determines that the Flutter component is in an abnormal state. This is beneficial for improving the accuracy, flexibility, and diversity of monitoring whether the Flutter component is abnormal based on the status code and cache resource conditions.

[0054] Example 2 Please see Figure 6 , Figure 6 This is a flowchart illustrating a method for clearing image cache based on lifecycle, as disclosed in an embodiment of the present invention. Figure 6 The described method for clearing image cache based on lifecycle can be applied to electronic devices with installed applications, where the electronic device is communicatively connected to a network attached storage device (NETS) and accesses the NETS through the application. The method is used to clear any image cache resource in the electronic device or the NETS. This method can also be applied to a device for clearing image cache based on lifecycle, wherein the device may include a clearing device or a clearing server, where the clearing server may include a cloud server or a local server; this embodiment of the invention does not impose limitations. Figure 6 As shown, this method for clearing image cache based on lifecycle can include the following operations: 201. By building a basic caching architecture, establish a reference mapping relationship between image cache references and Flutter component Widget instances.

[0055] 202. When an image loading request is received, generate a cache key corresponding to the image loading request based on the image loading request.

[0056] 203. Based on the cache key corresponding to the image loading request, determine whether the image loading request meets at least one preset cache resource condition.

[0057] In this embodiment of the invention, when the judgment result in step 203 is yes, that is, when it is determined that the image loading request meets at least one cached resource condition, step 204 is triggered; when the judgment result in step 203 is no, that is, when it is determined that the image loading request does not meet all cached resource conditions, step 205 is triggered.

[0058] 204. Based on the image cache resource corresponding to the cache key in the memory cache space, display the target image corresponding to the image cache resource.

[0059] 205. Determine the component lifecycle of the Widget instance of the Flutter component, indicating that the current state of the Flutter component is an abnormal component state.

[0060] In this embodiment of the invention, for other descriptions of steps 201-205, please refer to the detailed description of steps 101-105 in Embodiment 1. These descriptions will not be repeated in this embodiment of the invention.

[0061] 206. If the component lifecycle indicates that the current state of the Flutter component is a preset state, then determine the objects to be cleaned up based on the current state of the Flutter component.

[0062] In this embodiment of the invention, the object to be cleaned is the storage container that needs to be cleaned in its current state.

[0063] 207. Perform cache cleanup operations on the objects to be cleaned up.

[0064] It is evident that implementation Figure 6The described lifecycle-based image cache cleanup method establishes a reference mapping between image cache references and Flutter component Widget instances. It automatically generates a cache key corresponding to each received image loading request, thereby determining whether the memory cache space meets preset cache resource conditions. If the conditions are met, the target image is displayed directly based on the image cache resource corresponding to the cache key in the memory cache space, improving the accuracy and timeliness of image cache resource identification, and consequently, the accuracy and timeliness of target image display. Only when all cache resource conditions are not met is the Flutter component's lifecycle deemed abnormal, improving the accuracy and reliability of component anomaly monitoring. Furthermore, by converting the Flutter component's lifecycle into the cache resource lifecycle through a reference mapping, an automatic image cache cleanup mechanism is triggered when the Flutter component's lifecycle indicates that the component state meets preset conditions. This improves the timeliness and flexibility of cache cleanup. Compared to traditional caching solutions that only trigger cleanup when memory usage is extremely high, this solution triggers cleanup promptly by sensing changes in component state in real time, reducing the likelihood of memory leaks. In addition, it can flexibly and accurately determine the objects to be cleaned based on the current state of the monitored Flutter components, and then perform corresponding cache cleanup operations on the objects to be cleaned, which helps to further improve the flexibility and accuracy of cache cleanup.

[0065] In an optional embodiment, step 203 above, determining the objects to be cleaned up based on the current state of the Flutter component, includes: If the current state is the component destruction state, then determine the rendering layer corresponding to the image cache reference as the object to be cleaned up; If the current state is an abnormal state of the component, then the disks corresponding to the rendering layer and image cache references are identified as objects to be cleaned up.

[0066] As can be seen, this optional embodiment can determine the rendering layer corresponding to the image cache reference as the object to be cleaned when the current state is the component destruction state. It can improve the accuracy and reliability of subsequent cleaning of the rendering layer based on the component destruction state. When the current state is the component abnormal state, it can determine the disk corresponding to the rendering layer and the image cache reference as the object to be cleaned. It can improve the accuracy and reliability of subsequent cleaning of the disk cache based on the component abnormal state.

[0067] In another optional embodiment, the cache cleanup operation performed on the object to be cleaned in step 204 above includes: When a Flutter component is in the destroyed state, release the memory cache space of the rendering layer and retain the disk cache space; When the current state of a Flutter component is an abnormal state, determine the failure cache resources corresponding to the abnormal state, and release the failure cache resources in the memory cache space of the rendering layer, as well as the failure cache resources in the disk cache space.

[0068] In this embodiment of the invention, optionally, when a component is destroyed, such as when the page exits or a list item slides off the screen, evict() can be automatically called to release the rendering layer image cache. In this case, the rendering cache in memory is released, not the disk cache, which saves memory and maintains the caching effect. It can also use a precise cacheKey to ensure that only the image cache corresponding to the current component is released. Alternatively, if no widget key is set and the cache key changes, the rendering layer can be triggered to re-render, avoiding unnecessary rebuilding. This design ensures that the image is updated correctly and avoids frequent component rebuilding. Here, the widget key can represent the cache key of the widget instance.

[0069] In this embodiment of the invention, optionally, when a component malfunctions, such as when the UI layer malfunctions, it can be determined that the image loading failed, triggering the clearing of the failure cache in the rendering layer and disk cache.

[0070] As can be seen, this optional embodiment can, based on the current state of the Flutter component, choose to release only the rendering layer cache while retaining the disk cache when the Flutter component is in a destroyed state, which is beneficial for saving rendering layer memory while maintaining the disk cache effect. When the Flutter component is in an abnormal state, it can choose whether to render the layer and disk cache at the same time, which is beneficial for achieving deep cleaning of image cache.

[0071] Example 3 Please see Figure 7 , Figure 7 This is a schematic diagram of a device for cleaning up image cache based on lifecycle, as disclosed in an embodiment of the present invention. Figure 7 The described lifecycle-based image cache cleanup apparatus can be applied to electronic devices with installed applications. The electronic device is communicatively connected to a network attached storage device (NETS) and accesses the NETS via the application. The apparatus is used to clean up any image cache resource in the electronic device or the NETS. The apparatus may include a cleanup device or a cleanup server, wherein the cleanup server may be a cloud server or a local server; this embodiment of the invention is not limited thereto. Figure 7 As shown, the device for clearing image cache based on lifecycle may include: Module 301 is established to create a reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture.

[0072] The generation module 302 is used to generate a cache key corresponding to the image loading request when an image loading request is received.

[0073] The judgment module 303 is used to determine whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request.

[0074] The display module 304 is used to display the target image corresponding to the image cache resource based on the image cache resource corresponding to the cache key in the memory cache space when the judgment module 303 determines that the image loading request meets at least one cache resource condition.

[0075] The determination module 305 is used to determine the component lifecycle of the Widget instance of the Flutter component when the judgment module 303 determines that the image loading request does not meet all cached resource conditions. This indicates that the current state of the Flutter component is an abnormal state, and the component lifecycle can be transformed into the cached resource lifecycle of the image cache reference through the reference mapping relationship.

[0076] The cleanup module 306 is used to perform cache cleanup operations that match the current state of the Flutter component if the component lifecycle indicates that the current state of the Flutter component is a preset state. The preset state includes the component destruction state or the component abnormal state.

[0077] It is evident that implementation Figure 7The described lifecycle-based image cache cleanup device establishes a reference mapping relationship between image cache references and Flutter component Widget instances. Based on received image loading requests, it automatically generates a cache key corresponding to the image loading request, thereby determining whether the memory cache space meets preset cache resource conditions. If the cache resource conditions are met, the target image is directly displayed based on the image cache resource corresponding to the cache key in the memory cache space, improving the accuracy and timeliness of image cache resource identification, and thus improving the accuracy and timeliness of target image display. Only when all cache resource conditions are not met is the lifecycle of the Flutter component determined to be abnormal, which helps improve the accuracy and reliability of component anomaly monitoring. Furthermore, by converting the Flutter component lifecycle into the cache resource lifecycle through a reference mapping relationship, an automatic image cache cleanup mechanism is triggered when the Flutter component's lifecycle indicates that the component state meets preset conditions, improving the timeliness and flexibility of cache cleanup. Compared to traditional cache solutions that only trigger cleanup mechanisms when memory is extremely high, this solution triggers cleanup promptly by sensing changes in component state in real time, which helps reduce memory leaks.

[0078] In an optional embodiment, all cache resource conditions include at least one of memory cache resource conditions, disk cache resource conditions, and network request resource conditions. Furthermore, the specific method by which the determining module 303 determines whether an image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request includes: Based on the cache key corresponding to the image loading request, the pre-determined memory cache space is detected; and when the image cache resource corresponding to the cache key is detected in the memory cache space, it is determined that the image loading request meets the memory cache resource condition. When it is detected that there is no image cache resource corresponding to the cache key in the memory cache space, the pre-determined disk cache space is checked; and when it is detected that there is an image cache resource corresponding to the cache key in the disk cache space, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and it is determined that the image loading request meets the disk cache resource conditions. When it is detected that there is no image cache resource corresponding to the cache key in either the memory cache space or the disk cache space, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained from the network download operation is saved to the disk cache space, and the operation of loading the image cache resource corresponding to the cache key in the disk cache space into the memory cache space is triggered, and the image loading request is determined to meet the network request resource conditions. When an abnormal network request is detected, it is determined that the image loading request does not meet all cached resource conditions.

[0079] As can be seen, this optional embodiment can improve the accuracy and reliability of judging whether a Flutter component is abnormal by combining multiple conditions such as memory cache resource conditions, disk cache resource conditions, and network request resource conditions, based on the cache key corresponding to the image loading request. This improves the accuracy and reliability of component lifecycle monitoring, and further improves the accuracy and reliability of cache resource lifecycle monitoring.

[0080] In another alternative embodiment, such as Figure 8 As shown, the device may further include: The detection module 307 is used to detect a pre-built file service based on the network layer before the judgment module 303 determines whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. This is to detect whether the status code corresponding to the image loading request is a preset target status code. When the status code is the target status code, the judgment module 303 is triggered to perform the operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. The determination module 305 is also used to determine the component lifecycle when the status code is not the target status code, indicating that the current state of the Flutter component is an abnormal state.

[0081] As can be seen, this optional embodiment can, after receiving an image loading request, first detect the pre-built file service based on the network layer to accurately detect whether the status code is the preset target status code. If so, it triggers the subsequent operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. This improves the accuracy and timeliness of the cache resource condition determination operation. If not, it directly determines that the Flutter component is in an abnormal state. This is beneficial for improving the accuracy, flexibility, and diversity of monitoring whether the Flutter component is abnormal based on the status code and cache resource conditions.

[0082] In yet another optional embodiment, the specific manner in which the cleanup module 303 performs a cache cleanup operation matching the current state includes: Based on the current state of the Flutter component, determine the objects to be cleaned up. The objects to be cleaned up are the storage containers that need to be cleaned up in the current state. Perform cache cleanup operations on the objects to be cleaned up.

[0083] As can be seen, this optional embodiment can flexibly and accurately determine the objects to be cleaned based on the current state of the monitored Flutter components, and then perform corresponding cache cleanup operations on the objects to be cleaned, which helps to further improve the flexibility and accuracy of cache cleanup.

[0084] In this optional embodiment, as an optional implementation method, the cleanup module 303 determines the specific method of the object to be cleaned based on the current state of the Flutter component, including: If the current state is the component destruction state, then determine the rendering layer corresponding to the image cache reference as the object to be cleaned up; If the current state is an abnormal state of the component, then the disks corresponding to the rendering layer and image cache references are identified as objects to be cleaned up.

[0085] As can be seen, this optional implementation can identify the rendering layer corresponding to the image cache reference as the object to be cleaned when the current state is the component destruction state. It can improve the accuracy and reliability of subsequent cleaning of the rendering layer based on the component destruction state. When the current state is the component abnormal state, it can identify the disk corresponding to the rendering layer and the image cache reference as the object to be cleaned. It can improve the accuracy and reliability of subsequent cleaning of the disk cache based on the component abnormal state.

[0086] In this optional embodiment, as another optional implementation, the specific method by which the cleanup module 303 performs cache cleanup operations on the objects to be cleaned includes: When a Flutter component is in the destroyed state, release the memory cache space of the rendering layer and retain the disk cache space; When the current state of a Flutter component is an abnormal state, determine the failure cache resources corresponding to the abnormal state, and release the failure cache resources in the memory cache space of the rendering layer, as well as the failure cache resources in the disk cache space.

[0087] As can be seen, this optional implementation can, based on the current state of the Flutter component, choose to release only the rendering layer cache while retaining the disk cache when the Flutter component is in a destroyed state, which is beneficial for saving rendering layer memory while maintaining the disk cache effect. When the Flutter component is in an abnormal state, it can choose whether to render the layer and disk cache at the same time, which is beneficial for achieving deep cleaning of image cache.

[0088] In another optional embodiment, the specific method by which the establishment module 301 establishes the reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture includes: By building a basic caching architecture, we create a component management layer corresponding to the Widget instance of a Flutter component and a cache management layer corresponding to the image cache reference. Based on the component management layer and the cache management layer, establish a reference mapping relationship between image cache references and Widget instances.

[0089] As can be seen, this optional embodiment can accurately create the component management layer corresponding to the Widget instance of the Flutter component and the cache management layer corresponding to the image cache reference by building a basic caching architecture, thereby quickly and accurately establishing the reference mapping relationship between the image cache reference and the Widget instance.

[0090] Example 4 Please see Figure 9 , Figure 9 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. For example... Figure 9 As shown, the electronic device may include: Memory 401 storing executable program code; Processor 402 coupled to memory 401; The processor 402 calls the executable program code stored in the memory 401 to execute the steps in the method for cleaning up image cache based on lifecycle described in Embodiment 1 or Embodiment 2 of the present invention.

[0091] Example 5 Please see Figure 10 , Figure 10 This is a schematic diagram of the structure of a system for cleaning up image cache based on lifecycle, as disclosed in an embodiment of the present invention. Figure 10 As shown, the system includes at least a lifecycle-based image cache cleaning device 30 as described in Embodiment 3 of the present invention, and a network attached storage device 50 communicatively connected to the lifecycle-based image cache cleaning device 30. The network attached storage device 50 stores image cache resources. When the lifecycle-based image cache cleaning device 30 processes any image cache resource, the lifecycle-based image cache cleaning device 30 completes the cleaning operation for the image cache resource according to the lifecycle-based image cache cleaning method described in Embodiment 1 or Embodiment 2 of the present invention and based on the image cache resource. or, Please see Figure 11 , Figure 11This is a schematic diagram of another system for cleaning up image cache based on lifecycle disclosed in an embodiment of the present invention, such as... Figure 11 As shown, the system includes at least an electronic device 40 as described in Embodiment 4 of the present invention, and a network attached storage device 50 communicatively connected to the electronic device 40. The network attached storage device 50 stores image cache resources. When the electronic device 40 processes any image cache resource, the electronic device 40 performs a cleanup operation on the image cache resource based on the lifecycle-based image cache cleanup method described in Embodiment 1 or Embodiment 2 of the present invention.

[0092] Example 6 This invention discloses a computer storage medium storing computer instructions. When these computer instructions are invoked, they are used to execute the steps in the lifecycle-based image cache clearing method described in Embodiment 1 or Embodiment 2 of this invention.

[0093] Example 7 This invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform the steps in the lifecycle-based image cache cleanup method described in Embodiment 1 or Embodiment 2.

[0094] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0095] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.

[0096] Finally, it should be noted that the method, apparatus, device, and system for clearing image cache based on lifecycle disclosed in the embodiments of the present invention are merely preferred embodiments of the present invention and are only used to illustrate the technical solutions of the present invention, not to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for clearing image cache based on lifecycle, characterized in that, The method is applied to an electronic device with an application installed, and the electronic device is communicatively connected to a network attached storage device (NETS), accessing the NETS through the application. The method is used to clear any image cache resources in the electronic device or the NETS; wherein the method includes: By building a basic caching architecture, a reference mapping relationship is established between image cache references and Widget instances of Flutter components; When an image loading request is received, a cache key corresponding to the image loading request is generated based on the image loading request. Based on the cache key corresponding to the image loading request, determine whether the image loading request meets at least one preset cache resource condition; When it is determined that the image loading request meets at least one of the cached resource conditions, the target image corresponding to the image cached resource is displayed based on the image cached resource corresponding to the cache key in the memory cache space. When it is determined that the image loading request does not meet all the cached resource conditions, the component lifecycle of the Widget instance of the Flutter component is determined, indicating that the current state of the Flutter component is the abnormal state of the component. The component lifecycle can be transformed into the cached resource lifecycle of the image cache reference through the reference mapping relationship. If the component lifecycle indicates that the current state of the Flutter component is a preset state, then a cache cleanup operation matching the current state of the Flutter component is executed, wherein the preset state includes the component destruction state or the component abnormal state.

2. The method for clearing image cache based on lifecycle as described in claim 1, characterized in that, All of the aforementioned caching resource conditions include at least one of memory caching resource conditions, disk caching resource conditions, and network request resource conditions; And, the step of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request includes: Based on the cache key corresponding to the image loading request, a pre-determined memory cache space is detected; and when the image cache resource corresponding to the cache key is detected in the memory cache space, it is determined that the image loading request meets the memory cache resource condition. When it is detected that the image cache resource corresponding to the cache key does not exist in the memory cache space, the pre-determined disk cache space is detected; and when it is detected that the image cache resource corresponding to the cache key exists in the disk cache space, the image cache resource corresponding to the cache key in the disk cache is loaded into the memory cache, and it is determined that the image loading request meets the disk cache resource condition. When it is detected that there is no image cache resource corresponding to the cache key in either the memory cache space or the disk cache space, a network download operation is performed on the image loading request, and the network request corresponding to the network download operation is detected. When the network request is detected to be normal, the image cache resource corresponding to the cache key obtained by performing the network download operation is saved to the disk cache space, and the operation of loading the image cache resource corresponding to the cache key in the disk cache space to the memory cache space is triggered, and it is determined that the image loading request meets the network request resource conditions. When an anomaly is detected in the network request, it is determined that the image loading request does not meet all the cached resource conditions.

3. The method for clearing image cache based on lifecycle as described in claim 1 or 2, characterized in that, Before determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request, the method further includes: Based on network layer detection of pre-built file services, it is used to detect whether the status code corresponding to the image loading request is a preset target status code; When the status code is the target status code, the operation of determining whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request is triggered. When the status code is not the target status code, the component lifecycle indicates that the current state of the Flutter component is the abnormal state of the component.

4. The method for clearing image cache based on lifecycle as described in claim 1 or 2, characterized in that, The cache cleanup operation matching the current state includes: Based on the current state of the Flutter component, determine the objects to be cleaned up, which are storage containers that need to be cleaned up in the current state; Perform cache cleanup operations on the objects to be cleaned up; The step of determining the objects to be cleaned up based on the current state of the Flutter component includes: If the current state is the component destruction state, then the rendering layer corresponding to the image cache reference is determined as the object to be cleaned up; If the current state is an abnormal state of the component, then the disks corresponding to the rendering layer and the image cache reference are identified as the objects to be cleaned up.

5. The method for clearing image cache based on lifecycle as described in claim 4, characterized in that, The cache cleanup operation performed on the object to be cleaned includes: When the current state of the Flutter component is the destroyed state, release the memory cache space of the rendering layer and retain the disk cache space; When the current state of the Flutter component is the abnormal state of the component, the failure cache resource corresponding to the abnormal state of the component is determined, and the failure cache resource in the memory cache space of the rendering layer and the failure cache resource in the disk cache space are released.

6. The method for clearing image cache based on lifecycle according to any one of claims 1, 2, and 5, characterized in that, The process of building a basic caching architecture and establishing a reference mapping relationship between image cache references and Flutter component Widget instances includes: By building a basic caching architecture, we create a component management layer corresponding to the Widget instance of a Flutter component and a cache management layer corresponding to the image cache reference. Based on the component management layer and the cache management layer, a reference mapping relationship is established between the image cache reference and the Widget instance.

7. A device for clearing image cache based on lifecycle, characterized in that, The device is applied to an electronic device with an application installed, and the electronic device is communicatively connected to a network attached storage device (NETS) and accesses the NETS through the application. The device is used to clear any image cache resources in the electronic device or the NETS; wherein the device includes: A module is created to establish a reference mapping relationship between image cache references and Flutter component Widget instances by building a basic caching architecture; The generation module is used to generate a cache key corresponding to the image loading request when an image loading request is received. The judgment module is used to determine whether the image loading request meets at least one preset cache resource condition based on the cache key corresponding to the image loading request. The display module is used to display the target image corresponding to the image cache resource based on the image cache resource corresponding to the cache key in the memory cache space when the judgment module determines that the image loading request meets at least one of the cache resource conditions; The determination module is used to determine the component lifecycle of the Widget instance of the Flutter component when the judgment module determines that the image loading request does not meet all the cache resource conditions, indicating that the current state of the Flutter component is the abnormal state of the component, and the component lifecycle can be transformed into the cache resource lifecycle of the image cache reference through the reference mapping relationship; The cleanup module is used to perform a cache cleanup operation that matches the current state of the Flutter component if the component lifecycle indicates that the current state of the Flutter component is a preset state. The preset state includes the component destruction state or the component abnormal state.

8. An electronic device, characterized in that, The electronic device includes: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for clearing image cache based on lifecycle as described in any one of claims 1-6.

9. A system for clearing image cache based on lifecycle, characterized in that, The system includes at least the apparatus for cleaning up image cache based on lifecycle as described in claim 7, and a network attached storage device communicatively connected to the apparatus for cleaning up image cache based on lifecycle, wherein the network attached storage device stores image cache resources, and when the apparatus for cleaning up image cache based on lifecycle processes any image cache resource, the apparatus for cleaning up image cache based on lifecycle processes completes the cleaning operation for the image cache resource according to the method for cleaning up image cache based on lifecycle as described in any one of claims 1-6 and based on the image cache resource; Alternatively, the system may include at least the electronic device as described in claim 8, and a network-attached storage device communicatively connected to the electronic device, wherein the network-attached storage device stores image cache resources, and when the electronic device processes any image cache resource, the electronic device performs a cleanup operation on the image cache resource based on the lifecycle-based image cache cleanup method as described in any one of claims 1-6.

10. A computer storage medium, characterized in that, The computer storage medium stores computer instructions, which, when invoked, are used to execute the method for clearing image cache based on lifecycle as described in any one of claims 1-6.