[go: up one dir, main page]

CN111475180B - Method and system for updating client cache - Google Patents

Method and system for updating client cache Download PDF

Info

Publication number
CN111475180B
CN111475180B CN201910068527.0A CN201910068527A CN111475180B CN 111475180 B CN111475180 B CN 111475180B CN 201910068527 A CN201910068527 A CN 201910068527A CN 111475180 B CN111475180 B CN 111475180B
Authority
CN
China
Prior art keywords
cache
management module
resource file
cache management
server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910068527.0A
Other languages
Chinese (zh)
Other versions
CN111475180A (en
Inventor
卢晶晶
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201910068527.0A priority Critical patent/CN111475180B/en
Publication of CN111475180A publication Critical patent/CN111475180A/en
Application granted granted Critical
Publication of CN111475180B publication Critical patent/CN111475180B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种更新客户端缓存的方法和系统,涉及计算机技术领域。该方法的一具体实施方式包括:浏览器根据页面访问请求为未注册缓存管理模块的页面注册并安装缓存管理模块;缓存管理模块根据页面访问请求从缓存中查找请求的资源文件,并执行资源文件以将更新校验请求发送给服务器,更新校验请求包括资源文件的版本标识;服务器根据版本标识验证资源文件是否已更新,并将验证结果返回给缓存管理模块;缓存管理模块根据验证结果进行判断,若资源文件已更新,则通过更新缓存管理模块以向服务器请求最新的资源文件,并更新缓存中的资源文件。该实施方式无需修改资源文件的文件名,也无需对资源文件设置很短的缓存时间,即可实现缓存的及时更新。

The present invention discloses a method and system for updating client cache, and relates to the field of computer technology. A specific implementation of the method includes: a browser registers and installs a cache management module for a page that is not registered with a cache management module according to a page access request; the cache management module searches for a requested resource file from a cache according to the page access request, and executes the resource file to send an update verification request to a server, and 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 the verification result to the cache management module; the cache management module makes a judgment based on the verification result, and 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. This implementation method does not need to modify the file name of the resource file, nor does it need to set a very short cache time for the resource file, and can achieve timely update of the cache.

Description

Method and system for updating client cache
Technical Field
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
The browser caching means that the browser stores the requested resource files (such as JavaScript script files, CSS cascading style sheet files, picture files and the like) to the local client by using a caching mechanism of HTTP (HyperText Transfer Protocol ) protocol, and when the next request comes, the browser can directly load the resources meeting the caching conditions from the local client.
One of the problems with caching is how to update the cache. For two common caching strategies, the forced caching has the problems that if resources on a server are updated during the period that the caching is not expired, a client cannot be informed timely, the caching of a browser cannot be updated timely, the negotiation caching obtains updated information from the server every time, the caching can be updated timely, but frequent requests reduce the loading speed of the resources and sacrifice performance. In order to ensure timely update of the cache and maximally improve network performance, a non-coverage type release mode is generally adopted to update the cache. And the HTML page file adopts a negotiation caching strategy to ensure communication with a server and update in time, and the static resource files (such as JavaScript script files, CSS cascading style sheet files, picture files and the like) in the page are forcedly cached. When a static resource file issues an update, the file is renamed, released online with a new file (without overwriting the old version of the file), and the resource path referenced by the HTML page is modified. When the user requests the page, if the referenced static resource is updated, a new resource is requested, and the cache is updated in time, so that a developer can set a forced cache for the static resource for a long time.
However, in the implementation of the present invention, the inventors have found that at least the following problems exist in the prior art:
1. implementing a cache update by changing the file name is not suitable for all files:
(1) Some third-party static resource files are referenced by numerous developers, and updating by modifying the file name does not guarantee knowledge of all developers, which is inconvenient. Typically, the third party script's caching strategy is to employ forced caching and set a short expiration time so that the caching can be updated in time. However, this method cannot ensure that the client must be the latest resource for the next request after the server file is updated;
(2) For blog websites, users generally cannot modify page source codes, and therefore, the cache cannot be updated in a mode of updating resource file names;
2. If static resource files are updated frequently, HTML page files must also be published frequently. The current mainstream development mode is that front and back ends are separated, an HTML page and a static file are usually deployed on different servers, and each time updating both sides need to be deployed, so that deployment cost is increased.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a method and a system for updating a client cache, which can manage and update a cache file at a client, without modifying a file name of a resource file, and without setting a short cache time for the resource file, so as to implement timely update of the cache, thereby ensuring that the resource file of a user request page acquired by a browser each time is the latest version.
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.
A method for updating client side cache includes registering page of unregistered cache management module by browser according to page access request and installing cache management module, searching requested resource file from cache by said cache management module according to said page access request and executing said resource file to send update check request to server, verifying whether resource file has been updated by said server according to said version identification and returning verification result to said cache management module, judging by said cache management module according to said verification result, if said resource file has been updated, requesting up to date resource file to said server by updating said cache management module and updating resource file in said cache.
Optionally, the method further comprises setting a caching strategy of the update verification request to never cache, so that the update verification request is sent every time the resource file is executed.
Optionally, the method further comprises the step of directly requesting the server for obtaining the resource file if the resource file is not found in the cache by the cache management module.
Optionally, the step of updating the cache management module to request the latest resource file from the server comprises the step of 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.
Optionally, the method further comprises the step of setting a caching strategy of the request in the installation process of the caching management module to be never cached, so that the request in the installation process is directly sent to the server.
Optionally, the cache management module is a Service Worker for a Service Worker.
According to another aspect of an embodiment of the present invention, a system for updating a client cache is provided.
A system for updating client side cache comprises a browser, a cache management module and a server, wherein the browser is used for registering and installing the cache management module for a page of an unregistered cache management module according to a page access request, the cache management module is used for searching a requested resource file from a cache according to the page access request and executing the resource file to send an update verification request to the server, the update verification request comprises a version identification of the resource file, after receiving a verification result returned by the server, judgment is carried out according to the verification result, if the resource file is updated, the latest resource file is requested to the server through updating the cache management module, and the resource file in the cache is updated, and the server is used for verifying whether the resource file is updated according to the version identification and returning the verification result to the cache management module.
Optionally, the update verification request is sent each time the resource file is executed by setting a caching policy of the update verification request to never cache.
Optionally, if the cache management module does not find the resource file from the cache, the cache management module directly requests the server to acquire the resource file.
Optionally, the cache management module is further configured 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.
Optionally, the request in the installation process is directly sent to the server by setting the caching strategy of the request in the installation process of the caching management module to be never cached.
Optionally, the cache management module is a Service Worker for a Service Worker.
According to yet another aspect of an embodiment of the present invention, an electronic device for updating a client cache is provided.
An electronic device for updating a client cache comprises one or more processors and a storage device, wherein the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the method for updating the client cache.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer readable medium having stored thereon a computer program which when executed by a processor implements a method of updating a client cache provided by an embodiment of the present invention.
The embodiment of the invention has the advantages that the cache management module is introduced to control and update the cache at the client, the version identification is recorded in the resource file to be cached, and when the resource file is executed each time, an update verification request is sent to inform the server of the version identification, the server compares the received version identification with the version identification of the latest resource file, judges whether the update exists and informs the cache management module, if the cache management module receives the update information, the latest resource file is requested to the server through the update cache management module, the management and update of the cache file at the client are realized, the file name of the resource file is not required to be modified, and the cache can be updated in time without setting a short cache time for the resource file, so that the resource file of a user request page acquired by a browser each time is ensured to be the latest version. In addition, the invention can also avoid the problem of untimely resource update caused by caching the Service workbench installation file by carrying out version control on the cache name.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method of updating a client cache according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of the main components of a system for updating a client cache according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of an implementation flow of a client cache update method according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
Fig. 5 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In order to solve the problems in the prior art, the invention provides a method and a system for updating a cache file at a client, which can realize timely updating of the cache without modifying a file name or setting a short cache time for the file. Since browser cache generally refers to HTTP cache, for distinction, the cache in the browser of the client is referred to as client cache, simply referred to as "cache" in the present invention.
In describing embodiments of the present invention, the terminology that appears is defined as follows:
the static resource file is that a client sends a request to a Web server, the Web server obtains corresponding files from a file system and directly returns the corresponding files to the client, the client analyzes and renders the files to display, and the files are generally called static resources and are usually files generated by dynamic operation of a non-server such as JS (JavaScript for short), CSS (CASCADING STYLE SHEETS ), pictures and the like;
service Worker is a script that the browser runs in the background independently of the web page, and provides the capability that functions that do not need to interact with the web page are silently executed behind the web page. The method is a JavaScript working thread, is a programmable network agent, and a developer can control the processing mode of a network request sent by a page. The Service Worker first has a function of intercepting and processing network requests, including a programmable message cache management capability.
The invention is based on the principle that a cache management module Service Worker is introduced to control and update the cache at a client, a version identifier is recorded in a static resource file to be cached, an update verification request is sent to inform a server of the version identifier when the static resource file is executed each time, the server compares the received version identifier with the version identifier of the latest resource file, whether the update exists or not is judged, and the cache management module Service Worker is informed. If the cache management module Service workbench receives the update information, the update of the browser to the Service workbench is triggered by changing the cache version number of the cache management module Service workbench, and the updated cache management module Service workbench requests the latest resource file. According to the technical scheme of the invention, timely cache updating is realized, and the file name of the resource file is not required to be modified.
In order to realize the technical scheme of the invention, version identification can be added in the static resource files needing to be cached in advance, and when the static resource files are executed, an update verification request is sent to the server to verify whether the static resource files locally cached by the client are the latest version. Where the version identification is, for example, a version number or any data such as a timestamp that can identify the current version of the static resource file. In addition, the caching strategy of each resource can be preset, namely (1) the updating verification request for acquiring the file updating information is set to be directly sent to the server without caching, and (2) the static resource file is set to be cache priority, and if the result is not found in the cache, the static resource file is sent to the server again.
According to the technical scheme of the invention, the cache management module is, for example, a Service Worker of a Service work thread. When a user requests access to a page, the browser registers Service workbench for the page by calling a navigator. Serviceworkbench. Register () method. Specifically, the specific location of the browser Service workbench script can be notified by executing the code of the registered Service workbench deployed in the page.
After registering the Service workbench for the page, the browser finds the Service workbench script file from the specific position where the Service workbench script is placed, loads it into the browser and executes it to install the Service workbench. In the install callback event handling function, the Service Worker may request a resource (e.g., JS file, etc.) that needs to be cached, open the cache, set the cache name, set the cache policy, etc. When the cache name is set, the current version identifier (such as version number, timestamp, etc.) of the cache can be used as the cache name and stored by using a variable version. When the cache is changed, the cached change can be identified by modifying the version identification of the cache, so that the browser can timely find that the Service workbench is modified, update the Service workbench and reinstall the Service workbench. By carrying out version control on the cache name, the problem of untimely resource update caused by cached Service workbench installation files can be avoided.
Meanwhile, in order to avoid that static resource files of other page access requests sent by a user in the process of installing the Service workbench are loaded from a browser cache (namely an HTTP cache), a caching policy of the requests in the process of installing the Service workbench can be set to never cache, for example, a request parameter { cache: 'no-cache' } can be set to ensure that the requests must be verified to a server. For example, by setting new Request ('/script. Js', { cache: 'no-cache' }) so that the acquisition Request of the static resource file "/script. Js" is directly verified to the server.
Finally, after the Service workbench is installed, intercepting the network request through a fetch event of the Service workbench, and responding to each intercepted request according to a preset response rule of the request. The preset response rule for the request is that if the request is a page access request, the requested resource file is preferentially searched from the cache according to the page access request, if the request is the version identification of the resource file returned by the server, the request is judged according to the version identification, if the resource file is not updated (the version identification is the same), the cached resource file is sent to the browser, and if the resource file is updated (the version identification is different), the Service Worker is updated by modifying the cache name (or the version identification of the cached or the version identification of the resource file in the cached resource list) so as to request the server to acquire the latest resource file.
Fig. 1 is a schematic diagram of main steps of a method for updating a client cache according to an embodiment of the present invention. As shown in fig. 1, the method for updating a client cache according to the embodiment of the present invention mainly includes steps S101 to S104 as follows.
Step S101, a browser registers and installs a cache management module for a page of an unregistered cache management module according to a page access request;
Step S102, a cache management module searches a requested resource file from a cache according to a page access request, and executes the resource file to send an update checking request to a server, wherein the update checking request comprises a version identifier of the resource file;
step S103, the server verifies whether the resource file is updated according to the version identification, and returns a verification result to the cache management module;
step S104, the cache management module judges according to the verification result, if the resource file is 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.
According to the embodiment of the invention, the cache policy of the update verification request is set to never cache, so that the update verification request is sent every time the resource file is executed. Therefore, the static resource file of the user request page acquired by the browser can be guaranteed to be the latest version each time.
According to one embodiment of the invention, if the cache management module does not find the resource file from the cache, the resource file is directly requested to be obtained from the server. If the resource file is not found in the cache, it means that the file is not cached or the cache is expired, so that the latest file needs to be requested from the server, so that the file contained in the page displayed by the browser is the latest version of the file each time.
According to another embodiment of the invention, the method for requesting the latest resource file from the server by updating the cache management module can comprise the step of triggering the browser to update the cache management module by changing the version identification of the cache, so that the updated cache management module directly requests the latest resource file from the server. By carrying out version control on the cache name, the problem of untimely resource update caused by cached Service workbench installation files can be avoided.
According to one embodiment of the invention, the request in the installation process is directly sent to the server by setting the caching strategy of the request in the installation process to never cache. Therefore, the problem that the page file displayed to the user is not necessarily the latest version caused by loading the resource file from the browser cache (namely HTTP cache) when the user sends other page access requests in the installation process of the cache management module can be avoided, and the accuracy of the page file displayed to the user whenever the user is ensured.
In the embodiment of the invention, the cache management module is a Service Worker of a Service work thread.
Fig. 2 is a schematic diagram of the main components of a system for updating a client cache according to an embodiment of the present invention. As shown in fig. 2, a system 200 for updating client caches according to an embodiment of the present invention mainly includes a browser 201, a cache management module 202, and a server 203. Wherein, the browser 201 and the cache management module 202 are located at a client, and the server 203 is located at a server.
The browser 201 is configured to register and install a cache management module for a page of the unregistered cache management module according to a page access request;
The cache management module 202 is configured to search a requested resource file from a cache according to a page access request, execute the resource file to send an update verification request to a server, where the update verification request includes a version identifier of the resource file, and determine according to a verification result returned by the server after receiving the verification result, and if the resource file is updated, request an updated resource file from the server by updating the cache management module, and update the resource file in the cache;
the server 203 is configured to verify whether the resource file is updated according to the version identifier, and return a verification result to the cache management module.
According to one embodiment of the invention, the update verification request is sent each time the resource file is executed by setting the cache policy of the update verification request to never cache.
According to another embodiment of the present invention, if the cache management module does not find the resource file from the cache, it directly requests the server to acquire the resource file.
According to yet another embodiment of the present invention, the cache management module 202 may also be configured to:
and 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.
According to another embodiment of the invention, the request in the installation process is directly sent to the server by setting the caching strategy of the request in the installation process to never cache.
In the embodiment of the invention, the cache management module is a Service Worker for a Service work thread.
Fig. 3 is a schematic flow chart of an implementation of a client cache update method according to an embodiment of the present invention. As shown in fig. 3, the method for updating the client cache according to the embodiment of the present invention mainly includes the following implementation steps:
step S1, a user requests to open a page in a browser;
and S2, the browser judges whether the page is registered with the Service workbench. If so, executing the step S6, otherwise executing the step S3;
Step S3, the browser registers the Service workbench for the page, and can obtain the storage position of the Service workbench script by executing the code of registering the Service workbench in the page;
s4, downloading and executing a Service workbench script file by the browser;
S5, installing a Service workbench, and requesting and caching a required static resource file from a server through installing a callback event processing function;
and S6, judging whether the static resource file requested by the user exists in the cache after the Service workbench is installed. If yes, executing the step S8, otherwise, executing the step S7;
Step S7, requesting the latest static resource file from the server, and then executing step S8;
s8, the Service workbench executes the corresponding static resource file and sends an update verification request;
s9, intercepting a verification result returned by the server by a fetch method of a Service workbench;
and step S10, the Service workbench judges whether the static resource file is updated according to the verification result. If not, executing step S11, otherwise executing step S12;
Step S11, returning the static resource file cached in the installation stage of the Service workbench to the browser;
and S12, changing the buffer version number of the Service workbench to trigger the browser to execute the step S5.
According to the technical scheme of the embodiment of the invention, the cache management module is introduced to control and update the cache at the client, the version identification is recorded in the resource file to be cached, and when the resource file is executed each time, an update verification request is sent to inform the server of the version identification, the server compares the received version identification with the version identification of the latest resource file, judges whether the update exists and informs the cache management module, if the cache management module receives the update information, the latest resource file is requested to the server through the update cache management module, the management and update of the cache file at the client are realized, the file name of the resource file is not required to be modified, and the cache can be updated in time without setting a short cache time for the resource file, so that the resource file of a user request page acquired by a browser each time is ensured to be the latest version. In addition, the invention can also avoid the problem of untimely resource update caused by caching the Service workbench installation file by carrying out version control on the cache name.
Fig. 4 illustrates an exemplary system architecture 400 of a method of updating a client cache or a system of updating a client cache to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 is used as a medium to provide communication links 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, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403. The background management server may analyze and process the received data such as the product information query request, and feedback the processing result (e.g., the target push information, the product information—only an example) to the terminal device.
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.
It should be understood that the number of terminal devices, networks and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing a terminal device or server in accordance with an embodiment of the present invention. The terminal device or server shown in fig. 5 is only an example, and should not impose any limitation on the functions and scope of use of the embodiments of the present invention.
As shown in fig. 5, 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 section 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, ROM 502, and RAM 503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
Connected to the I/O interface 505 are an input section 506 including a keyboard, a mouse, and the like, an output section 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like, a storage section 508 including a hard disk, and the like, and a communication section 509 including a network interface card such as a LAN card, a modem, and the like. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of a computer-readable storage medium may include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present invention may be implemented in software or in hardware.
As a further aspect, the invention also provides a computer readable medium which may be comprised in the device described in the above embodiments or may be present alone without being fitted into the device. The computer readable medium carries one or more programs, when the one or more programs are executed by the device, the device comprises a browser, a cache management module, a server and a cache management module, wherein the browser registers and installs the cache management module for a page of an unregistered cache management module according to a page access request, the cache management module searches a requested resource file from a 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 comprises a version identifier of the resource file, the server verifies whether the resource file is updated according to the version identifier and returns a verification result to the cache management module, the cache management module judges according to the verification result, and if the resource file is updated, the cache management module is updated to request the latest resource file from the server and update the resource file in the cache.
According to the technical scheme of the embodiment of the invention, the cache management module is introduced to control and update the cache at the client, the version identification is recorded in the resource file to be cached, and when the resource file is executed each time, an update verification request is sent to inform the server of the version identification, the server compares the received version identification with the version identification of the latest resource file, judges whether the update exists and informs the cache management module, if the cache management module receives the update information, the latest resource file is requested to the server through the update cache management module, the management and update of the cache file at the client are realized, the file name of the resource file is not required to be modified, and the cache can be updated in time without setting a short cache time for the resource file, so that the resource file of a user request page acquired by a browser each time is ensured to be the latest version. In addition, the invention can also avoid the problem of untimely resource update caused by caching the Service workbench installation file by carrying out version control on the cache name.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (12)

1.一种更新客户端缓存的方法,其特征在于,包括:1. A method for updating a client cache, comprising: 浏览器根据页面访问请求为未注册缓存管理模块的页面注册并安装缓存管理模块,其中,浏览器通过执行页面里部署的注册缓存管理模块的代码获取放置缓存管理模块脚本的具体位置,并从放置缓存管理模块脚本的具体位置获取所述缓存管理模块的脚本,将所述缓存管理模块的脚本加载到浏览器中并执行以安装所述缓存管理模块;The browser registers and installs the cache management module for the page without the cache management module registered according to the page access request, wherein 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, 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 from the cache according to the page access request, and executes the resource file to send an update verification request to the server, wherein 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 the verification result to the cache management module; 所述缓存管理模块根据所述验证结果进行判断,若所述资源文件已更新,则通过更新所述缓存管理模块以向所述服务器请求最新的资源文件,并更新所述缓存中的资源文件;The cache management module makes a judgment based on the verification result, and if the resource file has been updated, 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 cache version identifier, so that the updated cache management module directly requests the latest resource file from the server. 2.根据权利要求1所述的方法,其特征在于,还包括:通过设置所述更新校验请求的缓存策略为永不缓存,以使每次执行所述资源文件时都会发送所述更新校验请求。2. The method according to claim 1 is characterized in that it also 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. 3.根据权利要求1所述的方法,其特征在于,还包括:若所述缓存管理模块从所述缓存中未查找到所述资源文件,则直接向所述服务器请求获取所述资源文件。3. The method according to claim 1 is characterized in that it also includes: if the cache management module fails to find the resource file in the cache, directly requesting the server to obtain the resource file. 4.根据权利要求1所述的方法,其特征在于,还包括:通过设置所述缓存管理模块在安装过程中的请求的缓存策略为永不缓存,以使所述安装过程中的请求直接发送给所述服务器。4. The method according to claim 1 is characterized in that it also includes: setting the cache policy of the cache management module during the installation process to never cache, so that the requests during the installation process are directly sent to the server. 5.根据权利要求1所述的方法,其特征在于,所述缓存管理模块为服务工作线程Service Worker。5. The method according to claim 1 is characterized in that the cache management module is a service worker thread Service Worker. 6.一种更新客户端缓存的系统,其特征在于,包括:浏览器、缓存管理模块和服务器,其中,6. A system for updating client cache, characterized in that it includes: a browser, a cache management module and a server, wherein: 所述浏览器用于根据页面访问请求为未注册缓存管理模块的页面注册并安装缓存管理模块,其中,浏览器通过执行页面里部署的注册缓存管理模块的代码获取放置缓存管理模块脚本的具体位置,并从放置缓存管理模块脚本的具体位置获取所述缓存管理模块的脚本,将所述缓存管理模块的脚本加载到浏览器中并执行以安装所述缓存管理模块;The browser is used to register and install a cache management module for a page that has not registered a cache management module according to a page access request, wherein the browser obtains a specific location where a cache management module script is placed by executing a code for registering the cache management module deployed in the page, 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 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, wherein the update verification request includes a version identifier of the resource file; and after receiving the verification result returned by the server, judging according to the verification result, if the resource file has been updated, requesting the latest resource file from the server by updating the cache management module, and updating 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 also 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.根据权利要求6所述的系统,其特征在于,通过设置所述更新校验请求的缓存策略为永不缓存,以使每次执行所述资源文件时都会发送所述更新校验请求。7. The system according to claim 6 is characterized in that the cache policy of the update verification request is set to never cache, so that the update verification request is sent each time the resource file is executed. 8.根据权利要求6所述的系统,其特征在于,若所述缓存管理模块从所述缓存中未查找到所述资源文件,则直接向所述服务器请求获取所述资源文件。8. The system according to claim 6 is characterized in that 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.根据权利要求6所述的系统,其特征在于,通过设置所述缓存管理模块在安装过程中的请求的缓存策略为永不缓存,以使所述安装过程中的请求直接发送给所述服务器。9. The system according to claim 6 is characterized in that the cache policy of the cache management module during the installation process is set to never cache, so that the requests during the installation process are directly sent to the server. 10.根据权利要求6所述的系统,其特征在于,所述缓存管理模块为服务工作线程Service Worker。10. The system according to claim 6, characterized in that the cache management module is a service worker thread Service Worker. 11.一种更新客户端缓存的电子设备,其特征在于,包括:11. An electronic device for updating a client cache, comprising: 一个或多个处理器;one or more processors; 存储装置,用于存储一个或多个程序,a storage device for storing one or more programs, 当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如权利要求1-5中任一所述的方法。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 to 5. 12.一种计算机可读介质,其上存储有计算机程序,其特征在于,所述程序被处理器执行时实现如权利要求1-5中任一所述的方法。12. A computer-readable medium having a computer program stored thereon, wherein when the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
CN201910068527.0A 2019-01-24 2019-01-24 Method and system for updating client cache Active CN111475180B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910068527.0A CN111475180B (en) 2019-01-24 2019-01-24 Method and system for updating client cache

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910068527.0A CN111475180B (en) 2019-01-24 2019-01-24 Method and system for updating client cache

Publications (2)

Publication Number Publication Date
CN111475180A CN111475180A (en) 2020-07-31
CN111475180B true CN111475180B (en) 2025-07-15

Family

ID=71743549

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910068527.0A Active CN111475180B (en) 2019-01-24 2019-01-24 Method and system for updating client cache

Country Status (1)

Country Link
CN (1) CN111475180B (en)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112637262B (en) * 2020-11-18 2022-12-02 网宿科技股份有限公司 A method and device for refreshing content
CN112925539B (en) * 2021-02-19 2022-12-06 天津车之家数据信息技术有限公司 Application updating method, computing device and storage medium
CN112926002A (en) * 2021-03-10 2021-06-08 工银科技有限公司 Service request processing method and device
CN113392078A (en) * 2021-06-04 2021-09-14 上海浦东发展银行股份有限公司 Method and device for monitoring operation change state, computer equipment and storage medium
CN113360464A (en) * 2021-06-10 2021-09-07 山东云缦智能科技有限公司 Cache synchronization method for realizing OSS based on Nginx
CN113296817A (en) * 2021-06-18 2021-08-24 杭州玳数科技有限公司 Silent updating method and device for front-end resources and computer equipment
CN113407876B (en) * 2021-06-18 2022-10-25 杭州安恒信息技术股份有限公司 Webpage refreshing method, webpage refreshing system and related device
CN113641932A (en) * 2021-06-23 2021-11-12 福建野小兽健康科技有限公司 Page updating method and system based on H5
CN113779458B (en) * 2021-07-27 2024-02-27 贝壳找房(北京)科技有限公司 Method and device for accelerating application loading, electronic equipment and storage medium
CN114115941A (en) * 2021-11-11 2022-03-01 北京沃东天骏信息技术有限公司 Resource sending method, page rendering method, apparatus, electronic device and medium
CN114584543A (en) * 2022-02-16 2022-06-03 百安居信息技术(上海)有限公司 Web-based resource quick access method, system, medium and equipment
CN115242775B (en) * 2022-07-04 2024-11-01 中国银联股份有限公司 Resource file acquisition method, device, equipment, medium and product
CN114936192B (en) * 2022-07-19 2022-10-28 成都新橙北斗智联有限公司 Method and system for dynamic compression confusion and bidirectional caching of files
CN115344804A (en) * 2022-08-31 2022-11-15 济南浪潮数据技术有限公司 Cache data acquisition method and related device
CN116244538B (en) * 2023-01-31 2023-11-21 彭志勇 File caching method and loading method based on serviceworker
CN116975482A (en) * 2023-07-10 2023-10-31 山东浪潮科学研究院有限公司 HTTP caching mechanism realization method and tool for Web page
CN117194823A (en) * 2023-09-07 2023-12-08 中国银行股份有限公司 A data update method, system, electronic device and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102109989A (en) * 2009-12-29 2011-06-29 阿里巴巴集团控股有限公司 Method, device and system for controlling browser cache
CN108287836A (en) * 2017-01-09 2018-07-17 腾讯科技(深圳)有限公司 A kind of resource caching method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
RU2673403C2 (en) * 2015-12-28 2018-11-26 Хуавэй Текнолоджиз Ко., Лтд. Website access method, device and website system

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102109989A (en) * 2009-12-29 2011-06-29 阿里巴巴集团控股有限公司 Method, device and system for controlling browser cache
CN108287836A (en) * 2017-01-09 2018-07-17 腾讯科技(深圳)有限公司 A kind of resource caching method and device

Also Published As

Publication number Publication date
CN111475180A (en) 2020-07-31

Similar Documents

Publication Publication Date Title
CN111475180B (en) Method and system for updating client cache
RU2673403C2 (en) Website access method, device and website system
US9929895B2 (en) Unique identifiers for browsers
CN112748962A (en) Application loading method and device, electronic equipment and computer readable medium
CN109936605B (en) Method and device for loading interface data
CN111783005B (en) Method, device and system for displaying web page, computer system and medium
CN113364887B (en) File downloading method based on FTP, proxy server and system
CN110851194A (en) Method and device for acquiring code for realizing new interface
CN119002966A (en) Method and system for automatically updating version based on single-page web front end
US9378178B1 (en) Enhancing HTTP caching by allowing content sharing of data blocks across resources identified by different uniform resource locators
CN112380469A (en) Page display method, device and system, electronic equipment and storage medium
US20140164556A1 (en) Method and system for live loading of a toolbar
CN110244975A (en) A method and device for generating a version number of a static resource
CN113449215B (en) Picture loading method and device
CN114115941A (en) Resource sending method, page rendering method, apparatus, electronic device and medium
CN113626152A (en) Proxy method and device for accessing distributed cluster
CN113760346A (en) Information management method and device
CN113746661B (en) A business processing method and device
US20240095007A1 (en) Managing installation and updates of an application on a computing device
CN114428805A (en) Page display method, device, equipment and computer readable medium
CN119938114A (en) A web application code updating method, device and computer equipment
CN116610295A (en) Interface service providing method, device, electronic equipment, system and storage medium
CN117131295A (en) Resource management method, system, device, electronic equipment and storage medium
CN115129428A (en) Method and device for version management of container image
CN112445651A (en) File copying method, device, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant