Dynamic image caching method, device, equipment and storage medium

By deploying image cache on the client, using hashing algorithm and file path mechanism to cache and obtain image resources, the problem of low image loading efficiency when refreshing the page is solved, and the user experience and overall request processing efficiency are improved.

CN113849753BActive Publication Date: 2025-03-21PINGAN INT SMART CITY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111137730.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-27
Publication Date
2025-03-21
Estimated Expiration
2041-09-27

AI Technical Summary

Technical Problem

The existing technology requires reloading a large number of images when refreshing the page, resulting in low loading efficiency and poor user experience. Especially under the concurrency limit of the Chrome kernel, if more than 6 requests for the same domain name will be blocked, resulting in the interface being stuck.

Method used

Deploy the image cache on the client, process it separately through the resource request interface and the service request interface, calculate the hash value of the image request using the hash algorithm, determine whether the target image exists in the cache folder, and if it does not exist, it will be obtained and cached from the server side, and provide the target file path to the client.

Benefits of technology

By cached downloaded image resources on the client and using the file path to achieve target image acquisition, the image is avoided reloading every time the page is refreshed, the image calling efficiency is improved, the problem of multiple download requests for refreshing the page is solved, and the overall request processing efficiency and user experience are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113849753B_ABST
    Figure CN113849753B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of artificial intelligence, and discloses a dynamic image caching method, device, equipment and storage medium. The method comprises: receiving a target image acquisition request sent by a user through a resource request interface; calculating a hash value of the target image acquisition request based on a hash algorithm; determining the file name of the target image according to the hash value; judging whether there is a corresponding target image in a preset cache folder of the image cache according to the file name; if not, sending a target image acquisition request to a server, acquiring a target image corresponding to the target image acquisition request, storing the target image in a preset cache folder, generating a target file path corresponding to the storage location of the target image and sending it to a client; if it exists, acquiring the target file path for storing the target image from the hash value and sending it to the client. The present invention can solve the problem of reloading images each time a page is refreshed and the loading efficiency is slow.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a dynamic image caching method, device, equipment and storage medium. Background Art

[0002] Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. This framework allows Web front-end developers to quickly build desktop programs using existing Web frameworks and UI component libraries. It also has the advantage of being cross-platform and can run on desktop operating systems such as Windows, Mac, and Linux, improving efficiency and reusing rich UI components on the Web side.

[0003] At present, many products display many dynamics similar to Moments on their work circle dynamic pages. Each dynamic contains many high-definition pictures. Therefore, the front-end page needs to obtain a large number of large pictures from the back-end for display. Due to the request limit of the Chrome kernel, the maximum concurrent number of requests for the same domain name is limited to 6. When the number of requests for the same domain name exceeds 6 due to the large image resources downloaded from the back-end and the long request time, subsequent requests will be blocked, causing the interface to freeze, and the image resources will be requested again every time the page is refreshed, seriously affecting the normal use of users. The general solution requires the background to separate the domain name of the image resource from the domain name of other interfaces, so that large images can be requested without blocking other requests. However, this solution has the problem of reloading the image every time the page is refreshed and the loading efficiency is slow, affecting the user experience. Summary of the invention

[0004] The present invention provides a dynamic image caching method, device, equipment and storage medium, which can solve the problem of reloading images each time a page is refreshed and the loading efficiency is low.

[0005] In order to solve the above technical problems, a technical solution adopted by the present invention is: to provide a dynamic image caching method, which is applied to an image cache running on a client, wherein the image cache is provided with a resource request interface and a service request interface, and the method comprises:

[0006] Receive a target image acquisition request sent by a user through the resource request interface;

[0007] Calculate the hash value of the target image acquisition request based on a hash algorithm;

[0008] Determine the file name of the target image according to the hash value;

[0009] Determine, according to the file name, whether a corresponding target image exists in a preset cache folder of the image cache;

[0010] If the target image corresponding to the file name does not exist in the preset cache folder, sending the target image acquisition request to the server, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image, and sending the target file path to the client;

[0011] If a target image corresponding to the file name exists in the preset cache folder, a target file path storing the target image is obtained from the hash value and the target file path is sent to the client.

[0012] According to an embodiment of the present invention, if the target image corresponding to the file name does not exist in the preset cache folder, the step of sending the target image acquisition request to the server, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image and sending the target file path to the client also includes:

[0013] When sending the target image acquisition request to the server, the target image acquisition request is stored in a preset resource download list;

[0014] When a new image acquisition request is sent to the server again, determining whether the new image acquisition request already exists in the preset resource download list;

[0015] If so, wait until the target image acquisition request is processed, obtain the target image corresponding to the target image acquisition request, store the target image in the preset cache folder, generate a target file path corresponding to the storage location of the target image, and send the target file path to the client;

[0016] If not, a new image acquisition request is sent to the server and the new image acquisition request is cached in the preset resource download list.

[0017] According to an embodiment of the present invention, the step of waiting for the target image acquisition request to be processed further includes:

[0018] While waiting for the target image acquisition request to be processed, the waiting time is recorded. If the waiting time exceeds a preset time threshold, the target image acquisition request is resent to the server.

[0019] According to an embodiment of the present invention, after the step of resending the target image acquisition request to the server, the method further includes:

[0020] The number of times the request is sent is recorded. If the number of times the request is sent exceeds a preset threshold, the request to obtain the target image is stopped from being sent to the server and download failure information is fed back to the client.

[0021] According to an embodiment of the present invention, after receiving the target image acquisition request sent by the user through the resource request interface, the method further includes:

[0022] Determine whether the target image acquisition request already exists in a preset resource call list, wherein the preset resource call list stores image acquisition requests being processed;

[0023] If yes, after waiting to obtain the target image corresponding to the target image acquisition request, send the target image to the client;

[0024] If not, the target image acquisition request is cached in the preset resource call list, and the target image acquisition request is processed to acquire the corresponding target image.

[0025] According to one embodiment of the present invention, the method further includes:

[0026] The preset cache folder is scanned regularly and a corresponding cleaning operation is performed on the target images stored in the preset cache folder according to the scanning result and the preset strategy.

[0027] According to one embodiment of the present invention, the method further includes:

[0028] receiving a service request sent by the user through the service request interface;

[0029] Forwarding the service request to a server to process the service request;

[0030] The processing result of the server is obtained and sent to the client.

[0031] In order to solve the above technical problems, another technical solution adopted by the present invention is: providing a picture buffer, the picture buffer is arranged on the client, the picture buffer is provided with a resource request interface and a service request interface, and the picture buffer comprises:

[0032] A receiving module, used for receiving a target image acquisition request sent by a user through the resource request interface;

[0033] A calculation module, used to calculate the hash value of the target image acquisition request based on a hash algorithm;

[0034] A determination module, used to determine the file name of the target image according to the hash value;

[0035] A judging module, used for judging whether there is a corresponding target image in a preset cache folder of the image cache according to the file name;

[0036] A first acquisition module is used for sending the target image acquisition request to the server if the target image corresponding to the file name does not exist in the preset cache folder, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image, and sending the target file path to the client;

[0037] The second acquisition module is used to obtain a target file path storing the target image from the hash value and send the target file path to the client if there is a target image corresponding to the file name in the preset cache folder.

[0038] In order to solve the above technical problems, another technical solution adopted by the present invention is: to provide a computer device, including: a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the dynamic image caching method when executing the computer program.

[0039] In order to solve the above technical problem, another technical solution adopted by the present invention is: providing a computer storage medium, on which a computer program is stored, and the computer program implements the above dynamic image caching method when executed by a processor.

[0040] The beneficial effects of the present invention are as follows: by separating the resource request interface and the business request interface on the client side, it is ensured that image resources are obtained from the resource request interface without blocking other business requests, thereby improving the overall request processing efficiency; by deploying an image cache on the client side to cache downloaded image resources and utilizing the file path to achieve target image acquisition, the image call efficiency is improved and the problem of multiple download requests when refreshing the page is solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 is a schematic flow chart of a dynamic picture caching method according to a first embodiment of the present invention;

[0042] Figure 2 is a schematic diagram of a network architecture of a first embodiment of the present invention;

[0043] Figure 3 is a flow chart of step S105 in the dynamic picture caching method according to an embodiment of the present invention;

[0044] Figure 4 is a flow chart of a dynamic picture caching method according to a second embodiment of the present invention;

[0045] Figure 5 is a schematic diagram of a flow chart of a dynamic picture caching method according to a third embodiment of the present invention;

[0046] Figure 6 is a schematic diagram of the structure of a picture buffer according to an embodiment of the present invention;

[0047] Figure 7 is a schematic diagram of the structure of a computer device according to an embodiment of the present invention;

[0048] Figure 8 It is a schematic diagram of the structure of a computer storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION

[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] The terms "first", "second" and "third" in the present invention are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first", "second" and "third" can explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. All directional indications (such as up, down, left, right, front, back...) in the embodiments of the present invention are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication also changes accordingly. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.

[0051] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0052] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0053] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0054] Figure 1 FIG. 1 is a flow chart of a dynamic image caching method according to a first embodiment of the present invention. It should be noted that the method of the present invention is not limited to the method of FIG. 1 if substantially the same results are achieved. Figure 1 The method of the present invention is applied to a picture buffer running on a client, such as Figure 2 As shown, the client 21 interacts with the server 23. The client 21 is provided with an image buffer 210. The image buffer 210 is provided with a resource request interface 211 and a service request interface 212. For the resource request interface 211, as shown in FIG. Figure 1 As shown, the method comprises the steps of:

[0055] Step S101: receiving a target image acquisition request sent by a user through a resource request interface.

[0056] In step S101, the target image acquisition request is in URL format, i.e., Uniform Resource Locator (URL), which is a concise representation of the location and access method of resources that can be obtained from the Internet, and is the address of standard resources on the Internet. Each file on the Internet has a unique URL. The image cache of this embodiment is deployed on the client, and the client of this embodiment can be Electron, and the image cache is .NetCore. Electron is a framework for building desktop applications using JavaScript, HTML and CSS. Through this framework, Web front-end personnel can use existing Web frameworks and UI component libraries to quickly build desktop programs, and have the advantage of cross-platform, can run on desktop operating systems such as Windows, Mac, Linux, etc., improve efficiency and reuse rich UI components on the web side. .Net Core is an open source general development framework that supports cross-platform, that is, supports development and deployment on systems such as Window, MacOS, Linux, etc., and can be used in hardware devices, cloud services, and embedded / Internet of Things solutions.

[0057] Due to the limitation of concurrent number of Chrome kernel in Electron, other requests are blocked and the problem of freezing occurs. The existing backend receives corresponding requests separately from the image resource server and the business interface server, but it cannot completely solve the user experience problem on the client side. This embodiment does not need to modify the backend, and sets the resource request interface and the business request interface on .Net Core. The resource request interface is used to receive image acquisition requests, and the business request interface is used to receive business requests. This implementation separates the image acquisition request and the business request on the client side to prevent the situation where other business requests are blocked due to the need to download image resources from the backend, thereby improving the user experience.

[0058] This embodiment adopts .Net Core hybrid programming, using .Net Core as the middle layer to proxy requests for Electron. Electron and .Net Core share file resources in the PC. All image resources downloaded by .Net Core can be directly obtained in Electron through the file path. .Net Core runs on the client, not on the backend, and is distributed on the backend in contrast to traditional proxy servers. .Net Core in this embodiment facilitates Electron to obtain image resources more quickly and efficiently.

[0059] Step S102: Calculate the hash value of the target image acquisition request based on a hash algorithm.

[0060] In step S102, the hash algorithm maps a binary value of any length to a smaller binary value of a fixed length, wherein the smaller binary value is a hash value. The hash algorithm is a one-way algorithm. In this embodiment, the target image acquisition request URL is converted into a fixed-length output, and different target image acquisition request URLs have different hash values. The hash value can be mapped to the file name of the target image corresponding to the target image acquisition request.

[0061] Step S103: Determine the file name of the target image according to the hash value.

[0062] In step S103, the hash value is mapped to the file name of the target image in the preset cache folder of the image cache. The preset cache folder of this embodiment is used to store all images downloaded from the background by .Net Core, which is convenient for image management and calling. Different hash values ​​correspond to different file names of target images. Specifically, the hash value is mapped to the file name of the target image in the preset cache folder through the file path. The file path is the location where the file is stored. For example, the target image acquisition request URL is: http: / / image.xx.cn / work / 20210826 / logo.jpg. The corresponding hash value obtained according to the hash algorithm is: 59a24db8915f6998f55514aeddeec949049c7b39. If the cache file directory is: d:\imageCache, then the file path of the downloaded and saved target image is: d:\imageCache\59a 24db8915f6998f55514aeddeec949049c7b39.jpg, the file path indicates a JPG format image file "59a24db8915f6998f55514aeddeec949049c7b39", which is stored in the folder "imageCache" of the "d" disk. The file name of the target image is: 59a24db8915f6998f55514aeddeec949049c7b39.jpg. If you want to obtain the target image with the file name "59a24db8915f6998f55514aeddeec949049c7b39.jpg", you need to find this image file level by level according to the file path, and then you can perform the corresponding operation.

[0063] Step S104: judging whether there is a corresponding target image in a preset cache folder of the image cache according to the file name.

[0064] In step S104, the target image is the target image corresponding to the target image acquisition request, because in step S103, the location of the target image to be acquired can be determined according to the file path, but it cannot be determined whether the target image corresponding to the file name is stored in the cache folder. According to the hash value, only the file name of the target image to be pre-acquired can be determined. Therefore, the execution continues to determine whether there is a corresponding target image in the preset cache folder of the image cache according to the file name. In step S104, if there is no target image corresponding to the file name in the preset cache folder, step S105 is executed, and if there is a target image corresponding to the file name in the preset cache folder, step S106 is executed.

[0065] Step S105: If the target image corresponding to the file name does not exist in the preset cache folder, a target image acquisition request is sent to the server, the target image corresponding to the target image acquisition request is acquired, the target image is stored in the preset cache folder, a target file path corresponding to the storage location of the target image is generated, and the target file path is sent to the client.

[0066] In step S105, the server side can be an independent server, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. This embodiment calculates a hash value based on a hash algorithm according to the storage location of the target image, maps the hash value to the target file path where the target image is stored, sends the target file path to the client, and the client obtains the corresponding target image according to the target file path. When the user repeatedly refreshes or sends the image acquisition request URL for obtaining the target image again, the image cache is deployed on the client to cache the downloaded target image, and the target file path is used to obtain the target image, thereby improving the efficiency of image calling and solving the problem of multiple download requests for refreshing the page.

[0067] Furthermore, the present embodiment stores the target images in a preset cache folder, scans the preset cache folder regularly, and performs corresponding cleanup operations on the target images stored in the preset cache folder according to the scan results and the preset strategy. Specifically, the preset strategy includes: 1. Obtaining the last access time of the target image according to the scan results, determining whether the target image is an expired cache file according to the last access time, and performing corresponding cleanup operations when the target image is determined to be an expired cache file; 2. Calculating the total capacity of all target images according to the scan results, and clearing unaccessed target images and expired cache files if the total capacity exceeds the preset capacity threshold. The above method can not only maintain the reading speed of frequently accessed images, but also limit the occupied space, thereby improving the efficiency of image acquisition.

[0068] For further information, see Figure 3 , step S105 further includes the following steps:

[0069] Step S301: When sending a target image acquisition request to a server, the target image acquisition request is stored in a preset resource download list.

