Method and System for Updating Client Cache

A caching management module with version control ensures timely cache updates for static resources by sending verification requests to the server, addressing the challenges of file renaming and frequent deployments in existing caching strategies, ensuring browser resources are always up-to-date.

CN111475180BActive Publication Date: 2025-07-15BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201910068527.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-01-24
Publication Date
2025-07-15
Estimated Expiration
2039-01-24

AI Technical Summary

Technical Problem

In the prior art, the browser cache update method has the problem that it cannot be updated in time, especially when the file name is not modified and the short cache time is not set, it is impossible to ensure that the client obtains the latest resource file.

Method used

The cache management module Service Worker is introduced to control and update the cache on the client. By recording the version identification in the resource file and sending an update verification request every time it is executed, the server compares the version identification to determine whether to update. If it is updated, it requests the latest resource file.

Benefits of technology

It realizes timely update of caches, without modifying the resource file name and setting a short cache time, ensuring that the resource file obtained by the browser is the latest version, avoiding the problem of untimely update of resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111475180B_ABST
    Figure CN111475180B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for updating a client cache, which relates to the field of computer technology. A specific embodiment of the method includes: the browser registers and installs a cache management module for a page that has not registered the cache management module according to a page access request; the cache management module searches for the requested resource file in the cache according to the page access request, and executes the resource file to send an update verification request to the server, and the update verification request includes the version identifier of the resource file; the server verifies whether the resource file has been updated according to the version identifier, and returns the verification result to the cache management module; the cache management module makes a judgment according to the verification result. If the resource file has been updated, the cache management module is updated to request the latest resource file from the server and update the resource file in the cache. This embodiment can achieve timely update of the cache without modifying the file name of the resource file or setting a very short cache time for the resource file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technologies, and in particular, to a method and a system for updating a client cache. Background Art

[0002] Browser cache refers to the browser using the cache mechanism of the HTTP (HyperText Transfer Protocol) protocol to store the requested resource files (such as JavaScript script files, CSS cascading style sheet files, and image files, etc.) on the client side locally. When the next request arrives, the browser can directly load the resource that meets the cache conditions from the client side locally.

[0003] One of the problems brought by caching is how to update the cache. For the two common caching strategies, the problem with forced caching is that during the period when the cache has not expired, if the resources on the server are updated, the client cannot be notified in time, and the browser cache cannot be updated in time; the conditional cache requests the server for update information every time, which can update the cache in time, but the frequent requests reduce the resource loading speed and sacrifice performance. In order to ensure the timely update of the cache and maximize the network performance, the non-overwriting publishing method is generally adopted to update the cache. For HTML page files, the conditional cache strategy is adopted to ensure communication with the server and update in time; for the static resource files in the page (such as JavaScript script files, CSS cascading style sheet files, and image files, etc.), forced caching is used. When the static resource file is published and updated, the file name is renamed, and a new file is published online (without overwriting the old version file), and the resource path referenced in the HTML page is modified. In this way, when the user requests the page, if the referenced static resource is updated, a new resource will be requested, and the cache will be updated in time, so that developers can set a relatively long forced cache for static resources.

[0004] However, in the process of implementing the present invention, the inventor found that there are at least the following problems in the prior art:

[0005] 1. Implementing cache update by changing the file name is not suitable for all files:

[0006] (1) Some third-party static resource files are referenced by many developers. Updating by modifying the file name cannot ensure that all developers are aware of it, which is very inconvenient. Usually, the cache strategy for third-party scripts is to use forced caching and set a relatively short expiration time so as to update the cache in time. However, this method also cannot ensure that after the server file is updated, the client will definitely request the latest resource the next time;

[0007] (2)For blog websites, users generally cannot modify the page source code, so they cannot update the cache by updating the resource file name.

[0008] 2. If static resource files are updated frequently, HTML page files must also be published frequently. The current mainstream development method is to separate the front end and the back end. HTML page files and static files are usually deployed on different servers. Each time both sides need to be deployed, increasing the deployment cost. Summary of the Invention

[0009] In view of this, embodiments of the present invention provide a method and a system for updating a client cache, which can manage and update cache files on the client side. Without modifying the file name of the resource file and without setting a very short cache time for the resource file, timely update of the cache can be achieved, so as to ensure that the resource files of the user request page obtained by the browser each time are the latest versions.

[0010] To achieve the above object, according to one aspect of the embodiments of the present invention, a method for updating a client cache is provided.

[0011] A method for updating a client cache includes: the browser registers and installs a cache management module for a page that has not registered a cache management module according to a page access request; the cache management module searches for a requested resource file in the cache according to the page access request, and executes the resource file to send an update verification request to the server, where the update verification request includes a version identifier of the resource file; the server verifies whether the resource file has been updated according to the version identifier, and returns a verification result to the cache management module; the cache management module makes a judgment according to the verification result. If the resource file has been updated, the cache management module is updated to request the latest resource file from the server, and the resource file in the cache is updated.

[0012] Optionally, it further includes: setting the cache policy of the update verification request to never cache, so that the update verification request is sent each time the resource file is executed.

[0013] Optionally, it further includes: if the cache management module does not find the resource file in the cache, directly request the resource file from the server.

[0014] Optionally, updating the cache management module to request the latest resource file from the server includes: triggering the browser to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server.

[0015] Optionally, it further includes: setting the cache policy of the requests during the installation process by the cache management module to never cache, so that the requests during the installation process are directly sent to the server.

[0016] Optionally, the cache management module is a Service Worker.

[0017] According to another aspect of the embodiments of the present invention, a system for updating the client cache is provided.

[0018] A system for updating the client cache includes: a browser, a cache management module, and a server. Among them, the browser is used to register and install the cache management module for the page that has not registered the cache management module according to the page access request; the cache management module is used to find the requested resource file from the cache according to the page access request, and execute the resource file to send an update verification request to the server, where the update verification request includes the version identifier of the resource file; and after receiving the verification result returned by the server, make a judgment according to the verification result. If the resource file has been updated, request the latest resource file from the server by updating the cache management module, and update the resource file in the cache; the server is used to verify whether the resource file has been updated according to the version identifier, and return the verification result to the cache management module.

[0019] Optionally, by setting the cache policy of the update verification request to never cache, so that the update verification request is sent each time the resource file is executed.

[0020] Optionally, if the cache management module fails to find the resource file in the cache, it directly requests the server to obtain the resource file.

[0021] Optionally, the cache management module is further used to: trigger the browser to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server.

[0022] Optionally, by setting the cache policy of the requests during the installation process by the cache management module to never cache, so that the requests during the installation process are directly sent to the server.

[0023] Optionally, the cache management module is a Service Worker.

[0024] According to still another aspect of the embodiments of the present invention, an electronic device for updating the client cache is provided.

[0025] An electronic device for updating a client cache, comprising: one or more processors; a storage device for storing one or more programs, which when executed by the one or more processors cause the one or more processors to implement the method for updating a client cache provided by the embodiments of the present invention.

[0026] According to another aspect of the embodiments of the present invention, there is provided a computer-readable medium.

[0027] A computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, it implements the method for updating a client cache provided by the embodiments of the present invention.

[0028] One embodiment of the above invention has the following advantages or beneficial effects: By introducing a cache management module to control and update the cache on the client side, recording a version identifier in the resource files that need to be cached, and sending an update verification request each time the resource file is executed to inform the server of the version identifier, the server compares the received version identifier with the version identifier of the latest resource file to determine whether there is an update and notifies the cache management module; If the cache management module receives the update information, it requests the latest resource file from the server through the update cache management module, realizing the management and update of the cache files on the client side. Without modifying the file name of the resource file and without setting a very short cache time for the resource file, the cache can be updated in a timely manner, thus ensuring that the resource files of the user request page obtained by the browser each time are the latest versions. In addition, by controlling the version of the cache name, the present invention can also avoid the problem of untimely resource update caused by the caching of the ServiceWorker installation file.

[0029] The further effects of the above non-conventional optional methods will be described in conjunction with the specific embodiments below. Brief Description of the Drawings

[0030] The drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention. Among them:

[0031] Figure 1 is a schematic diagram of the main steps of the method for updating a client cache according to an embodiment of the present invention;

