Picture caching and refreshing method and device, storage medium and equipment
By intercepting image request interfaces through a proxy and using an indexed database for cache lookup and dynamic probability refresh determination, the problem that the browser's native caching mechanism cannot effectively cache asynchronous request objects and image constructors is solved. This achieves efficient loading of image resources and data timeliness, thus improving the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 湖北省楚天云有限公司
- Filing Date
- 2025-12-30
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, the browser's native caching mechanism cannot effectively cache image resource requests initiated through asynchronous request objects and image constructors, resulting in frequent network requests that affect loading speed and user experience.
By intercepting image request interfaces through a proxy, using an indexed database for cached queries and data access, and combining dynamic probability refresh determination based on access frequency, the system ensures asynchronous updates when the cache is hit, achieving a balance between data timeliness and loading speed.
While improving loading speed, it maintains data timeliness, significantly improving user experience, especially when the network is unstable or the server load is high, both cache hit rate and loading speed are significantly improved.
Smart Images

Figure CN121880671A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, storage medium, and device for image caching and refreshing. Background Technology
[0002] In common map-based web applications, developers typically use front-end frameworks such as OpenLayers, MapBox, and CesiumJS for 2D or 3D map rendering, often combining ThreeJS and WebGL (Web Graphics Library) to achieve advanced visual effects. In these interaction-intensive applications, user experience is primarily limited by the performance of the user's terminal hardware (such as CPU / GPU processing power) and the loading efficiency of tile map images. Summary of the Invention
[0003] To ensure that caching improves speed while maintaining data timeliness, this invention provides an image caching and refresh method. The method intercepts image request interfaces through a proxy, performs cache queries and data access based on an indexed database, and introduces dynamic probability refresh judgment and processing based on access frequency. The method intelligently evaluates and updates cached data asynchronously each time it is returned, thus balancing loading speed and data timeliness.
[0004] As one aspect of the present invention, embodiments of the present invention provide an image caching and refreshing method, including:
[0005] The application interface that initiates the image resource request is intercepted by a proxy. The application interface includes at least an asynchronous request object and an image constructor.
[0006] When the application interface intercepted by the proxy is called, data retrieval and return operations are performed based on the cached query results of the indexed database. The indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks.
[0007] If the requested image resource already exists in the indexed database, then for the image resource, a dynamic probability refresh determination and processing based on access frequency is performed, wherein discarding the currently cached image resource corresponds to a refresh determination, and not discarding the currently cached image resource corresponds to a no-refresh determination.
[0008] As another aspect of the present invention, embodiments of the present invention provide an image caching and refreshing device, comprising:
[0009] The proxy interception module is used to intercept the application interface that initiates the image resource request. The application interface includes at least an asynchronous request object and an image constructor.
[0010] The cache management module is used to perform the following data retrieval and return operations based on the cache query results of the indexed database when the application interface intercepted by the proxy is called. The indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks.
[0011] If the requested image resource already exists in the indexed database, the corresponding binary data block is retrieved from it and returned to the caller. Based on the access information of the image resource recorded in the indexed database, a dynamic refresh determination is performed. If it is determined that a refresh is required, the image resource in the indexed database is cleared.
[0012] If the requested image resource does not exist in the indexed database, a request to obtain the image resource from the network is allowed.
[0013] As another aspect of the present invention, embodiments of the present invention provide a computer-readable storage medium storing a computer program that performs the image caching and refreshing method as described above.
[0014] As another aspect of the present invention, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image caching and refreshing method as described above.
[0015] The beneficial effects of the above-described technical solutions provided in the embodiments of the present invention include at least the following:
[0016] This invention provides an image caching and refresh method. By proxying and intercepting the application interface (including asynchronous request objects and image constructors) that initiates image resource requests, and using an indexed database as a unified local caching medium, it ensures that all requests can be captured, and performs data retrieval and return operations through cache queries of the indexed database. This solves the technical defect that the browser's native cache cannot cover asynchronous request object requests and dynamically created image constructor object requests.
[0017] The image caching and refresh method provided in this embodiment of the invention, after confirming that the result of the data acquisition and return operation is a return from the cache, triggers dynamic probability refresh judgment and processing based on access frequency, ensuring that each time the cache is hit, an asynchronous update is initiated in the background with probability, thus making full use of the cache to improve speed while maintaining the timeliness of the data.
[0018] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.
[0019] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0020] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0021] Figure 1 This is a flowchart of the image caching and refresh method in an embodiment of the present invention;
[0022] Figure 2 This is a diagram illustrating the data related to loading homepage data without applying image caching and refresh methods.
[0023] Figure 3 A diagram illustrating data related to loading homepage application image caching and refresh methods;
[0024] Figure 4 This is a schematic diagram of the image caching and refreshing device in an embodiment of the present invention. Detailed Implementation
[0025] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0026] In existing technologies, tile image requests are typically not handled specifically; instead, the browser's own caching mechanism for static resources is used for temporary storage of some images. This approach has significant drawbacks: firstly, for image requests initiated via XMLHttpRequest (XHR, a browser asynchronous request technology), the browser's default caching strategy often fails to effectively cache the response content; secondly, image resources loaded by image objects dynamically created using `new Image()` in JavaScript code cannot be captured by ordinary caching mechanisms, leading to repeated network requests. This results in a large amount of image data that could be reused locally still needing to be frequently retrieved from the server, increasing the network load, slowing down loading speed, and significantly degrading the user experience, especially when the network is unstable or the server load is high.
[0027] Through research and practice, the inventors discovered that in typical application scenarios such as smart communities, user access behavior to map areas exhibits clear patterns and localization. Specifically, most access is concentrated in a few fixed areas, and there is a potential correlation between access frequency and the likelihood of data updates. Based on the observation that "high-frequency accessed tile content is likely to be updated more frequently, while the effectiveness of cached content that has not been accessed for a long time decreases over time," and combining the indexed database (IndexedDB) provided by modern browsers with JavaScript proxy interception capabilities, the inventors designed a unified image caching and intelligent update scheme. The core of this scheme lies in the unified interception and management of image request interfaces through a proxy layer, and the introduction of a dynamic probability refresh algorithm. This ensures cache utilization while intelligently maintaining data freshness, achieving an effective balance between performance and timeliness.
[0028] It should be noted that the executing entity of each embodiment of this application can be a computing service system with data processing, network communication, and program execution functions, such as an electronic system capable of implementing the above functions, an image caching and refresh system, etc. The following description uses an image caching and refresh system (hereinafter referred to as "the system") as an example to illustrate the following embodiments.
[0029] Example 1
[0030] Reference Figure 1 As shown, this embodiment of the invention provides an image caching and refreshing method, including:
[0031] S10: Intercept the application interface that initiates the image resource request by proxy. The application interface includes at least an asynchronous request object and an image constructor.
[0032] S20: When the application interface intercepted by the proxy is called, the following data retrieval and return operations are performed based on the cached query results of the indexed database, wherein the indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks:
[0033] If the requested image resource already exists in the indexed database, the corresponding binary data block is retrieved from it and returned to the caller. Based on the access information of the image resource recorded in the indexed database, a dynamic refresh determination is performed. If it is determined that a refresh is required, the image resource in the indexed database is cleared.
[0034] If the requested image resource does not exist in the indexed database, a request to obtain the image resource from the network is allowed.
[0035] This invention addresses the problem that existing browser native caching mechanisms cannot effectively cache image resource requests initiated through asynchronous request objects and image constructors, and solves this problem collaboratively through the following methods:
[0036] First, by intercepting and proxying the application interfaces (including asynchronous request objects and image constructors) that initiate image resource requests, a unified processing entry point is created, overcoming the fundamental flaw of existing technologies that rely on the browser itself and cannot intervene in specific request flows. The proxy mechanism allows the request behavior of both asynchronous requests and dynamically created image instances to be captured and customized.
[0037] Upon intercepting a request, the system performs data retrieval and return operations based on the cached results of an indexed database. This utilizes the indexed database as a unified, programmable local caching medium, replacing the browser's native, uncontrollable caching strategy. Regardless of the proxy API from which the request originates, the system queries this database to determine if the resource exists. If it exists (i.e., a cache hit), the system retrieves and returns the data from that database; otherwise, it redirects to the network and ultimately stores the result in the database, ensuring that all types of image resource requests are included in the same manageable caching system.
[0038] To address the issue of data freshness after a cache hit, this invention designs a mechanism whereby if the result of the data acquisition and return operation is a cached image resource returned from the indexed database, a dynamic probability refresh judgment and processing based on access frequency is performed on the returned image resource. This ensures that an evaluation mechanism is triggered each time data is returned from the cache, dynamically determining whether an asynchronous update is needed in the background based on the access frequency of the resource. This solves the drawback of potentially outdated cached data under traditional fixed expiration strategies or no-update strategies, achieving the goal of improving loading speed while maintaining data timeliness.
[0039] In this embodiment of the invention, step S10 may specifically include: when the application interface that initiates the image resource request is an image constructor, performing proxy interception when creating an image instance and intercepting the assignment operation of the image instance source address attribute.
[0040] The described step S20 may specifically include steps S201 to S203:
[0041] S201: If the constructor of the image being intercepted by the proxy is called, then when setting the source address, it is determined whether the requested image resource exists in the indexed database, and the cached query result is obtained;
[0042] S202: If the cache query result exists, then obtain the corresponding binary data block from the indexed database, convert the binary data block into a local object address that can be recognized by the browser, and assign the local object address to the source address attribute of the image instance;
[0043] S203: If the cache query result is not found, a network request is allowed to be initiated at the original address, and after the image is loaded, the image data is converted into binary data blocks and stored in the indexed database.
[0044] Specifically, when the image constructor (such as "new Image()") intercepted by the proxy mechanism is called, the system triggers the interception logic when assigning a value to the source address ("src") attribute of the generated image instance. The interceptor extracts the source address to be assigned (i.e., the image URL) and uses it as the key to query IndexedDB to determine whether the requested image resource already exists in the local cache, obtaining a clear cache query result (existence or non-existence). By intercepting at the image object attribute setting level, the capture and cache determination of dynamic image loading behavior are achieved.
[0045] The system performs differentiated operations based on the query results: If the cache exists, the corresponding binary data block (Blob) is read directly from IndexedDB, converted into a browser-loadable local object address (Blob URL) using the "URL.createObjectURL()" method, and assigned to the "src" attribute of the image instance, thus loading directly from the local machine without a network request; if the cache does not exist, the original remote address is assigned to the "src" attribute to initiate a normal network request; after the image is loaded from the network, the system draws it onto the Canvas and calls the "toBlob()" method to convert the rendered data into a binary data block, and finally stores this data block and its corresponding source address as key-value pairs in the indexed database, completing the cache backfilling.
[0046] For example, for requests initiated by XHR, the native XMLHttpRequest object can be proxied using ajax-hook, which intercepts the request when it is initiated. If the request content exists in the local cache, the response content in the local cache is returned directly. If the request content does not exist in the local cache, the response content is written to the local cache when the request is completed.
[0047] For image requests initiated by `new Image()`, the constructor function of `Image` is intercepted using ES6 Proxy. An `Image` instance is created within the constructor, and `Object.defineProperty` is used to intercept the `setsrc` operation of the `Image` instance. During `setsrc`, it first checks if the requested image is in the local cache. If it is, the Blob object is retrieved from the cache, a blob URL is created using `URL.createObjectURL`, and the blob URL is assigned to the `src` property of the `Image` instance, thus avoiding a remote network request. If the requested image is not in the local cache, the `load` listener callback function added to the `Image` instance draws the `Image` instance onto a canvas, then converts the canvas to a Blob object and writes it to the local cache.
[0048] The code that intercepts the Image constructor is as follows:
[0049] / / Save the original Image constructor
[0050] const OriginalImage = window.Image
[0051] / / Create a Proxy for the Image constructor
[0052] window.Image = new Proxy(OriginalImage, {
[0053] construct(target, args) {
[0054] / / Create the original Image instance
[0055] const img = new target(...args)
[0056] / / Create a proxy for the Image instance
[0057] const imgProxy = new Proxy(img, {
[0058] set(target, prop, value) {
[0059] let src: string | undefined
[0060] const handle = async () => {
[0061] / / Intercept src attribute settings
[0062] if (prop === 'src') {
[0063] const srcUrl = value
[0064] src = srcUrl
[0065] const cachedBlob: Blob | null = await cache.getItem(srcUrl)
[0066] if (isNotNull(cachedBlob)) {
[0067] / / Create ObjectURL
[0068] const objectURL = URL.createObjectURL(cachedBlob)
[0069] / / Set src to ObjectURL
[0070] target.src = objectURL
[0071] } else {
[0072] target.src = srcUrl
[0073] }
[0074] } else if (prop === 'onload') {
[0075] if (typeof value === 'function') {
[0076] / / Rewrite onload and add caching logic
[0077] target.onload = function () {
[0078] try {
[0079] const canvas = document.createElement('canvas')
[0080] canvas.width = img.width
[0081] canvas.height = img.height
[0082] const ctx = canvas.getContext('2d')
[0083] ctx!.drawImage(img, 0, 0)
[0084] / / Convert to Blob and cache
[0085] canvas.toBlob(async (blob) => {
[0086] if (blob) {
[0087] if (src) {
[0088] await cache.setItem(src, blob)
[0089] }
[0090] }
[0091] / / Call user callback
[0092] value.call(imgProxy)
[0093] })
[0094] } catch {
[0095] value.call(imgProxy)
[0096] }
[0097] }
[0098] } else {
[0099] target.onload = null
[0100] }
[0101] } else {
[0102] img[prop] = value
[0103] }
[0104] }
[0105] handle()
[0106] return true
[0107] }
[0108] })
[0109] return imgProxy
[0110] }
[0111] })”
[0112] In this embodiment of the invention, step S20 may further include steps A201 to A203:
[0113] A201: When the asynchronous request object intercepted by the proxy is invoked, it is determined whether the requested image resource exists in the indexed database and the cached query result is obtained;
[0114] A202: If the cache query result exists, return the response content from the local cache;
[0115] A203: If the cache query result does not exist, the request is allowed to be initiated normally, and the response content is written to the indexed database when the request is completed.
[0116] Specifically, when an asynchronous request object intercepted by the proxy mechanism initiates a call, the system first extracts the request identifier (such as the URL) and uses it as the key to query IndexedDB. The purpose of this operation is to determine whether a valid local cached copy of the requested image resource already exists, thereby obtaining a clear cache query result (existence or non-existence). This step inserts cache judgment logic before the network request is actually sent through proxy technology.
[0117] The system performs differentiated operations based on the query results: If the cache exists, it directly reads the stored response content (usually a binary data block) from IndexedDB and returns it to the application as the response result of this request. This process is completed entirely locally without initiating an actual network request. If the cache does not exist, the proxied asynchronous request object is allowed to continue its original process and make a normal request to the network. After the request is completed and the server response is obtained, the system writes the response content (image resources and their binary data) to IndexedDB and creates a new cache entry for use by subsequent requests.
[0118] In this embodiment of the invention, the dynamic refresh determination based on the access information recorded in the indexed database of the image resource may specifically include the following steps:
[0119] Use count values are associated with existing image resources in the indexed database, and a global maximum usage threshold is preset.
[0120] Based on the current usage count of the image resource and the maximum usage threshold, calculate the probability value of this request triggering a cache refresh;
[0121] A random decision is made based on the probability value to determine whether the currently cached image resource should be discarded.
[0122] If it is determined to be a refresh, then the image resources are cleared, the latest image data is retrieved from the network again and cached, and the corresponding usage count value is reset to the initial value.
[0123] If it is determined that no refresh is needed, the current cache will continue to be used, and the corresponding usage count value will be increased by a preset value.
[0124] Specifically, each image resource stored in IndexedDB maintains a dynamic usage count and sets a globally unified maximum usage threshold as the basis for probability calculation. When a request confirms a cache hit, the system calculates the probability of triggering a cache update in real time based on the ratio of the resource's current usage count to the preset threshold. This step establishes a direct mathematical relationship between access frequency and refresh probability, making frequently accessed resources more likely to be updated.
[0125] The system performs a random judgment based on calculated probability values to determine whether to discard currently cached image resources. If the judgment is to refresh, it clears the old data, retrieves new data from the network, and caches it again, while resetting the usage count associated with the resource to its initial value. If the judgment is not to refresh, it continues to return the existing cached data and increments its usage count by a preset value. This mechanism achieves dynamic and automated cache update decisions through the linkage between probabilistic judgment and the counting status.
[0126] For example, in a smart community, since the map service refreshes periodically, a cache refresh mechanism needs to be implemented, and this mechanism should be imperceptible to users. When an image request is intercepted, if the refresh algorithm indicates that the cache needs to be refreshed, it is only necessary to clear the local cache for that request. Then, the browser initiates the actual request to retrieve the new image content and caches it in the local IndexedDB. Since the users of the smart community application are mainly grid workers / community administrators, based on their daily usage, most users access relatively fixed map areas. Therefore, the more frequently a user accesses the map, the higher the probability of a refresh should be, and vice versa. The cache refresh algorithm is as follows:
[0127] 1. Set a global image cache maximum usage threshold, denoted as MAX_USE_COUNT;
[0128] 2. When caching image requests, simultaneously record the number of times the cache is used, denoted as CURRENT_USE_COUNT. If the request does not exist in the cache, the usage count is recorded as 1 when writing to the cache. If it exists in the cache, calculate the probability of the cache being refreshed as P = CURRENT_USE_COUNT / MAX_USE_COUNT. Use Math.random() < P to determine whether to refresh the cache. If refreshed, reset the usage count to 1; otherwise, increment the usage count by 1.
[0129] In this embodiment of the invention, before performing a random determination based on the probability value to determine whether to discard the currently cached image resource, the specific steps may include:
[0130] Obtain the last access timestamp of the image resource in the indexed database, and determine the time interval between the last access timestamp and the current time;
[0131] According to a preset nonlinear mapping relationship, the interval duration is converted into a time decay factor between 0 and 1, wherein the longer the interval duration, the closer the time decay factor is to 1;
[0132] The probability value is weighted and fused with the time decay factor to generate the final probability value used for random determination.
[0133] Specifically, the system maintains a last access timestamp for each cached image resource in IndexedDB. When a refresh is triggered, the system calculates the interval between the current time and that timestamp, thus quantifying the length of time the resource has not been accessed. Using a pre-defined non-linear mapping function, this continuous time interval is converted into a scalar value between 0 and 1, namely the time decay factor. This mapping relationship is designed such that the shorter the interval, the closer the decay factor is to 0; the longer the interval, the closer the decay factor is to 1.
[0134] The original refresh probability value calculated based on the access frequency is weighted and fused with the aforementioned time decay factor. This operation essentially combines the access frequency (frequency factor) and the time since the last access (time factor) mathematically to generate a comprehensive refresh probability value used for random determination. This ensures that the final determination not only depends on the access frequency of the resource but also incorporates the effect of time decay. Even if a resource has not been accessed for a long time and its initial frequency is low, its refresh probability will increase due to the increase in the time factor.
[0135] In this embodiment of the invention, the method of converting the interval duration into a time decay factor between 0 and 1 based on a preset nonlinear mapping relationship may specifically include:
[0136] Set the baseline time window and saturation time threshold;
[0137] According to the preset nonlinear mapping relationship, if the interval duration is less than or equal to the reference time window, then the preset lower limit value greater than 0 is determined as the time decay factor.
[0138] If the interval duration is greater than or equal to the saturation time threshold, then the time decay factor is determined to be 1;
[0139] If the interval duration is between the reference time window and the saturation time threshold, then according to a monotonically increasing function, the interval duration is mapped to a time decay factor between the preset lower limit and 1.
[0140] Specifically, the system pre-sets a baseline time window and a saturation time threshold. When the calculated access interval is less than or equal to the baseline time window, it indicates that the resource has been accessed recently. The system directly determines a preset lower limit value (such as 0.1) greater than zero as the time decay factor. That is, for recently accessed resources, the impact of the time dimension on their refresh probability is suppressed to a very low level, and their cache effectiveness is still mainly dominated by the access frequency.
[0141] If the access interval is greater than or equal to the saturation time threshold, it indicates that the resource has been idle for a long time, and the system directly sets the time decay factor to 1, which is the maximum impact value. For resources whose interval is between the baseline time window and the saturation time threshold, the system uses a preset monotonically increasing function (such as an exponential function, logarithmic function, or piecewise linear function) to smoothly map the continuously changing time interval to a dynamic decay factor between a preset lower limit and 1.
[0142] Combination Figure 2 and Figure 3 ( Figure 2 This is a diagram illustrating the data related to loading homepage data without applying image caching and refresh methods. Figure 3 The performance comparison data (illustrated as a diagram of data related to image caching and refresh methods for loading the homepage) shows that applying image caching and refresh methods significantly improves the smoothness of homepage loading. The most prominent improvement is in the loading efficiency of tile images: the average loading time has been drastically reduced from 400–600ms to approximately 1ms, an improvement of several hundred times.
[0143] This data comes from the browser developer tools' network panel, calculated by averaging the total loading time of multiple requests. Before optimization, loading each tile image required a network request, data transmission, and rendering, taking hundreds of milliseconds, which easily led to page rendering blockage and visual stuttering. After optimization, thanks to local caching and intelligent refresh mechanisms, most images can be read directly from the cache, achieving almost instant loading with an average time of only about 1ms. This not only significantly shortens the presentation time of homepage content but also significantly improves the user's interactive experience, making page scrolling and visual transitions smoother and more natural, transforming what was originally a perceptible wait into a near-instantaneous response.
[0144] Example 2
[0145] Based on the same inventive concept, embodiments of the present invention also provide an image caching and refreshing device, such as... Figure 4 As shown, it includes:
[0146] Proxy interception module 10 is used to intercept the application interface that initiates the image resource request. The application interface includes at least an asynchronous request object and an image constructor.
[0147] The cache management module 20 is used to perform the following data retrieval and return operations based on the cache query results of the indexed database when the application interface intercepted by the proxy is called. The indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks.
[0148] If the requested image resource already exists in the indexed database, the corresponding binary data block is retrieved from it and returned to the caller. Based on the access information of the image resource recorded in the indexed database, a dynamic refresh determination is performed. If it is determined that a refresh is required, the image resource in the indexed database is cleared.
[0149] If the requested image resource does not exist in the indexed database, a request to obtain the image resource from the network is allowed.
[0150] In this embodiment of the invention, the image caching and refreshing device is a device corresponding to the image caching and refreshing method provided in Embodiment 1. Its specific implementation can be referred to the detailed description of the image caching and refreshing method in Embodiment 1. In this embodiment of the invention, it will not be repeated here.
[0151] Example 3
[0152] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer program that performs the image caching and refreshing method as described in Embodiment 1.
[0153] Example 4
[0154] Based on the same inventive concept, this embodiment of the invention also provides an image caching and refreshing device, including the image caching and refreshing method described in Embodiment 1 above.
[0155] The principles by which the above-described apparatus, client, medium, related equipment and system in this embodiment of the invention solve the problem are similar to those of the aforementioned method. Therefore, their implementation can refer to the implementation of the aforementioned method, and repeated details will not be repeated.
[0156] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0157] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0158] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0159] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1The steps of the function specified in one or more boxes.
[0160] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of equivalents of this invention, this invention is also intended to include these modifications and variations.
Claims
1. A picture buffering and refresh method, characterized by, include: The application interface that initiates the image resource request is intercepted by a proxy. The application interface includes at least an asynchronous request object and an image constructor. When the application interface intercepted by the proxy is invoked, the following data retrieval and return operations are performed based on the cached query results of the indexed database, wherein the indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks: If the requested image resource already exists in the indexed database, the corresponding binary data block is retrieved from it and returned to the caller. Based on the access information of the image resource recorded in the indexed database, a dynamic refresh determination is performed. If it is determined that a refresh is required, the image resource in the indexed database is cleared. If the requested image resource does not exist in the indexed database, a request to obtain the image resource from the network is allowed.
2. The picture buffering and refresh method of claim 1, wherein, The step of performing dynamic refresh determination based on the access information recorded in the indexed database of the image resources includes: Use count values are associated with existing image resources in the indexed database, and a global maximum usage threshold is preset. Based on the current usage count of the image resource and the maximum usage threshold, calculate the probability value of this request triggering a cache refresh; A random decision is made based on the probability value to determine whether the currently cached image resource should be discarded. If it is determined to be a refresh, then the image resources are cleared, the latest image data is retrieved from the network again and cached, and the corresponding usage count value is reset to the initial value. If it is determined that no refresh is needed, the current cache will continue to be used, and the corresponding usage count value will be increased by a preset value.
3. The picture buffering and refresh method of claim 1, wherein, When the application interface intercepted by the proxy is invoked, data retrieval and return operations are performed based on the cached query results of the indexed database, including: When the asynchronous request object intercepted by the proxy is invoked, it is determined whether the requested image resource exists in the indexed database and the cached query result is obtained. If the cache query result exists, the response content in the local cache is returned; If the cache query result does not exist, the request is allowed to be initiated normally, and the response content is written to the indexed database when the request is completed.
4. The picture buffering and refresh method of claim 1, wherein, When the application interface intercepted by the proxy is invoked, data retrieval and return operations are performed based on the cached query results of the indexed database, including: If the constructor of the image being intercepted by the proxy is called, then when setting the source address, it is determined whether the requested image resource exists in the indexed database, and the cached query result is obtained; If the cache query result exists, the corresponding binary data block is obtained from the indexed database, the binary data block is converted into a local object address that can be recognized by the browser, and the local object address is assigned to the source address attribute of the image instance. If the cache query result is not found, a network request is allowed to be initiated at the original address, and after the image is loaded, the image data is converted into binary data blocks and stored in the indexed database.
5. The picture buffering and refresh method of claim 1, wherein, The method of intercepting the application interface that initiates the image resource request includes: When the application interface that initiates the image resource request is the image constructor, a proxy interception is performed when the image instance is created, and the assignment operation of the image instance source address attribute is also intercepted.
6. The picture buffering and refresh method of claim 2, wherein, Before performing a random determination based on the probability value to determine whether to discard the currently cached image resource, the method further includes: Obtain the last access timestamp of the image resource in the indexed database, and determine the time interval between the last access timestamp and the current time; According to a preset nonlinear mapping relationship, the interval duration is converted into a time decay factor between 0 and 1, wherein the longer the interval duration, the closer the time decay factor is to 1; The probability value is weighted and fused with the time decay factor to generate the final probability value used for random determination.
7. The picture buffering and refresh method according to claim 6, wherein, The step of converting the interval duration into a time decay factor between 0 and 1 according to a preset nonlinear mapping relationship includes: Set the baseline time window and saturation time threshold; According to the preset nonlinear mapping relationship, if the interval duration is less than or equal to the reference time window, then the preset lower limit value greater than 0 is determined as the time decay factor. If the interval duration is greater than or equal to the saturation time threshold, then the time decay factor is set to 1; If the interval duration is between the reference time window and the saturation time threshold, then according to a monotonically increasing function, the interval duration is mapped to a time decay factor between the preset lower limit and 1.
8. An image caching and refreshing device, characterized in that, include: The proxy interception module is used to intercept the application interface that initiates the image resource request. The application interface includes at least an asynchronous request object and an image constructor. The cache management module is used to perform the following data retrieval and return operations based on the cache query results of the indexed database when the application interface intercepted by the proxy is called. The indexed database serves as a local cache medium for storing image resources and corresponding binary data blocks. If the requested image resource already exists in the indexed database, the corresponding binary data block is retrieved from it and returned to the caller. Based on the access information of the image resource recorded in the indexed database, a dynamic refresh determination is performed. If it is determined that a refresh is required, the image resource in the indexed database is cleared. If the requested image resource does not exist in the indexed database, a request to obtain the image resource from the network is allowed.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the image caching and refreshing method as described in any one of claims 1 to 7.
10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the image caching and refreshing method as described in any one of claims 1 to 7.