[0070] The .Net Core of this embodiment is provided with a preset resource download list, and the preset resource download list stores the image acquisition request being processed.

[0071] Step S302: when a new image acquisition request is sent to the server again, it is determined whether the new image acquisition request already exists in the preset resource download list.

[0072] In step S302, the new image acquisition request is compared with the image acquisition request in the preset resource download list to see if they are the same. If they are the same, it means that a new image acquisition request already exists in the preset resource download list and the new image acquisition request is being processed, then step S303 is executed to refuse to add the new image acquisition request to the preset resource download list to avoid duplicate requests and thus prolong the image loading time; if they are not the same, it means that there is no new image acquisition request in the preset resource download list, then step S304 is executed to add the new image acquisition request to the preset resource download list and wait for the image to be loaded.

[0073] Step S303: If yes, wait until the target image acquisition request is processed, obtain the target image corresponding to the target image acquisition request, store the target image in a preset cache folder, generate a target file path corresponding to the storage location of the target image, and send the target file path to the client;

[0074] In step S303, since the image is large, it often takes a certain amount of time to load the image. However, if the network is normal, the loading of the image can be guaranteed to be completed within the preset time threshold. If the network speed is slow, the loading time may be long. If .Net Core waits for a long time, it may resend the target image acquisition request to reload the image. Furthermore, while waiting for the target image acquisition request to be processed, the waiting time is recorded. If the waiting time exceeds the preset time threshold, the target image acquisition request is resent to the server. The number of times it is sent is recorded. If the number of times it is sent exceeds the preset number threshold, the target image acquisition request is stopped from being sent to the server and the download failure information is fed back to the client.

[0075] Step S304: If not, a new image acquisition request is sent to the server and the new image acquisition request is cached in a preset resource download list.

[0076] Step S106: If a target image corresponding to the file name exists in the preset cache folder, a target file path storing the target image is obtained from the hash value and the target file path is sent to the client.

[0077] In this embodiment, if the target image is stored in a preset cache folder, it can be directly obtained without downloading the target image from the server, which saves resource acquisition time, improves request processing efficiency, and thus improves user experience.

[0078] The dynamic image caching method of the first embodiment of the present invention separates the resource request interface and the service request interface on the client side, thereby ensuring that image resources are obtained from the resource request interface without blocking other service requests, thereby improving the overall request processing efficiency; by deploying an image cache on the client side to cache downloaded image resources and using the file path to achieve target image acquisition, the image calling efficiency is improved and the problem of multiple download requests when refreshing the page is solved.

[0079] Figure 4 FIG. 1 is a flow chart of a dynamic image caching method according to a second embodiment of the present invention. It should be noted that if substantially the same results are achieved, the method of the present invention is not limited to the method of FIG. Figure 4 The method of the present invention is applied to a picture buffer running on a client, such as Figure 2 As shown, the client 21 interacts with the server 23. The client 21 is provided with an image buffer 210. The image buffer 210 is provided with a resource request interface 211 and a service request interface 212. For the resource request interface 211, as shown in FIG. Figure 4 As shown, the method comprises the steps of:

[0080] Step S401: receiving a target image acquisition request sent by a user through a resource request interface.

[0081] In this embodiment, Figure 4 Step S401 and Figure 1 The process is similar to step S101 in , and for the sake of brevity, it will not be repeated here.

[0082] Step S402: determining whether the target image acquisition request already exists in a preset resource call list, wherein the preset resource call list stores image acquisition requests being processed.

[0083] In step S402, Electron may request to obtain the same resource multiple times. If no processing is done, it will lead to multiple downloads of the same resource and download conflicts. Because the image is large, it often takes a certain amount of time to retrieve the image. In addition, due to the slow network speed, the user may have to wait for a long time and may resend the image acquisition request to try to obtain the image. In order to solve the problem of users refreshing and re-requesting to download images, .Net Core is set with a preset resource call list, which can cache the image acquisition request being processed.