[0032] Figure 2 is a schematic diagram of the main components of the system for updating a client cache according to an embodiment of the present invention;

[0033] Figure 3 is a schematic diagram of the implementation process of the method for updating a client cache in an embodiment of the present invention;

[0034] Figure 4is an exemplary system architecture diagram to which embodiments of the present invention can be applied;

[0035] Figure 5 is a schematic structural diagram of a computer system of a terminal device or a server suitable for implementing embodiments of the present invention. Detailed implementation manners

[0036] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following.

[0037] To solve the problems existing in the prior art, the present invention provides a method and a system for updating cached files on a client side, which can achieve timely update of the cache without modifying the file name or setting a very short cache time for the file. Since browser cache generally refers to HTTP cache, for the sake of distinction, the cache in the browser on the client side in the present invention is called client cache, simply referred to as "cache".

[0038] In the introduction of the detailed implementation manners of the present invention, the noun interpretations are as follows:

[0039] Static resource file: When the client sends a request to a web (abbreviation of World Wide Web, the World Wide Web) server, the web server obtains the corresponding file from the file system and directly returns it to the client. The client parses and renders it for display. Such a file is generally called a static resource, usually referring to files such as JS (abbreviation of JavaScript), CSS (Cascading StyleSheets), and pictures that are not generated by the server dynamically running.

[0040] Service Worker: A service worker thread is a script that runs in the background of the browser independently of the web page, providing the ability to execute functions that do not require interaction with the web page quietly behind the scenes. It is a JavaScript worker thread and a programmable network proxy. Developers can control the processing manner of network requests sent by the page. The first function that ServiceWorker has is the function of intercepting and processing network requests, including programmable message cache management capabilities.

[0041] The principle of the present invention is as follows: By introducing a cache management module, Service Worker, to control and update the cache on the client side, a version identifier is recorded in the static resource files that need to be cached, and an update verification request is sent each time the static resource file is executed to inform the server of the version identifier. The server compares the received version identifier with the version identifier of the latest resource file to determine whether there is an update and notifies the cache management module, Service Worker. If the cache management module, Service Worker, receives the update information, it triggers the update of the Service Worker in the browser by changing the cache version number of the cache management module, Service Worker, and requests the latest resource file through the updated cache management module, Service Worker. According to the technical solution of the present invention, timely cache update is achieved without modifying the file name of the resource file.

[0042] To implement the technical solution of the present invention, a version identifier can be added to the static resource files that need to be cached in advance, and it is set that when these static resource files are executed, an update verification request will be sent to the server to verify whether the static resource files cached locally on the client are the latest version. Among them, the version identifier is, for example, a version number or a timestamp, or any data that can identify the current version of the static resource file. In addition, the cache policy for each resource can be set in advance: (1) The update verification request for obtaining file update information is set to be sent directly to the server side without caching; (2) The static resource file is set to cache first, and if the result cannot be found in the cache, it is sent to the server side again.

[0043] According to the technical solution of the present invention, the cache management module is, for example, the service worker thread, Service Worker. When the user requests to access a page, the browser registers the Service Worker for this page by calling the navigator.serviceWorker.register() method. Specifically, by executing the code for registering the Service Worker deployed in the page, the specific location of the Service Worker script can be informed to the browser.

[0044] After registering the Service Worker for a page, the browser locates the Service Worker script file from the specific location where the Service Worker script is placed, loads it into the browser, and executes it to install the Service Worker. In the install callback event handler, the Service Worker can request resources that need to be cached (e.g., JS files, etc.), open the cache, set the cache name, set the cache policy, and so on. Among them, when setting the cache name, the current version identifier of the cache (e.g., version number, timestamp, etc.) can be used as the cache name and saved with a variable named version. When the cache changes, the change of the cache can be identified by modifying the version identifier of the cache, so that the browser can promptly detect that the Service Worker has been modified, update the Service Worker, and reinstall the Service Worker. By performing version control on the cache name, the problem of untimely resource updates caused by the caching of the Service Worker installation file can be avoided.

[0045] At the same time, in order to prevent static resource files of other page access requests sent by users during the installation of the Service Worker from being loaded from the browser cache (i.e., HTTP cache), the cache policy for requests during the installation of the Service Worker can be set to never cache. For example, the request parameter {cache: 'no-cache'} can be set to ensure that the request must be verified with the server. For example: by setting new Request(' / script.js', {cache: 'no-cache'}), the fetch request for the static resource file " / script.js" is directly verified with the server.

[0046] Finally, after the installation of the Service Worker is completed, network requests are intercepted through the fetch event of the Service Worker, and each intercepted request is responded to according to the pre-set response rules for the requests. The pre-set response rules for requests are, for example: if the request is a page access request, the resource file requested is preferentially searched for in the cache according to the page access request; if the request is the version identifier of a resource file returned by the server, a judgment is made based on the version identifier. If the resource file has not been updated (the version identifiers are the same), the cached resource file is sent to the browser. If the resource file has been updated (the version identifiers are different), the Service Worker is updated by modifying the cache name (or the version identifier of the cache, or the version identifier of the resource file in the cached resource list) to request the latest resource file from the server.

[0047] Figure 1 is a schematic diagram of the main steps of a method for updating a client cache according to an embodiment of the present invention. As Figure 1 shown, the method for updating a client cache according to an embodiment of the present invention mainly includes the following steps S101 to S104.

[0048] Step S101: The browser registers and installs a cache management module for a page that has not registered a cache management module according to a page access request;

[0049] Step S102: The cache management module searches for a requested resource file from the cache according to the page access request, and executes the resource file to send an update verification request to the server. The update verification request includes a version identifier of the resource file;

[0050] Step S103: The server verifies whether the resource file has been updated according to the version identifier, and returns the verification result to the cache management module;

[0051] Step S104: The cache management module makes a judgment according to the verification result. If the resource file has been updated, the cache management module is updated to request the latest resource file from the server, and the resource file in the cache is updated.

[0052] According to an embodiment of the present invention, by setting the cache policy of the update verification request to never cache, an update verification request is sent each time the resource file is executed. In this way, it can be ensured that the static resource files of the user-requested page obtained by the browser each time are all the latest versions.

[0053] According to an embodiment of the present invention, if the cache management module does not find the resource file in the cache, it directly requests the resource file from the server. If the resource file is not found in the cache, it means that the file has not been cached or the cache has expired. Therefore, it is necessary to request the latest file from the server, so that the files included in the page displayed by the browser each time are all the latest version files.

[0054] According to another embodiment of the present invention, when the cache management module is updated to request the latest resource file from the server, it may specifically include: triggering the browser to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server. By performing version control on the cache name, the problem of untimely resource update caused by the Service Worker installation file being cached can be avoided.

[0055] According to an embodiment of the present invention, by setting the cache policy of requests during the installation process of the cache management module to never cache, requests during the installation process are directly sent to the server. In this way, the problem that the page file displayed to the user may not be the latest version caused by loading resource files from the browser cache (i.e., HTTP cache) when the user sends other page access requests during the installation process of the cache management module can be avoided, thereby ensuring the accuracy of the page file displayed to the user at any time.

[0056] In an embodiment of the present invention, the cache management module is a Service Worker.

[0057] Figure 2 It is a schematic diagram of the main components of a system for updating the client cache according to an embodiment of the present invention. As Figure 2 shown, the system 200 for updating the client cache according to an embodiment of the present invention mainly includes a browser 201, a cache management module 202, and a server 203. Among them, the browser 201 and the cache management module 202 are located on the client side, and the server 203 is located on the server side.

[0058] The browser 201 is used to register and install the cache management module for a page that has not registered the cache management module according to a page access request;

[0059] The cache management module 202 is used to find the requested resource file from the cache according to the page access request, and execute the resource file to send an update verification request to the server. The update verification request includes the version identifier of the resource file; and after receiving the verification result returned by the server, make a judgment according to the verification result. If the resource file has been updated, request the latest resource file from the server by updating the cache management module, and update the resource file in the cache;

[0060] The server 203 is used to verify whether the resource file has been updated according to the version identifier, and return the verification result to the cache management module.

[0061] According to an embodiment of the present invention, by setting the cache policy of the update verification request to never cache, an update verification request is sent every time the resource file is executed.

