The content of the invention
The purpose of the embodiment of the present application is a kind of method for realizing Web offline storages of offer, device and electronic equipment, with
Realize both can according to user specify determine offline storage mode, can also the not specified offline storage mode of user situation
Under, it is the adaptively selected offline storage mode of user.
To reach above-mentioned purpose, on the one hand, the embodiment of the present application provides a kind of method for realizing Web offline storages, bag
Include following steps:
First interface object is initialized on startup;
Judge whether the first interface object after initialization is designated particular memory driving;
If particular memory driving is designated, after particular memory driving is initialized, the particular memory is driven
Native interface be mapped to first interface;
If not specified particular memory driving, according to current browser environment, is selected from default storage driving set
Optimal storage driving is selected, and after the optimal storage driving is initialized, the native interface that the optimal storage is driven maps
Into the first interface;
When needing to carry out Web offline storages, the first interface is called to be handled.
On the other hand, the embodiment of the present application additionally provides a kind of device for realizing Web offline storages, including:
Object initialization module, for initializing first interface object according to default building method on startup;
Driving confirms module, for judging whether the first interface object after initialization is designated particular memory driving;
First package module,, will after particular memory driving is initialized for when particular memory driving is designated
The native interface of the particular memory driving is mapped to first interface;
Second package module, for when not specified particular memory drives, according to current browser environment, being deposited from default
Selection optimal storage driving in storage driving set, and after the optimal storage driving is initialized, the optimal storage is driven
Native interface be mapped to the first interface;
Interface interchange module, for when needing to carry out Web offline storages, calling the first interface to be handled.
Another further aspect, the embodiment of the present application additionally provides a kind of electronic equipment, including:
Processor;
Memory for storing executable instruction;
Wherein, the processor is configured as:
First interface object is initialized according to default building method on startup;
Judge whether the first interface object after initialization is designated particular memory driving;
If particular memory driving is designated, after particular memory driving is initialized, the particular memory is driven
Native interface be mapped to first interface;
If not specified particular memory driving, according to current browser environment, is selected from default storage driving set
Optimal storage driving is selected, and after the optimal storage driving is initialized, the native interface that the optimal storage is driven maps
Into the first interface;
When needing to carry out Web offline storages, the first interface is called to be handled.
The technical scheme provided from above the embodiment of the present application, the embodiment of the present application is in initialization first interface object
Afterwards, first judge whether the first interface object after initialization is designated particular memory driving;If particular memory is designated
Driving, then after particular memory driving is initialized, first interface is mapped to by the native interface that particular memory drives;If not
Particular memory driving is specified, then according to current browser environment, optimal storage driving is selected from default storage driving set,
And after the optimal storage driving is initialized, the native interface that optimal storage drives is mapped to first interface;When need into
During row Web offline storages, first interface is called to be handled.Therefore, the embodiment of the present application is realized can both refer to according to user
Surely determine offline storage mode, can also in the case of the not specified offline storage mode of user, be user it is adaptively selected from
Line storage mode, so as to improve Consumer's Experience.
Embodiment
In order that those skilled in the art more fully understand the technical scheme in the application, it is real below in conjunction with the application
The accompanying drawing in example is applied, the technical scheme in the embodiment of the present application is clearly and completely described, it is clear that described implementation
Example only some embodiments of the present application, rather than whole embodiments.Based on the embodiment in the application, this area is common
The every other embodiment that technical staff is obtained under the premise of creative work is not made, should all belong to the application protection
Scope.
With reference to shown in Fig. 1, the method for realizing Web offline storages of the embodiment of the present application comprises the following steps:
S101, on startup initialization first interface object.
In the embodiment of the present application, described starts the startup that can be applied for Web.Described Web applications can be chat
Room (chat room), forum (forum), BBS(Bulletin Board System) (BBS, Bulletin Board System), WebQQ, Web
Mailbox, Web mapping softwares or Web game etc..
In the application one embodiment, described startup for example can be the User logs in Web applications of Web applications, example
As WebQQ user logs in WebQQ by browser.In one embodiment of the application, described startup can also be WebQQ
User opens Web applications by browser, for example, the homepage of Web applications is opened by browser.
In the embodiment of the present application, the initialization first interface object is the process that first interface object assigns initial value.
In embodiments herein, the first interface object is according to the construction stated in third party's class libraries by Web application providers
What method was created, the first interface object can call first interface, to realize the operation of Web offline storages correlation.Wherein, it is right
For a class, typically all definition has building method, to complete the initialization of object;Can be certainly when class instantiates an object
It is dynamic to call building method.Third party's class libraries is the reusable type set of an object-oriented, and these types for example can be with
Including interface and realize class.In the application one embodiment, such as one Storage class libraries can include following interface and
Realize class:
Storage.get () // be used to obtain particular memory record according to key (key assignments)
Storage.set//be used to set particular memory to record
Storage.remove//be used to remove stored record according to key
Storage.clear//be used to remove all stored records
Storage.has is used to judge whether that particular memory is recorded according to key, returns to true/false
Storage.forEach is used for all stored records in searching loop driving, and performs certain specific readjustment letter successively
Number (incoming through parameter)
In the embodiment of the present application, third party's class libraries can be obtained from third-party server, such as shown in Fig. 2, and third party is opening
Distribute into after storage class libraries, can be deposited on the server of one's own side, so that user (is generally the service of Web applications here
Provider) use.In the other embodiment of the application, third party can also be developed the class libraries completed and deposit in and be entrusted by it
On the other side Entrust Server of support.
S102, judge initialization after first interface object whether be designated particular memory driving.
In the application one embodiment, parameter can be specified according to the pressure of the first interface object after initialization
(forcibly parameters), judges whether the first interface object after initialization is designated particular memory driving.For example when
When forcibly parameters are true, then illustrate that first interface object is forced to specify the driving of some particular memory.It is corresponding, when
When forcibly parameters are false, then illustrate that first interface object is not forced to specify any storage driving.It the above is only citing
Illustrate, in the application other embodiment, also judge by other means.
For the service provider that Web is applied, the purpose for specifying the driving of some particular memory is forced to be, sometimes by force
Making the storage driving specified may be more preferable than the effect of automatic adaptation, such as when storing small lot data, forcing to specify makes
It is substantially more efficient than the indexedDB of automatic adaptation with localStorage.Therefore, when the Web service providers applied wish
Hope that the embodiment of the present application is provided for facility when independently selecting storage driving according to actual demand.Therefore, with
The example that localForage directly returns to an automatic adaptation pattern is different, and the embodiment of the present application realizes the initialization of example
The Web service providers of application are given, the service provider applied by Web builds example by new instructions, this is just many examples
Structure provide may.Particularly when a web application is excessively complicated, there are a variety of different data types and storage demand,
Different adaptation patterns is used for different data, multiple different examples directly can be constructed by new instructions.
In the application one embodiment, the storage that the particular memory is driven in default storage driving set is driven
It is dynamic.It is corresponding, if the particular memory driving were designated, and current browser environment would not support the particular memory to drive
It is dynamic, then according to current browser environment, from the remaining storage driving of storage driving set, selection optimal storage driving.
Wherein, the storage driving in the storage driving set can for example include:IndexedDB drives and LocalStorage drives
It is dynamic.
If S103a, particular memory driving is designated, after particular memory driving is initialized, specific deposited described
The native interface of storage driving is mapped to first interface.
In the embodiment of the present application, the first interface can be the unified interface for the otherness for shielding different storage drivings
Or general-purpose interface, the first interface can be provided in the way of asynchronous chain type access key-value pair (key/value) external interface tune
With.
When confirming that first interface object is forced to specify the driving of some particular memory (such as LocalStorage),
Particular memory driving can directly be initialized.Initialize the particular memory driving after, it is described by particular memory drive it is primary
Interface mappings can specifically include into first interface:
By predefined empty first interface, first interface of the native interface driven with the particular memory by encapsulation
Carry out unified interface mapping.In one exemplary embodiment of the application, native interface, which is mapped to first interface process, to be
The process of first interface encapsulation is carried out using the Promise patterns of asynchronism callback.Below, to " native interface encapsulation " and " unification
Interface mappings " are illustrated respectively.Described " native interface encapsulation " is understood that:Such as to the encapsulation of set interfaces,
During using localStorage as storage driving, directly invoking its setItem interface just can be with;And using indexedDB as
, it is necessary to first open an affairs during storage driving, create after a table object, recall put interfaces, encapsulation work is exactly to pack
Above-mentioned work.By taking set interfaces as an example, described " unified interface mapping " is exactly by the both above set interfaces for driving and encapsulating
Predefined unified interface is all uniformly mapped to, so when calling unified interface, what is actually called is exactly behind
The set interfaces that localStorage and inndexedDB was encapsulated, such interface docking operation is exactly unified interface mapping.
If S103b, not specified particular memory drive, according to current browser environment, from default storage driving collection
Optimal storage driving is selected in conjunction, and after optimal storage driving is initialized, primary connect what the optimal storage drove
Mouth is mapped to the first interface.
In the embodiment of the present application, the current browser environment, i.e., the essential information of currently used browser is for example browsed
Device title and version, which storage driving etc. supported.Wherein, current browser environment can be by calling current browser itself to carry
The API of confession is realized.
It is described according to current browser environment in the application one embodiment, selected from default storage driving set
Optimal storage driving is selected, can be included:
Whether detection current browser environment supports the first storage driving in the storage driving set;If supporting institute
The first storage driving is stated, then it is optimal driving to confirm first storage driving;
If not supporting first storage driving, whether detection current browser environment supports the storage driving collection
The second storage driving in conjunction;
If supporting second storage driving, it is optimal driving to confirm first storage driving;
If not supporting second storage driving, mistake of dishing out.
Wherein, first storage driving can include IndexedDB drivings, and second storage driving can include
LocalStorage drives.Due to clearly having discarded WebSQL drivings in HTML5 specifications, although currently may some browsers
WebSQL drivings also are being supported, but in edition upgrading of the future with browser, the branch driven to WebSQL may be abandoned at any time
Hold, it is possible to some offline storage data based on WebSQL drivings can be caused unavailable.And the embodiment of the present application is discarded
The support driven to WebSQL, and it is comprehensive use LocalStorage and IndexedDB, this can substantially meet main flow and browse
Numeral in offline storage demand (such as shown in table 1 below) under device, table 1 is supported minimum browser version, and can be with
Simplify the code of Web applications.
Table 1
Driving |
Chorme |
Firefox(Gecko) |
IE |
Opera |
Safari(webkit) |
LocalStorage |
4 |
3.5 |
8 |
10.5 |
4 |
IndexedDB |
23、24(webkit) |
10、16(moz) |
10 |
15 |
7.1 |
S104, when need carry out Web offline storages when, call the first interface to be handled.
Specific which data are done with how offline storage is operated, the service provider that can be applied by Web applies according to web
Particular demands do programmed instruction preset, these programmed instruction are typically JS (JavaScript) script.For final use
For family (using the user that web is applied by browser), when the interaction shape of progress web applications is, loaded by browser
And above-mentioned JS scripts are performed, operated with doing corresponding storage according to the instruction of default offline storage.
Although procedures described above flow includes the multiple operations occurred with particular order, it should however be appreciated that understand,
These processes can include more or less operations, and these operations can sequentially be performed or performed parallel (such as using parallel
Processor or multi-thread environment).
With reference to shown in Fig. 3, the device for realizing Web offline storages of the embodiment of the present application, including:
Object initialization module 31, for initializing first interface object according to default building method on startup;
Driving confirms module 32, is driven for judging whether the first interface object after initialization is designated particular memory
It is dynamic;
First package module 33, for when particular memory driving is designated, after particular memory driving is initialized,
The native interface that the particular memory is driven is mapped to first interface;
Second package module 34, for when not specified particular memory drives, according to current browser environment, from default
Optimal storage driving is selected in storage driving set, and after the optimal storage driving is initialized, the optimal storage is driven
Dynamic native interface is mapped to the first interface;
Interface interchange module 35, for when needing to carry out Web offline storages, calling the first interface to be handled.
The device for realizing Web offline storages of the embodiment of the present application is corresponding with above-mentioned embodiment illustrated in fig. 1, therefore, relevant
In the detailed description of the device for realizing Web offline storages of the embodiment of the present application, above-mentioned embodiment illustrated in fig. 1 is referred to, herein
Repeat no more.
Fig. 4 shows the structured flowchart of the electronic equipment of the embodiment of the application.It refer to shown in Fig. 4, in hardware layer
Face, the electronic equipment includes processor, internal bus, network interface, internal memory and nonvolatile memory, and bag is also possible to certainly
Include the hardware required for other business.It is right into internal memory that processor reads corresponding computer program from nonvolatile memory
After run, formed on logic level and realize the devices of Web offline storages.Certainly, in addition to software realization mode, the application
It is not precluded from other implementations, such as the mode of logical device or software and hardware combining etc., that is to say, that following processing stream
The executive agent of journey is not limited to each logic unit or hardware or logical device.Wherein, the processor by with
It is set to:
First interface object is initialized according to default building method on startup;
Judge whether the first interface object after initialization is designated particular memory driving;
If particular memory driving is designated, after particular memory driving is initialized, the particular memory is driven
Native interface be mapped to first interface;
If not specified particular memory driving, according to current browser environment, is selected from default storage driving set
Optimal storage driving is selected, and after the optimal storage driving is initialized, the native interface that the optimal storage is driven maps
Into the first interface;
When needing to carry out Web offline storages, the first interface is called to be handled.
The electronic equipment of the embodiment of the present application is corresponding with above-mentioned embodiment illustrated in fig. 1, therefore, is related to the embodiment of the present application
Electronic equipment detailed description, refer to above-mentioned embodiment illustrated in fig. 1, will not be repeated here.
In the 1990s, for a technology improvement can clearly distinguish be on hardware improvement (for example,
Improvement to circuit structures such as diode, transistor, switches) or software on improvement (for the improvement of method flow).So
And, with the development of technology, the improvement of current many method flows can be considered as directly improving for hardware circuit.
Designer nearly all obtains corresponding hardware circuit by the way that improved method flow is programmed into hardware circuit.Cause
This, it cannot be said that the improvement of a method flow cannot be realized with hardware entities module.For example, PLD
(Programmable Logic Device, PLD) (such as field programmable gate array (Field Programmable Gate
Array, FPGA)) it is exactly such a integrated circuit, its logic function is determined by user to device programming.By designer
Voluntarily programming comes a digital display circuit " integrated " on a piece of PLD, without asking chip maker to design and make
Special IC chip.Moreover, nowadays, substitution manually makes IC chip, and this programming is also used instead mostly " patrols
Volume compiler (logic compiler) " software realizes that software compiler used is similar when it writes with program development,
And the source code before compiling also write by handy specific programming language, this is referred to as hardware description language
(Hardware Description Language, HDL), and HDL is also not only a kind of, but have many kinds, such as ABEL
(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description
Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL
(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby
Hardware Description Language) etc., VHDL (Very-High-Speed are most generally used at present
Integrated Circuit Hardware Description Language) and Verilog.Those skilled in the art also should
This understands, it is only necessary to slightly programming in logic and be programmed into method flow in integrated circuit with above-mentioned several hardware description languages,
The hardware circuit for realizing the logical method flow can be just readily available.
Controller can be implemented in any suitable manner, for example, controller can take such as microprocessor or processing
Device and storage can by the computer of the computer readable program code (such as software or firmware) of (micro-) computing device
Read medium, gate, switch, application specific integrated circuit (Application Specific Integrated Circuit,
ASIC), the form of programmable logic controller (PLC) and embedded microcontroller, the example of controller includes but is not limited to following microcontroller
Device:ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, are deposited
Memory controller is also implemented as a part for the control logic of memory.It is also known in the art that except with
Pure computer readable program code mode is realized beyond controller, can be made completely by the way that method and step is carried out into programming in logic
Obtain controller and come real in the form of gate, switch, application specific integrated circuit, programmable logic controller (PLC) and embedded microcontroller etc.
Existing identical function.Therefore this controller is considered a kind of hardware component, and various for realizing to including in it
The device of function can also be considered as the structure in hardware component.Or even, can be by for realizing that the device of various functions is regarded
For that not only can be the software module of implementation method but also can be the structure in hardware component.
Device, module or unit that above-described embodiment is illustrated, can specifically be realized, Huo Zheyou by computer chip or entity
Product with certain function is realized.It is a kind of typically to realize that equipment is computer.Specifically, computer for example can be individual
People's computer, laptop computer, cell phone, camera phone, smart phone, personal digital assistant, media player, navigation
Any equipment in equipment, electronic mail equipment, game console, tablet PC, wearable device or these equipment
Combination.
For convenience of description, it is divided into various units during description apparatus above with function to describe respectively.Certainly, this is being implemented
The function of each unit can be realized in same or multiple softwares and/or hardware during application.
The present invention be with reference to method according to embodiments of the present invention, device and computer program product flow chart and/or
Block diagram is described.It should be understood that can by each flow in computer program instructions implementation process figure and/or block diagram and/or
Square frame and the flow in flow chart and/or block diagram and/or the combination of square frame.These computer program instructions can be provided to arrive
All-purpose computer, special-purpose computer, the processor of Embedded Processor or other programmable data processing devices are to produce one
Machine so that produced by the instruction of computer or the computing device of other programmable data processing devices for realizing in stream
The device for the function of being specified in one flow of journey figure or multiple flows and/or one square frame of block diagram or multiple square frames.
These computer program instructions, which may be alternatively stored in, can guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory, which is produced, to be included referring to
Make the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one square frame of block diagram or
The function of being specified in multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that in meter
Series of operation steps is performed on calculation machine or other programmable devices to produce computer implemented processing, thus in computer or
The instruction performed on other programmable devices is provided for realizing in one flow of flow chart or multiple flows and/or block diagram one
The step of function of being specified in individual square frame or multiple square frames.
In a typical configuration, computing device includes one or more processors (CPU), input/output interface, net
Network interface and internal memory.
Internal memory potentially includes the volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only storage (ROM) or flash memory (flash RAM).Internal memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer-readable instruction, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase transition internal memory (PRAM), static RAM (SRAM), moved
State random access memory (DRAM), other kinds of random access memory (RAM), read-only storage (ROM), electric erasable
Programmable read only memory (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read-only storage (CD-ROM),
Digital versatile disc (DVD) or other optical storages, magnetic cassette tape, the storage of tape magnetic rigid disk or other magnetic storage apparatus
Or any other non-transmission medium, the information that can be accessed by a computing device available for storage.Define, calculate according to herein
Machine computer-readable recording medium does not include temporary computer readable media (transitory media), such as data-signal and carrier wave of modulation.
It should also be noted that, term " comprising ", "comprising" or its any other variant are intended to nonexcludability
Comprising so that process, method, commodity or equipment including a series of key elements are not only including those key elements, but also wrap
Include other key elements being not expressly set out, or also include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that wanted including described
Also there is other identical element in process, method, commodity or the equipment of element.
It will be understood by those skilled in the art that embodiments herein can be provided as method, device or computer program product.
Therefore, the application can be using the embodiment in terms of complete hardware embodiment, complete software embodiment or combination software and hardware
Form.Deposited moreover, the application can use to can use in one or more computers for wherein including computer usable program code
The shape for the computer program product that storage media is implemented on (including but is not limited to magnetic disk storage, CD-ROM, optical memory etc.)
Formula.
The application can be described in the general context of computer executable instructions, such as program
Module.Usually, program module includes performing particular task or realizes routine, program, object, the group of particular abstract data type
Part, data structure etc..The application can also be put into practice in a distributed computing environment, in these DCEs, by
Remote processing devices connected by communication network perform task.In a distributed computing environment, program module can be with
Positioned at including in the local and remote computer-readable storage medium including storage device.
Each embodiment in this specification is described by the way of progressive, identical similar portion between each embodiment
Divide mutually referring to what each embodiment was stressed is the difference with other embodiment.It is real especially for system
Apply for example, because it is substantially similar to embodiment of the method, so description is fairly simple, related part is referring to embodiment of the method
Part explanation.
Embodiments herein is the foregoing is only, the application is not limited to.For those skilled in the art
For, the application can have various modifications and variations.It is all any modifications made within spirit herein and principle, equivalent
Replace, improve etc., it should be included within the scope of claims hereof.