[0084] This embodiment compares the target image acquisition request with the image acquisition request in the preset resource call list to see if they are the same. If they are the same, it means that the target image acquisition request already exists in the preset resource call list and the target image acquisition request is being processed, and step S403 is executed to avoid repeated requests and thus prolonging the acquisition time. If they are not the same, it means that the target image acquisition request does not exist in the preset resource call list, and step S404 is executed.

[0085] Step S403: If yes, wait until a target image corresponding to the target image acquisition request is obtained, and then send the target image to the client.

[0086] Step S404: If not, cache the target image acquisition request into a preset resource call list, and process the target image acquisition request to acquire the corresponding target image.

[0087] In step S404, the corresponding target image may be obtained by directly retrieving it from the local file of .Net Core or by downloading it from the server. For specific acquisition methods, please refer to steps S405-S408.

[0088] Step S405: Calculate the hash value of the target image acquisition request based on the hash algorithm.

[0089] In this embodiment, Figure 4 Step S405 and Figure 1 The process is similar to step S102 in , and will not be described again for the sake of brevity.

[0090] Step S406: Determine the file name of the target image according to the hash value.

[0091] In this embodiment, Figure 4 Step S406 and Figure 1 The process is similar to step S103 in , and will not be described again for the sake of brevity.

[0092] Step S407: judging whether there is a corresponding target image in the preset cache folder of the image cache according to the file name.

[0093] In this embodiment, Figure 4 Step S407 and Figure 1 The process is similar to step S104 in , and will not be described again for the sake of brevity.

[0094] Step S408: If the target image corresponding to the file name does not exist in the preset cache folder, a target image acquisition request is sent to the server, the target image corresponding to the target image acquisition request is acquired, the target image is stored in the preset cache folder, a target file path corresponding to the storage location of the target image is generated, and the target file path is sent to the client.

[0095] In this embodiment, Figure 4 Step S408 and Figure 1 The process is similar to step S105 in , and will not be described again for the sake of brevity.

[0096] Step S409: If a target image corresponding to the file name exists in the preset cache folder, a target file path storing the target image is obtained from the hash value and the target file path is sent to the client.

[0097] In this embodiment, Figure 4 Step S409 and Figure 1 The process is similar to step S106 in , and for the sake of brevity, it will not be repeated here.

[0098] The dynamic image caching method of the second embodiment of the present invention is based on the first embodiment. A target image acquisition request being processed can be cached through a preset resource call list. By comparing whether the target image acquisition request is the same as the target image acquisition request in the preset resource call list, different target image acquisition requests are processed, and the same target image acquisition requests are waited for processing, thereby solving the problem of users refreshing and re-requesting to download images.

[0099] Figure 5 FIG. 1 is a flow chart of a dynamic image caching method according to a third embodiment of the present invention. It should be noted that if substantially the same results are achieved, the method of the present invention is not limited to the method of FIG. Figure 5The method of the present invention is applied to a picture buffer running on a client, such as Figure 2 As shown, the client 21 interacts with the server 23. The client 21 is provided with an image buffer 210. The image buffer 210 is provided with a resource request interface 211 and a service request interface 212. For the service request interface 212, as shown in FIG. Figure 5 As shown, the method comprises the steps of:

[0100] Step S501: receiving a service request sent by a user through a service request interface.

[0101] Step S502: forwarding the service request to the server to process the service request.

[0102] Step S503: Obtain the processing result of the server and send it to the client.

[0103] In this embodiment, the request number limit of the Chrome kernel of Electron is 6 for the maximum concurrent number of requests with the same domain name. If .Net Core only provides image request services and no other business request processing is performed, 6 concurrent requests can meet the usage requirements. However, in order to expand the scope of application and compatibility, .Net Core also solves other business problems. Therefore, it is still possible that other business requests may be blocked due to the need to download unbrowsed images from the server. Therefore, .Net Core receives business requests through the business request interface and receives image acquisition requests through the resource request interface, so that the image acquisition process will not affect other business proxy request processing.