[0062] According to another embodiment of the present invention, if the cache management module fails to find the resource file in the cache, it directly requests the resource file from the server.

[0063] According to still another embodiment of the present invention, the cache management module 202 can also be used for:

[0064] The browser is triggered to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server.

[0065] According to another embodiment of the present invention, by setting the cache policy of the requests during the installation process of the cache management module to never cache, the requests during the installation process are directly sent to the server.

[0066] In the embodiments of the present invention, the cache management module is a service worker, i.e., Service Worker.

[0067] Figure 3 It is a schematic diagram of the implementation process of the client cache update method according to the embodiments of the present invention. As Figure 3 shown, the client cache update method according to the embodiments of the present invention mainly includes the following implementation steps:

[0068] Step S1: The user requests to open a page in the browser;

[0069] Step S2: The browser determines whether the Service Worker has been registered for this page. If it has been registered, step S6 is executed; otherwise, step S3 is executed;

[0070] Step S3: The browser registers the Service Worker for the page. Specifically, it can obtain the storage location of the Service Worker script by executing the code for registering the Service Worker in the page;

[0071] Step S4: The browser downloads and executes the Service Worker script file;

[0072] Step S5: Install the Service Worker and request and cache the required static resource files from the server through the installation callback event handling function;

[0073] Step S6: After the Service Worker is installed, it is determined whether there are static resource files requested by the user in the cache. If there are, step S8 is executed; otherwise, step S7 is executed;

[0074] Step S7: Request the latest static resource files from the server, and then execute step S8;

[0075] Step S8: The Service Worker executes the corresponding static resource file and sends an update verification request;

[0076] Step S9: The fetch method of the Service Worker intercepts the verification result returned by the server;

[0077] Step S10: The Service Worker determines whether the static resource file is updated according to the verification result. If it is not updated, step S11 is executed; otherwise, step S12 is executed.

[0078] Step S11: Return the static resource file cached in the Service Worker installation stage to the browser.

[0079] Step S12: Change the cache version number of the Service Worker to trigger the browser to execute step S5.

[0080] According to the technical solution of the embodiment of the present invention, by introducing a cache management module to control and update the cache on the client side, a version identifier is recorded in the resource file that needs to be cached, and an update verification request is sent each time the resource file is executed to inform the server of the version identifier. The server compares the received version identifier with the version identifier of the latest resource file to determine whether there is an update and notifies the cache management module. If the cache management module receives the update information, it requests the latest resource file from the server by updating the cache management module, realizing the management and update of the cache file on the client side. Without modifying the file name of the resource file and without setting a very short cache time for the resource file, the cache can be updated in a timely manner, thereby ensuring that the resource file of the user-requested page obtained by the browser each time is the latest version. In addition, by controlling the version of the cache name, the present invention can also avoid the problem of untimely resource update caused by the caching of the Service Worker installation file.

[0081] Figure 4 An exemplary system architecture 400 is shown that can apply the method for updating the client cache or the system for updating the client cache according to the embodiment of the present invention.

[0082] As Figure 4 shown, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 is used to provide a medium for a communication link between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0083] Users can use the terminal devices 401, 402, 403 to interact with the server 405 through the network 404 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0084] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.

[0085] The server 405 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 401, 402, and 403. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.

[0086] It should be noted that the method for updating the client cache provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the system for updating the client cache is generally set in the server 405 .

[0087] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0088] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 5 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0089] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0090] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as required. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is mounted on the drive 510 as required so that a computer program read therefrom is installed into the storage section 508 as required.

[0091] Specifically, according to an embodiment disclosed by the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment disclosed by the present invention includes a computer program product which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from the removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, the above functions defined in the system of the present invention are performed.

[0092] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0093] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram can represent a module, a program segment, or a part of code, and the above-mentioned module, program segment, or part of code contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and the combination of blocks in a block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0094] The units or modules described in the embodiments of the present invention can be implemented in software or in hardware.

[0095] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist separately without being assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device includes: the browser registers and installs a cache management module for a page that has not registered the cache management module according to a page access request; the cache management module searches for a requested resource file in the cache according to the page access request, and executes the resource file to send an update verification request to the server, where the update verification request includes a version identifier of the resource file; the server verifies whether the resource file has been updated according to the version identifier, and returns a verification result to the cache management module; the cache management module makes a judgment according to the verification result. If the resource file has been updated, the cache management module requests the latest resource file from the server by updating itself, and updates the resource file in the cache.

