CN108846141B - Offline cache loading method and device - Google Patents

Offline cache loading method and device Download PDF

Info

Publication number
CN108846141B
CN108846141B CN201810760618.6A CN201810760618A CN108846141B CN 108846141 B CN108846141 B CN 108846141B CN 201810760618 A CN201810760618 A CN 201810760618A CN 108846141 B CN108846141 B CN 108846141B
Authority
CN
China
Prior art keywords
resource
request
loading
memory
resources
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
CN201810760618.6A
Other languages
Chinese (zh)
Other versions
CN108846141A (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.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
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 China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN201810760618.6A priority Critical patent/CN108846141B/en
Publication of CN108846141A publication Critical patent/CN108846141A/en
Application granted granted Critical
Publication of CN108846141B publication Critical patent/CN108846141B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention provides an offline cache loading method and device, and relates to the technical field of computing equipment. The off-line cache loading method comprises the steps of firstly obtaining a network resource loading request containing uniform resource locators of corresponding resources, searching resources corresponding to the uniform resource locators in a memory, searching the resources in an external storage if the resources are not searched in the memory, and loading the resources into the memory if the resources are searched in the external storage. According to the offline cache loading method, caching and cache reading of resources in the internal memory and the external memory are realized in the iOS operating system, the utilization rate of the cache is improved, the utilization rate of the system internal memory is reduced, and offline caching of network resources is effectively realized.

Description

Offline cache loading method and device
Technical Field
The invention relates to the technical field of computing equipment, in particular to an offline cache loading method and device.
Background
With the rapid development of internet technology, more and more data and resources are stored in network cloud devices such as a cloud server, some programs of the existing computing device terminal generally need to acquire related resources on the network when running, and the programs cannot normally acquire the related resources when the network conditions are poor and the computing device terminal cannot access the internet. The network caching mechanism plays an important role in optimizing network response and improving user experience, and how a good network program smoothly runs in a complex network environment depends on the quality of the network caching mechanism to some extent.
However, in the current iOS system, the buffer mechanism of the iOS operating system can achieve the problem of optimizing the secondary loading network resource, however, such optimization is based on consuming limited memory, when the system memory is insufficient, the system will discard part of the buffer resource, and under severe conditions, the system will terminate the running of the program, resulting in the flash back of APP, and reducing the user experience. This phenomenon is particularly evident in the increasingly large variety of APP programs. On the other hand, due to the mechanism of the memory, after the user exits the APP, the cache can be cleared, and after the APP is opened for the second time, the resources loaded again can be regarded as new resources, and the cache needs to be re-cached.
Disclosure of Invention
In view of the above, an embodiment of the present invention provides an offline cache loading method and apparatus to solve the above problems in the prior art.
In a first aspect, an embodiment of the present invention provides an offline cache loading method, where the offline cache loading method first obtains a network resource loading request including a uniform resource locator of a corresponding resource, searches a memory for a resource corresponding to the uniform resource locator, searches an external storage for the resource if the resource is not searched in the memory, and loads the resource into the memory if the resource is searched in the external storage.
In summary of the first aspect, after the obtaining the network resource loading request and before searching the cache of the resource corresponding to the uniform resource locator in the memory, the offline cache loading method further includes: determining that the resource belongs to the resource needing to be intercepted according to the network resource loading request; and determining that the network resource loading request does not belong to a secondary packaging request based on a parameter flag bit of the network resource loading request, wherein the secondary packaging request is a request subjected to secondary packaging through a canonical request ForRequest function in the NSURLProtocol protocol.
In summary of the first aspect, after determining that the network resource loading request does not belong to a secondary encapsulation request based on the parameter flag bit of the network resource loading request, the offline cache loading method further includes: performing secondary packaging on the network resource loading request through a canonicalRequestForRequest function to obtain a secondary packaging request; and based on the secondary packaging request, adopting an NSURLCache protocol to execute the steps from searching the resources corresponding to the uniform resource locator in the memory to loading the resources into the memory.
In summary of the first aspect, after the obtaining the network resource loading request, before the determining, according to the network resource loading request, that the resource belongs to the resource that needs to be intercepted, the offline cache loading method further includes: judging whether the network resource loading request contains a specific character string or not; if yes, executing the steps of searching resources corresponding to the uniform resource locator in the memory to package the resources and finish loading according to a startLoading function; if not, according to the canInitWithrequest, executing the step of searching the resources corresponding to the uniform resource locator in the memory to package and complete loading the resources according to the function.
In summary of the first aspect, after the loading the resource into the memory, the method includes: and adding a parameter flag bit to the secondary packaging request.
In summary of the first aspect, after the loading the resource into the memory, the offline cache loading method further includes: judging whether the residual memory space of the memory can cache the resources or not; if so, caching the resource in the memory; if not, caching the resources in the external memory.
In a second aspect, an embodiment of the present invention provides an offline cache loading device, where the offline cache loading device includes a network resource loading request obtaining module, a resource searching module, a resource loading module, and a resource encapsulating module. The network resource loading request acquisition module is used for acquiring a network resource loading request, and the network resource loading request comprises a uniform resource locator of a corresponding resource. The resource searching module is used for searching the resources corresponding to the uniform resource locator in the memory or the external memory. The resource loading module is used for loading the resource into the memory when the resource is searched in the external memory. And the resource encapsulation module is used for encapsulating the resources and completing loading.
In summary of the second aspect, the offline cache loading device further includes an interception module, where the interception module includes an interception determination unit and a secondary encapsulation determination unit. And the interception judging unit is used for determining that the resource belongs to the resource needing to be intercepted according to the network resource loading request. The secondary packaging judging unit is used for determining that the network resource loading request does not belong to a secondary packaging request based on the parameter flag bit of the network resource loading request, wherein the secondary packaging request is a request after secondary packaging is carried out through a canonical request ForRequest function in an NSURLProtocol protocol.
In a third aspect, the embodiment of the present invention further provides a computing device, where the computing device includes a bus, and a processor and a memory connected to the bus, where the memory is used to store computer instructions, and the processor is used to execute the computer instructions to perform the above method when executing the computer instructions.
In a fourth aspect, the present invention further provides a storage medium stored in a computer, where the storage medium includes a plurality of instructions configured to cause the computer to execute the above method.
The beneficial effects provided by the invention are as follows:
the invention provides an offline cache loading method and device, wherein the offline cache loading method searches whether cached resources exist in a memory and an external storage, and directly loads the resources when the cache of the resources exists in the memory or the external storage, so that the simultaneous caching of the resources in the memory and the external storage is realized, the quantity of offline cache resources is increased, and an application program can load the cache from a local external storage even if the application program is restarted. Meanwhile, after a network resource loading request is obtained, whether cached resources exist in the memory is searched first, whether cached resources exist in the external storage is searched, and auxiliary caching is performed through external storage, so that the utilization rate of the memory in the system is reduced, and the cache loading speed and the cache utilization rate are effectively improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the embodiments of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
FIG. 1 is a flow chart of a cache response of NSURLProtocol protocol and NSURLCache protocol;
fig. 2 is a flowchart of an offline cache loading method according to a first embodiment of the present invention;
FIG. 3 is a flowchart of an interception determination procedure according to a first embodiment of the present invention;
fig. 4 is a block diagram of an offline cache loading apparatus according to a second embodiment of the present invention;
fig. 5 is a block diagram of a computing device according to a third embodiment of the present invention.
Icon: 100-an offline cache loading device; 110-a network resource loading request obtaining module; 120-a resource search module; 130-resource loading module; 140-an interception module; 200-a computing device; 201-a memory; 202-a memory controller; 203-a processor; 204-peripheral interface; 205-input-output unit; 206-an audio unit; 207-display unit.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present invention, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
The following first introduces a processing mechanism of the iOS system network framework protocol to network resource caching according to the embodiment of the present application:
each step in the offline cache loading method in the embodiment of the present application is implemented by using the NSURLProtocol protocol and/or the NSURLCache protocol. Referring to fig. 1, fig. 1 is a flow chart of a cache response of the NSURLProtocol protocol and the NSURLCache protocol.
The NSURLProtocol protocol is a protocol interface which is provided by a Cocoa Touch framework and is established on the basis of a URL Load System framework, and provides a Uniform Resource Locator (URL) for processing network resource loading requests or other types of requests.
The NSURLProtocol protocol is composed of four core functions, namely a canInitWithRequest function, a canonicaLRequest function, an initWithRequest function and a startLoading function. The function is used for judging whether the protocol is required to process the received network resource loading request; the function is used for carrying out secondary encapsulation on the network resource loading request and the corresponding resource to obtain a secondary encapsulation request in the form of NSCachedURLResponse variable; the initWithRequest function is used for processing the NSCachedURLResponse variable, assembling a new NSCachedURLResponse variable and sending the new NSCachedURLResponse variable to the system; and the startLoading function is used for loading the resources after the required parameters are assembled.
The URL request of NSURLCache protocol application provides a memory and a comprehensive cache mechanism on a disk, which is a part of the URL loading of a basic class library, and any request loaded through NSURLConnection/NSURLSession is processed by NSURLCache.
The NSURLCache protocol comprises a core function, namely a cachedResponseForRequest function, wherein the cachedResponseForRequest function identifies a request through NSURLRquest, judges whether the resource needs to be cached or not and judges whether the resource is cached or not, and then returns NSCachedURLResponse to NSURLProtocol for processing.
First embodiment
The research of the applicant discovers that the network framework protocol of the iOS system upgrades the cache of the network resources, and the cache mechanism is realized by loading the resources into the memory. When loading new resources, the framework serializes the resources and stores the resources in the memory according to a certain rule, and then when loading the resources each time, the resources loaded in the memory are directly obtained from the memory without accessing the network again. Due to the obvious advantage of the access speed of the memory, the loading speed of the APP is usually increased by a factor of two when the same resource is loaded for the second time. However, in the existing cache mechanism, when the system memory is insufficient, the system discards part of cache resources, and in a severe case, the system terminates the running of a program, so that the APP is flashed off, and the user experience is reduced; meanwhile, due to the mechanism of the memory, when the user quits the APP, the cache can be emptied; moreover, cacheable resource types specified by the iOS network framework protocol are flexible, not customizable and not suitable for the requirement that some projects need to cache specific resources. In order to solve the above problem, a first embodiment of the present invention provides an offline cache loading method.
Referring to fig. 2, fig. 2 is a flowchart of an offline cache loading method according to a first embodiment of the present invention. The off-line cache loading method comprises the following specific steps:
step S10: the terminal equipment acquires a network resource loading request, wherein the network resource loading request comprises a uniform resource locator of a corresponding resource.
Step S20: and the terminal equipment searches the resources corresponding to the uniform resource locator in the memory.
Step S30: and if the resources are not searched in the memory, the terminal equipment searches the resources in an external memory.
Step S40: and if the resources are searched in the external memory, the terminal equipment loads the resources into the memory.
For step S10, namely: the terminal equipment acquires a network resource loading request, wherein the network resource loading request comprises a uniform resource locator of a corresponding resource. The terminal device may be a smart phone, a personal computer, a server or other computing processing device with an iOS operating system installed. The network resource loading request is a request encapsulated by the iOS system when the iOS system needs to acquire resources from a network, and stores all data sent to the network server by the iOS system, including an NSURL object, a request method, a request header, a request body and the like. The Uniform Resource Locator (URL) is a compact representation of the location and access method of a Resource available on the internet, and is an address of a standard Resource on the internet, and each file on the internet has a unique URL, which contains information indicating the location of the file and how the browser should handle it.
After the function completes the secondary encapsulation on the network resource loading request to obtain the secondary encapsulation request, step S20 and step S30 should be executed, that is, the cache corresponding to the secondary encapsulation request is searched in the memory and the external storage. Optionally, the searching may be performed through an NSURLCache protocol, and the cache resource corresponding to the secondary encapsulation request is identified and acquired through the NSURLCache protocol, and the acquired resource is encapsulated into an nscachurlresponse variable.
Step S40 should be performed next, namely: and if the resources are searched in the external memory, the terminal equipment loads the resources into the memory. Optionally, the specific step of step S40 may be: an initWithRequest, cachedResponse and a client of the NSURLProtocol protocol process the NSCachedURLResponse variable to assemble a new NSCachedURLResponse variable, wherein the NSCachedURLResponse variable comprises cache resources corresponding to the network resource loading request, and then the resources are loaded into a memory.
For step S10, the network resource load request is NSURLRequest, and before step S20 is completed, it needs to determine whether the protocol needs to intercept the network resource load request NSURLRequest through a canInitWithRequest function.
The embodiment also provides a response judgment of the network resource loading request in the interception judgment step. Referring to fig. 3, fig. 3 shows a flow of the interception judging step, and the specific steps of the interception judging step are as follows:
step S11: and the terminal processing equipment determines that the resource belongs to the resource needing to be intercepted according to the network resource loading request.
Step S12: the terminal processing equipment determines that the network resource loading request does not belong to a secondary packaging request based on the parameter flag bit of the network resource loading request, wherein the secondary packaging request is a request after secondary packaging is carried out through a canonical request ForRequest function in the NSURLProtocol protocol.
It should be understood that, the cacheable resource type specified by the network framework protocol of the existing iOS system is flexible, not customizable, and not suitable for the requirement of some projects that require caching specific resources, so in addition to the general interception mechanism, the offline cache loading method of this embodiment further includes a custom interception mechanism. Generally, a generic interception mechanism generally intercepts resources by a resource suffix name and a MIME type, such as the MIME type corresponding to the following common file types: "jpg, image/jpeg", "bmp, image/bmp", "png, image/png", "tiff, image/tiff", "svg, image/svg + xml", "wma, audio/x-ms-wma", "wav, audio/x-wav", "wmv, video/x-ms-wmv", "zip, application/zip", "doc, application/msword" and "txt, text/in", etc., where the network resource loading request for the type of resource includes the universal character string.
In order to identify the processing type of the network resource loading request belonging to the custom interception mechanism or the general interception mechanism, the specific step of judging that the custom interception mechanism or the general interception mechanism should be adopted may be: judging whether the network resource loading request contains a specific character string or not; if yes, executing the steps of searching resources corresponding to the uniform resource locator in the memory to package the resources and finish loading according to a startLoading function; if not, according to the canInitWithrequest, executing the step of searching the resources corresponding to the uniform resource locator in the memory to package and complete loading the resources according to the function.
For the custom interception mechanism: aiming at the step S11, when the network resource loading request belongs to the processing type of the user-defined interception mechanism, judging whether the network resource loading request belongs to the user-defined protocol according to the value returned by request.rul in the canInitWithrequest function (the same way as judging whether the user-defined interception mechanism is adopted), and if so, judging that the resource needs to be intercepted; aiming at the step S12, whether the network resource loading request belongs to the secondary packaging request is determined by judging the parameter flag bit of the network resource loading request, and when the parameter flag bit is 'ECPURLPROTOCOL HandleDKey', the network resource loading request belongs to the secondary packaging request.
For the generic interception mechanism: for step S11, when the network resource loading request belongs to the processing type of the general interception mechanism, determining whether interception is required according to the network resource loading request; for step S12, it is determined whether the network resource loading request belongs to a secondary encapsulation request by determining a parameter flag of the network resource loading request, where the network resource loading request is a secondary encapsulation request when the parameter flag is "ECPRequestHandledKey".
In the embodiment, by dividing the custom interception mechanism and the general interception mechanism, the application program can cache more types of resources under the network framework of the iOS system, and the application range of the cache is improved.
Further, after step S10 is executed, in order to obtain the resource corresponding to the network resource loading request through the NSURLCache protocol, the following steps are also executed:
step S13: and the terminal processing equipment carries out secondary packaging on the network resource loading request through a canonicalcalatForRequest function to obtain a secondary packaging request.
After completing the resource search in step S20 and step S30, if the resource is still likely to be called, the resource may be cached through a memory, and the specific steps include: the terminal processing equipment judges whether the residual memory space of the memory can cache the resources or not; if so, the terminal processing equipment caches the resource in the memory; if not, the terminal processing equipment caches the resources in the external memory.
It should be understood that, in the actual cache reading, there is certainly a case that there is no corresponding resource in both the internal memory and the external memory, and in this case, the offline cache loading method provided by this embodiment will call the nsurconnection/nsursursion function to directly load the resource from the network. Further, in order to prevent the resource loaded from the network from entering the cache flow again, a parameter flag bit needs to be added to the secondary encapsulation request, where the parameter flag bit corresponds to a custom interception mechanism "ecpurl protocol handleedkey" and the corresponding general interception mechanism "ecprequesthandleedkey". And then packaging the finally obtained resources into NSURLResponse to finish loading (corresponding to a custom interception mechanism), or packaging the resources into NSCachedURLResponse and transmitting the NSURLResponse to a NSURLProtocol protocol until loading is finished (corresponding to a general interception mechanism).
In the offline cache loading method provided by this embodiment, after the iOS system acquires the network resource loading request through the NSURLCache protocol, resources corresponding to the network resource loading request are sequentially searched in the memory and the external storage, and the resources are directly loaded after being searched, so that the cache utilization rate and the resource acquisition speed during program operation are improved, and the problem that some application programs need to be cached again after exiting is solved. Meanwhile, the offline cache loading method also aims at two cache loading schemes, namely a user-defined interception mechanism and a general interception mechanism, of the iOS system, can perform network request interception and cache loading on a protocol defined by a developer or a standard HTTP protocol, and solves the problems that cacheable resources specified by an iOS network framework protocol are too few in types, cannot be customized and cannot meet the requirement that some application programs need to cache some specific resources.
Second embodiment
In order to cooperate with the offline cache loading method provided in the first embodiment of the present invention, a second embodiment of the present invention further provides an offline cache loading apparatus 100.
Referring to fig. 4, fig. 4 is a block diagram of an offline cache loading apparatus according to a second embodiment of the present invention.
The offline cache loading apparatus 100 includes a network resource loading request obtaining module 110, a resource searching module 120, and a resource loading module 130.
A network resource loading request obtaining module 110, configured to obtain a network resource loading request, where the network resource loading request includes a uniform resource locator of a corresponding resource.
The resource searching module 120 is configured to search a resource corresponding to the uniform resource locator in a memory or an external storage.
A resource loading module 130, configured to load the resource into the memory when the resource is searched in the external storage.
Further, the offline cache loading apparatus 100 may include an intercepting module 140, where the intercepting module 140 includes an intercepting judgment unit and a secondary encapsulation judgment unit. The interception judging unit is used for determining that the resource belongs to the resource needing to be intercepted according to the network resource loading request. The secondary packaging judging unit is used for determining that the network resource loading request does not belong to a secondary packaging request based on the parameter flag bit of the network resource loading request, wherein the secondary packaging request is a request after secondary packaging is carried out through a canonical RequestForRequest (NICACONICLE) function in the NSURLProtocol protocol.
It can be clearly understood by those skilled in the art that, for convenience and simplicity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method, and redundant description is not repeated here.
Third embodiment
In order to be able to implement the step counting method described above, a third embodiment of the present invention provides a computing device 200. Referring to fig. 5, fig. 5 is a block diagram of a computing device according to a third embodiment of the present invention.
The computing device 200 may include the offline cache loading apparatus 100, a memory 201, a storage controller 202, a processor 203, a peripheral interface 204, an input-output unit 205, an audio unit 206, a display unit 207, and a bus for connection of the units. The computing device 200 comprises the terminal processing device in the first embodiment of the invention.
The memory 201, the memory controller 202, the processor 203, the peripheral interface 204, the input/output unit 205, the audio unit 206, and the display unit 207 are electrically connected to each other directly or indirectly through a bus, so as to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines. The offline cache loading apparatus 100 includes at least one software functional module, which may be stored in the memory 201 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the offline cache loading apparatus 100. The processor 203 is configured to execute an executable module stored in the memory 201, such as a software functional module or a computer program included in the offline cache loading apparatus 100.
The Memory 201 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like. The memory 201 is used for storing a program, the processor 203 executes the program after receiving an execution instruction, and the method executed by the server defined by the flow process disclosed in any of the foregoing embodiments of the present invention may be applied to the processor 203, or implemented by the processor 203.
The processor 203 may be an integrated circuit chip having signal processing capabilities. The Processor 203 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor 203 may be any conventional processor or the like.
The peripheral interface 204 couples various input/output devices to the processor 203 as well as to the memory 201. In some embodiments, the peripheral interface 204, the processor 203, and the memory controller 202 may be implemented in a single chip. In other examples, they may be implemented separately from the individual chips.
The input and output unit 205 is used for providing input data for a user to realize the interaction of the user with the server (or the local terminal). The input/output unit 205 may be, but is not limited to, a mouse, a keyboard, and the like.
The audio unit 206 provides an audio interface to the user, which may include one or more microphones, one or more speakers, and audio circuitry.
The display unit 207 provides an interactive interface (e.g., a user interface) between the computing device 200 and a user or for displaying image data to a user reference. In this embodiment, the display unit 207 may be a liquid crystal display or a touch display. In the case of a touch display, the display can be a capacitive touch screen or a resistive touch screen, which supports single-point and multi-point touch operations. Supporting single-point and multi-point touch operations means that the touch display can sense touch operations from one or more locations on the touch display at the same time, and the sensed touch operations are sent to the processor 203 for calculation and processing.
It will be appreciated that the configuration shown in FIG. 5 is merely illustrative and that the computing device 200 may include more or fewer components than shown in FIG. 5 or may have a different configuration than shown in FIG. 5. The components shown in fig. 5 may be implemented in hardware, software, or a combination thereof.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working process of the apparatus described above may refer to the corresponding process in the foregoing method, and will not be described in too much detail herein.
In summary, embodiments of the present invention provide an offline cache loading method and an offline cache loading device, where the offline cache loading method searches whether cached resources exist in a memory and an external storage, and directly loads the resources when a cache of the resources exists in the memory or the external storage, so as to implement simultaneous caching of the resources in the memory and the external storage, increase an amount of resources that can be cached offline, and enable an application program to load a cache from a local external storage even if the application program is restarted. Meanwhile, after a network resource loading request is obtained, whether cached resources exist in the memory is searched first, whether cached resources exist in the external storage is searched, and auxiliary caching is performed through external storage, so that the utilization rate of the memory in the system is reduced, and the cache loading speed and the cache utilization rate are effectively improved.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented by other functions. The apparatus embodiments described above are merely illustrative, and for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, 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 and/or flowchart illustration, and combinations of blocks in the block diagrams and/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.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention or a part thereof which substantially contributes to the prior art may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

Claims (8)

1. An offline cache loading method, characterized in that the offline cache loading method comprises:
acquiring a network resource loading request, wherein the network resource loading request comprises a uniform resource locator of a corresponding resource;
determining that the resource belongs to the resource needing to be intercepted according to the network resource loading request through a general interception mechanism and a custom interception mechanism, wherein the method comprises the following steps: when the network resource loading request belongs to the processing type of the custom interception mechanism, judging whether the network resource loading request belongs to a custom protocol according to a canInitWithRequest which is a value returned by request.rul in a function, if so, intercepting the resource, wherein the universal interception mechanism intercepts the resource through a resource suffix and an MIME type;
determining that the network resource loading request does not belong to a secondary packaging request based on a parameter flag bit of the network resource loading request, wherein the secondary packaging request is a request obtained after secondary packaging is carried out through a canonical requestForRequest function in the NSURLProtocol protocol;
performing secondary packaging on the network resource loading request through a canonica RequestForRequest function to obtain a secondary packaging request;
searching the resources corresponding to the uniform resource locator in the memory;
if the resources are not searched in the memory, searching the resources in an external memory;
and if the resources are searched in the external memory, loading the resources into the memory.
2. The offline cache loading method according to claim 1, wherein after determining that the network resource loading request does not belong to a secondary encapsulation request based on the parameter flag bit of the network resource loading request, the offline cache loading method further comprises:
performing secondary packaging on the network resource loading request through a canonicalRequestForRequest function to obtain a secondary packaging request;
based on the secondary packaging request, adopting an NSURLCache protocol to search the resources corresponding to the uniform resource locators in the memory; if the resources are not searched in the memory, searching the resources in an external memory; and loading the resource into the memory if the resource is searched in the external memory.
3. The offline cache loading method according to claim 2, wherein after said obtaining the network resource loading request and before said determining that the resource belongs to the resource that needs to be intercepted according to the network resource loading request, the offline cache loading method further comprises:
judging whether the network resource loading request contains a specific character string or not;
if yes, searching the resources corresponding to the uniform resource locators in the memory according to a startLoading function; if the resources are not searched in the memory, searching the resources in an external memory; if the resource is searched in the external memory, loading the resource into the memory;
if not, according to the canInitWithrequest, executing the function to search the resources corresponding to the uniform resource locator in the memory; if the resources are not searched in the memory, searching the resources in an external memory; and loading the resource into the memory if the resource is searched in the external memory.
4. The method of claim 2, wherein after the loading the resource into the memory, the method further comprises:
and adding a parameter flag bit to the secondary packaging request.
5. The offline cache loading method according to claim 1, wherein after said loading said resource into said memory, said offline cache loading method further comprises:
judging whether the residual memory space of the memory can cache the resources or not;
if so, caching the resources in the memory; if not, caching the resources in the external memory.
6. An offline cache loading apparatus, wherein the offline cache loading apparatus comprises:
a network resource loading request obtaining module, configured to obtain a network resource loading request, where the network resource loading request includes a uniform resource locator of a corresponding resource;
an interception template, the interception template comprising: an interception judging unit and a secondary packaging judging unit;
the interception judging unit is used for determining that the resource belongs to the resource needing to be intercepted according to the network resource loading request through a general interception mechanism and a user-defined interception mechanism;
the interception judging unit is also used for judging whether the network resource loading request belongs to a self-defined protocol according to a value returned by request in a CanInitWithrequest function, if so, the resource needs to be intercepted, wherein the universal interception mechanism intercepts the resource through a resource suffix name and an MIME type;
the secondary packaging judging unit is used for determining that the network resource loading request does not belong to a secondary packaging request based on the parameter flag bit of the network resource loading request, wherein the secondary packaging request refers to a request after secondary packaging is carried out through a canonical request ForRequest in an NSURLProtocol protocol;
the secondary packaging judging unit is also used for carrying out secondary packaging on the network resource loading request through a canonica RequestForRequest function to obtain a secondary packaging request;
the resource searching module is used for searching resources corresponding to the uniform resource locator in a memory or an external memory;
and the resource loading module is used for loading the resource into the memory when the resource is searched in the external memory.
7. A computing device comprising a bus, and a processor coupled to the bus, a memory for storing computer instructions, the processor being configured to execute the computer instructions to perform the method of any of claims 1 to 5 when executing the computer instructions.
8. A storage medium having stored thereon computer program instructions which, when read and executed by a processor, perform the steps of the method of any one of claims 1 to 5.
CN201810760618.6A 2018-07-11 2018-07-11 Offline cache loading method and device Active CN108846141B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810760618.6A CN108846141B (en) 2018-07-11 2018-07-11 Offline cache loading method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810760618.6A CN108846141B (en) 2018-07-11 2018-07-11 Offline cache loading method and device

Publications (2)

Publication Number Publication Date
CN108846141A CN108846141A (en) 2018-11-20
CN108846141B true CN108846141B (en) 2022-05-24

Family

ID=64197076

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810760618.6A Active CN108846141B (en) 2018-07-11 2018-07-11 Offline cache loading method and device

Country Status (1)

Country Link
CN (1) CN108846141B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111159238A (en) * 2019-12-26 2020-05-15 厦门市美亚柏科信息股份有限公司 Cache file evidence obtaining method based on IOS (input/output system), terminal equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101075241A (en) * 2006-12-26 2007-11-21 腾讯科技(深圳)有限公司 Method and system for processing buffer
CN103686684A (en) * 2012-09-20 2014-03-26 腾讯科技(深圳)有限公司 Offline cache method and device
CN105760405A (en) * 2014-12-19 2016-07-13 阿里巴巴集团控股有限公司 Methods and devices for obtaining network resource for loading web page and method and device for caching network resource
CN106372109A (en) * 2016-08-19 2017-02-01 中国银联股份有限公司 Internet resource file caching method and apparatus
CN107203555A (en) * 2016-03-17 2017-09-26 阿里巴巴集团控股有限公司 Page loading processing method and device
CN107332843A (en) * 2017-07-01 2017-11-07 华泰证券股份有限公司 IOS network requests intercept forwarding cache method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9936041B2 (en) * 2015-02-11 2018-04-03 International Business Machines Corporation Smart cache for offline data availability
CN105760232B (en) * 2016-02-19 2019-03-22 四川长虹电器股份有限公司 Offline cache method and system for IOS application

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101075241A (en) * 2006-12-26 2007-11-21 腾讯科技(深圳)有限公司 Method and system for processing buffer
CN103686684A (en) * 2012-09-20 2014-03-26 腾讯科技(深圳)有限公司 Offline cache method and device
CN105760405A (en) * 2014-12-19 2016-07-13 阿里巴巴集团控股有限公司 Methods and devices for obtaining network resource for loading web page and method and device for caching network resource
CN107203555A (en) * 2016-03-17 2017-09-26 阿里巴巴集团控股有限公司 Page loading processing method and device
CN106372109A (en) * 2016-08-19 2017-02-01 中国银联股份有限公司 Internet resource file caching method and apparatus
CN107332843A (en) * 2017-07-01 2017-11-07 华泰证券股份有限公司 IOS network requests intercept forwarding cache method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
NSURLProtocol 离线缓存;3行代码;《https://blog.csdn.net/jiang314/article/details/53894821》;20161227;第1页 *

Also Published As

Publication number Publication date
CN108846141A (en) 2018-11-20

Similar Documents

Publication Publication Date Title
CN107798108B (en) Asynchronous task query method and device
RU2608668C2 (en) System and method for control and organisation of web-browser cache for offline browsing
US10191856B2 (en) Method of managing web browser cache size using logical relationships and clustering
US8126859B2 (en) Updating a local version of a file based on a rule
US11010215B2 (en) Recommending applications based on call requests between applications
WO2017114206A1 (en) Method and device for processing short link, and short link server
US9590859B2 (en) Discovering resources of a distributed computing environment
CN105740330B (en) Method and device for displaying data in paging mode
US20170153909A1 (en) Methods and Devices for Acquiring Data Using Virtual Machine and Host Machine
US20230367829A1 (en) Indexing Native Application Data
CN112580315A (en) Webpage table display method and device, terminal equipment and medium
CN108846141B (en) Offline cache loading method and device
CN111078697B (en) Data storage method and device, storage medium and electronic equipment
WO2018057401A1 (en) Preserve input focus while scrolling in a virtualized dataset
US9430530B1 (en) Reusing database statistics for user aggregate queries
CN113849125B (en) CDN server disk reading method, device and system
US10684898B2 (en) In-line event handlers across domains
CN114741165A (en) Processing method of data processing platform, computer equipment and storage device
WO2018075009A1 (en) Response caching
CN108804195B (en) Page display method and device, server and client
CN112579282A (en) Data processing method, device, system and computer readable storage medium
US10037242B2 (en) Failure detection in a processing system
CN110753136A (en) Domain name resolution method, device, equipment and storage medium
CN112988592B (en) Code detection method, device, equipment and storage medium
US11210357B2 (en) Automatically categorizing bookmarks from customized folders and implementation based on web browsing activity

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