[0104] The dynamic image caching method of the third embodiment of the present invention separates the resource request interface and the service request interface on the client side, thereby ensuring that image resources are obtained from the resource request interface without blocking other service requests, thereby improving the overall request processing efficiency.

[0105] Figure 6 is a schematic diagram of the structure of the picture buffer of an embodiment of the present invention. The picture buffer is arranged on the client, such as Figure 6 As shown, the picture buffer 60 includes a receiving module 61, a calculating module 62, a determining module 63, a judging module 64, a first obtaining module 65 and a second obtaining module 66. The picture buffer 50 is provided with a resource request interface and a service request interface.

[0106] The receiving module 61 is used to receive a target image acquisition request sent by a user through a resource request interface;

[0107] The calculation module 62 is used to calculate the hash value of the target image acquisition request based on the hash algorithm;

[0108] The determination module 63 is used to determine the file name of the target image according to the hash value;

[0109] The judging module 64 is used to judge whether there is a corresponding target image in the preset cache folder of the image cache according to the file name;

[0110] The first acquisition module 65 is used to send a target image acquisition request to the server if the target image corresponding to the file name does not exist in the preset cache folder, acquire the target image corresponding to the target image acquisition request, store the target image in the preset cache folder, generate a target file path corresponding to the storage location of the target image, and send the target file path to the client;

[0111] Furthermore, the first acquisition module 65 calculates a hash value based on the storage location of the target image based on a hash algorithm, maps the hash value to a target file path for storing the target image, sends the target file path to the client, and the client obtains the corresponding target image based on the target file path. When the image acquisition request URL for obtaining the target image that is repeatedly refreshed or sent again by the user is obtained, the target image is acquired by deploying an image cache on the client to cache the downloaded target image and using the target file path to obtain the target image, thereby improving the efficiency of image calling and solving the problem of multiple download requests for refreshing the page.

[0112] Furthermore, the present embodiment stores the target images in a preset cache folder, scans the preset cache folder regularly, and performs corresponding cleanup operations on the target images stored in the preset cache folder according to the scan results and the preset strategy. Specifically, the preset strategy includes: 1. Obtaining the last access time of the target image according to the scan results, determining whether the target image is an expired cache file according to the last access time, and performing corresponding cleanup operations when the target image is determined to be an expired cache file; 2. Calculating the total capacity of all target images according to the scan results, and clearing unaccessed target images and expired cache files if the total capacity exceeds the preset capacity threshold. The above method can not only maintain the reading speed of frequently accessed images, but also limit the occupied space, thereby improving the efficiency of image acquisition.

[0113] The second acquisition module 66 is used to obtain the target file path storing the target image from the hash value and send the target file path to the client if there is a target image corresponding to the file name in the preset cache folder.

[0114] See also Figure 7 , Figure 7 FIG. 1 is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. Figure 7 As shown, the computer device 70 includes a processor 71 and a memory 72 coupled to the processor 71 .

[0115] The memory 72 stores program instructions for implementing the dynamic image caching method described in any of the above embodiments.

[0116] The processor 71 is used to execute program instructions stored in the memory 72 to cache dynamic images.

[0117] The processor 71 may also be referred to as a CPU (Central Processing Unit). The processor 71 may be an integrated circuit chip having signal processing capabilities. The processor 71 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0118] See also Figure 8 , Figure 8 Schematic diagram of the structure of the computer storage medium of the embodiment of the present invention. The computer storage medium of the embodiment of the present invention stores a program file 81 that can implement all the above methods, wherein the program file 81 can be stored in the above computer storage medium in the form of a software product, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned computer storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes, or terminal devices such as computers, servers, mobile phones, tablets, etc.

[0119] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0120] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0121] The above are only implementation modes of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A dynamic image caching method, characterized in that: The method is applied to an image buffer running on a client, the image buffer is .Net Core, the image buffer is provided with a resource request interface and a service request interface, the resource request interface is used to receive an image acquisition request, and the service request interface is used to receive a service request, and the method includes: Receive a target image acquisition request sent by a user through the resource request interface; Calculate the hash value of the target image acquisition request based on a hash algorithm; Determine the file name of the target image according to the hash value; Determine, according to the file name, whether a corresponding target image exists in a preset cache folder of the image cache; If the target image corresponding to the file name does not exist in the preset cache folder, sending the target image acquisition request to the server, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image, and sending the target file path to the client; If a target image corresponding to the file name exists in the preset cache folder, obtaining a target file path storing the target image from the hash value and sending the target file path to the client; If the target image corresponding to the file name does not exist in the preset cache folder, the step of sending the target image acquisition request to the server, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image and sending the target file path to the client also includes: When sending the target image acquisition request to the server, the target image acquisition request is stored in a preset resource download list; When a new image acquisition request is sent to the server again, determining whether the new image acquisition request already exists in the preset resource download list; If so, wait until the target image acquisition request is processed, obtain the target image corresponding to the target image acquisition request, store the target image in the preset cache folder, generate a target file path corresponding to the storage location of the target image, and send the target file path to the client; If not, a new image acquisition request is sent to the server and the new image acquisition request is cached in the preset resource download list.

2. The method according to claim 1, characterized in that The step of waiting for the target image acquisition request to be processed also includes: While waiting for the target image acquisition request to be processed, the waiting time is recorded. If the waiting time exceeds a preset time threshold, the target image acquisition request is resent to the server.

3. The method according to claim 2, characterized in that After the step of resending the target image acquisition request to the server, the method further includes: The number of times the request is sent is recorded. If the number of times the request is sent exceeds a preset threshold, the request to obtain the target image is stopped from being sent to the server and download failure information is fed back to the client.

4. The method according to claim 1, characterized in that: After receiving the target image acquisition request sent by the user through the resource request interface, the method further includes: Determine whether the target image acquisition request already exists in a preset resource call list, wherein the preset resource call list stores image acquisition requests being processed; If yes, after waiting to obtain the target image corresponding to the target image acquisition request, send the target image to the client; If not, the target image acquisition request is cached in the preset resource call list, and the target image acquisition request is processed to acquire the corresponding target image.

5. The method according to claim 1, characterized in that The method further comprises: The preset cache folder is scanned regularly and a corresponding cleaning operation is performed on the target images stored in the preset cache folder according to the scanning result and the preset strategy.

6. The method according to claim 1, characterized in that The method further comprises: Receiving a service request sent by the user through the service request interface; Forwarding the service request to a server to process the service request; The processing result of the server is obtained and sent to the client.

7. A picture buffer, the picture buffer being used to implement the steps of the dynamic picture caching method according to any one of claims 1 to 6, characterized in that: The picture buffer is arranged on the client, and the picture buffer is provided with a resource request interface and a service request interface, and the picture buffer comprises: A receiving module, used for receiving a target image acquisition request sent by a user through the resource request interface; A calculation module, used to calculate the hash value of the target image acquisition request based on a hash algorithm; A determination module, used to determine the file name of the target image according to the hash value; A judging module, used for judging whether there is a corresponding target image in a preset cache folder of the image cache according to the file name; A first acquisition module is used for sending the target image acquisition request to the server if the target image corresponding to the file name does not exist in the preset cache folder, acquiring the target image corresponding to the target image acquisition request, storing the target image in the preset cache folder, generating a target file path corresponding to the storage location of the target image, and sending the target file path to the client; The second acquisition module is used to obtain a target file path storing the target image from the hash value and send the target file path to the client if there is a target image corresponding to the file name in the preset cache folder.

8. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the dynamic image caching method according to any one of claims 1 to 6 when executing the computer program.

9. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the dynamic image caching method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Interface request processing method and device, computer equipment and storage medium

    CN109842610A

  • Intelligent picture loading method and device for terminal and electronic equipment

    CN111597479A