[0096] According to the technical solution of the embodiment of the present invention, by introducing a cache management module to control and update the cache on the client side, a version identifier is recorded in the resource file that needs to be cached, and an update verification request is sent each time the resource file is executed to inform the server of the version identifier. The server compares the received version identifier with the version identifier of the latest resource file to determine whether there is an update, and notifies the cache management module; if the cache management module receives the update information, it requests the latest resource file from the server by updating the cache management module, realizing the management and update of the cache file on the client side. Without modifying the file name of the resource file and without setting a very short cache time for the resource file, the cache can be updated in a timely manner, so as to ensure that the resource file of the user-requested page obtained by the browser each time is the latest version. In addition, by controlling the version of the cache name, the present invention can also avoid the problem that the resource update is not timely due to the caching of the Service Worker installation file.

[0097] The above specific embodiments do not constitute a limitation to the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for updating a client cache, characterized in that, Including: The browser registers and installs a cache management module for a page that has not registered the cache management module according to a page access request. Specifically, the browser obtains the specific location where the cache management module script is placed by executing the code for registering the cache management module deployed in the page, and obtains the script of the cache management module from the specific location where the cache management module script is placed, loads the script of the cache management module into the browser and executes it to install the cache management module; The cache management module searches for the requested resource file in the cache according to the page access request, and executes the resource file to send an update verification request to the server, where the update verification request includes the version identifier of the resource file; The server verifies whether the resource file has been updated according to the version identifier, and returns the verification result to the cache management module; The cache management module makes a judgment according to the verification result. If the resource file has been updated, it requests the latest resource file from the server by updating the cache management module, and updates the resource file in the cache; Requesting the latest resource file from the server by updating the cache management module includes: triggering the browser to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server.

2. The method according to claim 1, wherein Also including: By setting the cache policy of the update verification request to never cache, so that the update verification request is sent every time the resource file is executed.

3. The method according to claim 1, wherein Also including: If the cache management module fails to find the resource file in the cache, it directly requests the resource file from the server.

4. The method according to claim 1, wherein Also including: By setting the cache policy of the request during the installation process of the cache management module to never cache, so that the request during the installation process is directly sent to the server.

5. The method according to claim 1, characterized in that, The cache management module is a Service Worker.

6. A system for updating a client cache, characterized in that, Including: A browser, a cache management module and a server, where The browser is used to register and install a cache management module for a page that has not registered the cache management module according to a page access request. Specifically, the browser obtains the specific location where the cache management module script is placed by executing the code for registering the cache management module deployed in the page, and obtains the script of the cache management module from the specific location where the cache management module script is placed, loads the script of the cache management module into the browser and executes it to install the cache management module; The cache management module is used to search for the requested resource file in the cache according to the page access request, and execute the resource file to send an update verification request to the server, where the update verification request includes the version identifier of the resource file; and after receiving the verification result returned by the server, make a judgment according to the verification result. If the resource file has been updated, it requests the latest resource file from the server by updating the cache management module, and updates the resource file in the cache; The server is used to verify whether the resource file has been updated according to the version identifier, and return the verification result to the cache management module; The cache management module is further used to: trigger the browser to update the cache management module by changing the version identifier of the cache, so that the updated cache management module directly requests the latest resource file from the server.

7. The system according to claim 6, wherein By setting the cache policy of the update verification request to never cache, so that the update verification request is sent each time the resource file is executed.

8. The system according to claim 6, wherein If the cache management module fails to find the resource file in the cache, it directly requests the server to obtain the resource file.

9. The system according to claim 6, wherein By setting the cache policy of the request during the installation process of the cache management module to never cache, so that the request during the installation process is directly sent to the server.

10. The system according to claim 6, wherein The cache management module is a service worker, i.e., Service Worker.

11. An electronic device for updating a client cache, characterized in that, It includes: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-5.

12. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Method, device and system for controlling browser cache

    CN102109989A

  • Resource caching method and device

    CN108287836A