Data cache method, device, whole electronic equipment and storage mediumTechnical field
The embodiment of the present disclosure is related to computer application technology more particularly to a kind of data cache method, device, electronicsEquipment and storage medium.
Background technique
Currently, database is generally provided with data buffer storage mechanism.The local cache of database is generally used for storage userUsed data.Whether when receiving the data of user using request, can first check in local data base has user instituteData to be used, if so, can then be not necessarily to directly with the data of the data response user of local cache using request from numberAccording to library again pulling data, it on the one hand can alleviate the pressure of database, the access for being on the other hand enable to respond quickly user is askedIt asks.
But if the data of local data base have occurred and that change, and the update of the data of local cache is too late, then can leadCause the data in local cache and local data base inconsistent, that is, after data change can not be accessed in user by local cacheNew data, influence user experience.
Summary of the invention
The embodiment of the present disclosure provides data cache method, device, electronic equipment and the storage medium of a kind of database, withThe technical issues of solving the poor user experience caused by updating not in time local cache, guarantees local cache and local dataConsistency.
In a first aspect, the embodiment of the present disclosure provides a kind of data cache method, this method comprises:
When detecting the data altering event of local data base, the log information that local data base generates is obtained;
The log information is parsed, local cache is updated according to parsing result.
Second aspect, the embodiment of the present disclosure additionally provide a kind of data buffer storage device, which includes:
Log information obtains module, for obtaining local data when detecting the data altering event of local data baseThe log information that library generates;
Local cache update module updates local cache according to parsing result for parsing to the log information.
The third aspect, the embodiment of the present disclosure additionally provide a kind of electronic equipment, which includes:
One or more processing units;
Memory, for storing one or more programs;
When one or more of programs are executed by one or more of processing units, so that one or more of placesManage the method for data synchronization for the database that device is realized as described in any embodiment in the disclosure.
Fourth aspect, the embodiment of the present disclosure additionally provide a kind of computer readable storage medium, are stored thereon with computerProgram, the embodiment of the present disclosure, which additionally provides, to be realized when a kind of computer program is executed by processor such as any reality in the disclosureApply the data cache method of database described in example.
The technical solution of the embodiment of the present disclosure passes through the log information generated when data altering event to local data baseIt is parsed, since log information recording has the data information and data operation information of local data base, according to parsingAs a result the technical issues of updating local cache, solving the poor user experience caused by updating not in time local cache, not onlyIt can guarantee timely updating for local cache, also keep the consistency of local cache and local data.
Detailed description of the invention
Fig. 1 is a kind of flow diagram of data cache method provided by the embodiment of the present disclosure one;
Fig. 2 is a kind of flow diagram of data cache method provided by the embodiment of the present disclosure two;
Fig. 3 is a kind of optional example schematic of data cache method provided by the embodiment of the present disclosure two;
Fig. 4 is a kind of structural schematic diagram of data buffer storage device provided by the embodiment of the present disclosure three;
Fig. 5 is the structural schematic diagram of a kind of electronic equipment provided by the embodiment of the present disclosure four.
Specific embodiment
The disclosure is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouchedThe specific embodiment stated is used only for explaining the disclosure, rather than the restriction to the disclosure.It also should be noted that in order to justPart relevant to the disclosure is illustrated only in description, attached drawing rather than entire infrastructure.In following each embodiments, each embodimentIn simultaneously provide optional feature and example, each feature recorded in embodiment can be combined, form multiple optinal plans,The embodiment of each number should not be considered merely as to a technical solution.
Embodiment one
Fig. 1 is a kind of flow chart of data cache method provided by the embodiment of the present disclosure one, and the present embodiment is especially suitableThe case where timely updating under data interchange state to local cache, this method can be executed by data buffer storage device,The data buffer storage device can be configured at the data cache method in terminal or server for realizing the embodiment of the present disclosure.Such as figureShown in 1, the method for the present embodiment is specific can include:
S110, when detecting the data altering event of local data base, obtain local data base generate log information.
Illustratively, when detecting the data altering event of local data base, the log information of local data base is obtained,It may include: to obtain the log information of the local data base when detecting the local change operation of local data base data,Wherein, the local change operation may include the operation such as modification, write-in and/or deletion executed to local data base.
If local data base with there are data interchange, also can to the strange land data change of client database to client databaseThe data of local data base are had an impact.Therefore, when detecting the data altering event of local data base, local number is obtainedIt can also include: to obtain local data base when receiving the data to be synchronized of opposite end database transmissions according to the log information in libraryLog information.
It should be understood that the data to be synchronized of opposite end database transmissions may include through the opposite end change operation to client databaseData that are generated and needing to be synchronized to local data base.It wherein, may include to right to the opposite end change operation of client databaseThe operation such as modification performed by the data of client database, write-in and/or deletion.
Optionally, local data base can carry out data interchange with to client database by data duplication centre component, alsoIt is to say, local data base can control to receive the data to be synchronized of opposite end database transmissions by data duplication centre component.
In the embodiments of the present disclosure, the journal file that log information can be generated from local data base, can be used for recordingThe variation of the whole data flow of local data base one, while recording data information and data manipulation, can not only guarantee databaseExecute sequence, and can guarantee that data are not lost.Therefore, obtaining log information can get described in local data baseData information and data manipulation.It should be noted that can be when the data of local data base change, obtain in real timeLog information.It obtains one by one, is not disposably to obtain, so as to according to data alteration updating cache in real time.
It is understood that may be related to repeatedly updating slow in the use process of the local cache of local data baseThe operation deposited, if analyzed whole log informations every time, the case where change for only partial data, and it is uncomfortableWith, it will increase the time cost of data analysis, it therefore, can also basis when obtaining the log information that local data base generatesThe time of data change and/or log information generate the log information for the time obtaining local data base generation.
S120, the log information is parsed, local cache is updated according to parsing result.
As noted previously, as record has data information and the data manipulation of local data base whole in log information, it canSelection of land, it is described that the log information is parsed, local cache is updated according to parsing result, comprising: parse the logChange data and data manipulation order information in information are updated according to the change data and data manipulation order informationLocal cache.
Wherein, the process parsed to the log information can be to be parsed one by one, is parsed of course for improvingEfficiency is also possible to a plurality of log information while parsing.It should be noted that same in a plurality of log informationWhen parsing, it is ensured that the being originally generated sequence in log information is stored.
In the embodiments of the present disclosure, local cache is updated according to parsing result, it may include: it will be original slow in local cacheDeposit data is deleted, and will be in the target cache data write-in local cache in parsing result.It wherein, will be original in local cacheData cached deletion can specifically include: carrying out data to the data in local cache according to cache key mapping logic and deletesIt removes.Specifically can include: obtain the target in local cache and delete the database storage address of data in the local database;According toThe database storage address is mapped as the keyword in local cache by cache key mapping logic, and is removed from the cacheThe keyword.Wherein, target, which deletes data, can be all data currently stored in local cache.It is understood thatIt is the database storage address being stored in the cache key mapping logic data in the database and in local cacheIn keyword between corresponding relationship.
Illustratively, it updates local cache and specifically can be to repeat and delay recorded in the log information with targetThe corresponding data information of deposit data and data manipulation update local cache data.Wherein, target cache data can according toFamily actual demand is determined, herein and without limitation.It should be noted that it is data cached accurate qualitative in order to guarantee, moreNew caching will be subject to database rule, that is, update caching again after guaranteeing database rule.
The technical solution of the embodiment of the present disclosure passes through the log information generated when data altering event to local data baseIt is parsed, since log information recording has the data information and data operation information of local data base, according to parsingAs a result the technical issues of updating local cache, solving the poor user experience caused by updating not in time local cache, not onlyIt can guarantee timely updating for local cache, also keep the consistency of local cache and local data.
Embodiment two
Fig. 2 is a kind of flow diagram of data cache method provided by the embodiment of the present disclosure two, more than the present embodimentIt states in embodiment and is advanced optimized based on each optinal plan.In the present embodiment, optionally, described to the logInformation is parsed, and updates local cache according to parsing result, comprising: parse change data in the log information andData manipulation order information updates local cache according to the change data and data manipulation order information.
In the embodiments of the present disclosure, optionally, the log information is parsed, comprising: control the local dataThe log information is sent to incremental data and subscribed to and consumption service component by library;It is subscribed to based on the incremental data and consumes clothesBusiness component parses the log information.
As shown in Fig. 2, the method for the present embodiment is specific can include:
S210, when detecting the data altering event of local data base, obtain local data base generate log information.
The log information is sent to incremental data and subscribed to and consumption service group by S220, the control local data basePart.
Wherein, incremental data, which is subscribed to, can be canal canal server in other words with consumption service, being capable of disguised costThe slave database of ground database, then the log information can will be then sent to incremental data and subscribed to and consumption clothes by local data baseBusiness component, which, which subscribes to, receives the log information that database is transmitted with consumption service component, and to the journal fileParsing.
Wherein, the log information is transferred to incremental data subscription and the transmission mode of consumption service component and can beReal-time perfoming is transmitted after one log information of generation of local data base, that is, is sent one by one;It can certainly be basisDefault first transmission rule transmits after being packaged to two or two or more log informations.Illustratively, the first transmissionRule can be the degree of association etc. of the first duration or two and two or more log information.
S230, the log information is parsed with consumption service component based on incremental data subscription.
In the embodiments of the present disclosure, it obtains the log information and is intended to update caching, therefore, it is necessary to be based on the incremental numberGo out to update the log information required for caching with consumption service analyzing component according to subscribing to, more particularly, to databases comparison thingThe log information of part.
It should be noted that the incremental data is subscribed to will parse with consumption service component for which log information, depend onWhich log information that local data base generates is corresponding in data altering event.The incremental data is subscribed to be taken with consumptionBusiness component does not need to determine whether data altering event can really have an impact to the raw cache data in local cache,It does not need corresponding with target cache data according to being found out in the raw cache data in the local cache really log informationLog information.The logic that buffer update can be simplified in this way improves the efficiency of buffer update, and can fully ensure that local cacheWith the consistency of local data base data.
In the embodiments of the present disclosure, it subscribes to consumption service component canal based on incremental data to log letterAfter breath is parsed, it can also include: to be packaged the log information after at least one parsing, obtain Update log packet;IntoAnd local cache is updated according to Update log packet.Wherein, being updated according to the Update log packet can specifically include: obtainThe log information in the Update log packet is taken, the local cache is updated according to the log information in the Update log packet.
S240, change data and data manipulation order information in the log information are parsed, according to the changeData and data manipulation order information update local cache.
Since the processing result of database data is often closely bound up with data processing sequence, therefore, it is necessary to parseThe change data and data manipulation order information in log information are stated, and then are grasped according to the change data and the dataMake order information to be updated the raw cache data of local cache.
Illustratively, local cache is updated according to the change data and data manipulation order information, it may include: according toSequencing in data manipulation order information updates the target cache data in the change data into local cache.
The technical solution of the present embodiment is subscribed to by incremental data and receives log information with consumption service component, and to dayWill information is parsed, and the log information of local data base generation can be quickly and easily obtained;And then according in log informationThe data information parsed is updated local cache with data manipulation order information, can fully ensure that local cache dataWith the consistency of local data base data, and it can guarantee the one of the update sequence of database and the update sequence of local cacheCause property.
Fig. 3 is a kind of schematic diagram of the optional example of data buffer storage provided by the embodiment of the present disclosure, as shown in figure 3, withFor MySQL database cluster, local data base MySQL Master is replicated with to client database MySQLMaster by dataCenter Drc component carries out data interchange.
It is illustrated using left data library in scheming as local data base, detailed process is as follows for data buffer storage: working as localWhen database MySQL Master data change, such as when having data loading, log information Binlog can be generated, at this time may be usedThe data change time is converted to update caching thing with tools such as consumption service component canal to subscribe to by incremental dataPart is updated local cache cache, and the data landing for guaranteeing that Local Data landing and opposite end are come by drc can be moreNew caching, guarantees the consistency of the data of local cache and the data of local data base.
The local cache of the embodiment of the present disclosure can be understood as can store data cached carrier, can be a storageSpace or a kind of storage medium can be independent caching cache, be also possible to using Redis database etc., as long as can depositIt stores up data cached, herein and is not specifically limited.
Embodiment three
Fig. 4 is a kind of structural schematic diagram of data buffer storage device provided by the embodiment of the present disclosure three, as shown in figure 4, thisData buffer storage device provided by open embodiment can include: log information obtains module 410 and local cache update module420.Wherein, log information obtains module 410, local for obtaining when detecting the data altering event of local data baseThe log information that database generates;Local cache update module 420, for being parsed to the log information, according to parsingAs a result local cache is updated.
The technical solution of the embodiment of the present disclosure passes through the log information generated when data altering event to local data baseIt is parsed, since log information recording has the data information and data operation information of local data base, according to parsingAs a result the technical issues of updating local cache, solving the poor user experience caused by updating not in time local cache, not onlyIt can guarantee timely updating for local cache, also keep the consistency of local cache and local data.
Based on the above technical solution, the log information obtains module and can be used for executing in operations described below at leastOne:
When receiving the data to be synchronized of opposite end database transmissions, the log information of local data base is obtained;
When detecting the local change operation of local data base data, the log information of the local data base is obtained,Wherein, the local change operation includes modification, write-in and/or deletes.
On the basis of above-mentioned each technical solution, the data buffer storage device can also include:
Data simultaneous module receives opposite end database transmissions by data duplication centre component for controlling local data baseData to be synchronized.
On the basis of above-mentioned each technical solution, the local cache update module be can be also used for:
The log information is sent to incremental data and subscribed to and consumption service group by the local slow control local data basePart;
It is subscribed to based on the incremental data and the log information is parsed with consumption service component.
On the basis of above-mentioned each technical solution, local cache update module can be used for:
Parse the change data and data manipulation order information in the log information, according to the change data withAnd data manipulation order information updates local cache.
On the basis of above-mentioned each technical solution, the local cache update module can be further used for:
The target cache data update in the change data is arrived according to the sequencing in data manipulation order informationIn local cache.
On the basis of above-mentioned each technical solution, the local cache update module be can be also used for:
Raw cache data in local cache are deleted, and the target cache data write-in in parsing result is local slowIn depositing.
Data cache method provided by disclosure any embodiment can be performed in above-mentioned data buffer storage device, has execution numberAccording to the corresponding functional module of caching method and beneficial effect.
Example IV
Below with reference to Fig. 5, it illustrates the electronic equipments (such as terminal device) for being suitable for being used to realize the embodiment of the present disclosure500 structural schematic diagram.Terminal device in the embodiment of the present disclosure can include but is not limited to such as mobile phone, notebook electricityBrain, digit broadcasting receiver, PDA (personal digital assistant), PAD (tablet computer), PMP (portable media player), vehicleThe mobile terminal of mounted terminal (such as vehicle mounted guidance terminal) etc. and such as number TV, desktop computer etc. are fixed eventuallyEnd.Electronic equipment shown in Fig. 5 is only an example, should not function to the embodiment of the present disclosure and use scope bring it is anyLimitation.
As shown in figure 5, electronic equipment 500 may include processing unit (such as central processing unit, graphics processor etc.)501, random access can be loaded into according to the program being stored in read-only memory (ROM) 502 or from storage device 508Program in memory (RAM) 503 and execute various movements appropriate and processing.In RAM 503, it is also stored with electronic equipmentVarious programs and data needed for 500 operations.Processing unit 501, ROM 502 and RAM 503 pass through the phase each other of bus 504Even.Input/output (I/O) interface 505 is also connected to bus 504.
In general, following device can connect to I/O interface 505: including such as touch screen, touch tablet, keyboard, mouse, taking the photographAs the input unit 506 of head, microphone, accelerometer, gyroscope etc.;Including such as liquid crystal display (LCD), loudspeaker, vibrationThe output device 507 of dynamic device etc.;Storage device 508 including such as tape, hard disk etc.;And communication device 509.Communication device509, which can permit electronic equipment 500, is wirelessly or non-wirelessly communicated with other equipment to exchange data.Although Fig. 5 shows toolThere is the electronic equipment 500 of various devices, it should be understood that being not required for implementing or having all devices shown.It can be withAlternatively implement or have more or fewer devices.
Particularly, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart descriptionSoftware program.For example, embodiment of the disclosure includes a kind of computer program product comprising be carried on computer-readable mediumOn computer program, which includes the program code for method shown in execution flow chart.In such realityIt applies in example, which can be downloaded and installed from network by communication device 509, or from storage device 508It is mounted, or is mounted from ROM 502.When the computer program is executed by processing unit 501, the embodiment of the present disclosure is executedMethod in the above-mentioned function that limits.
It should be noted that the above-mentioned computer-readable medium of the disclosure can be computer-readable signal media or meterCalculation machine readable storage medium storing program for executing either the two any combination.Computer readable storage medium for example can be --- but notBe limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or any above combination.MeterThe more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to: have the electrical connection, just of one or more conducting wiresTaking formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type may be programmed read-only storageDevice (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device,Or above-mentioned any appropriate combination.In the disclosure, computer readable storage medium can be it is any include or storage journeyThe tangible medium of sequence, the program can be commanded execution system, device or device use or in connection.And at thisIn open, computer-readable signal media may include in a base band or as the data-signal that carrier wave a part is propagated,In carry computer-readable program code.The data-signal of this propagation can take various forms, including but not limited toElectromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be computer-readable and depositAny computer-readable medium other than storage media, the computer-readable signal media can send, propagate or transmit and be used forBy the use of instruction execution system, device or device or program in connection.Include on computer-readable mediumProgram code can transmit with any suitable medium, including but not limited to: electric wire, optical cable, RF (radio frequency) etc. are above-mentionedAny appropriate combination.
Above-mentioned computer-readable medium can be included in above-mentioned electronic equipment;It is also possible to individualism, and notIt is fitted into the electronic equipment.
Above-mentioned computer-readable medium carries one or more program, when said one or multiple programs are by the electricityWhen sub- equipment executes, so that the electronic equipment: when detecting the data altering event of local data base, obtaining local data baseThe log information of generation;The log information is parsed, local cache is updated according to parsing result.
The calculating of the operation for executing the disclosure can be write with one or more programming languages or combinations thereofMachine program code, above procedure design language include object oriented program language-such as Java, Smalltalk, C++, it further include conventional procedural programming language-such as " C " language or similar programming language.Program code canFully to execute, partly execute on the user computer on the user computer, be executed as an independent software package,Part executes on the remote computer or executes on a remote computer or server completely on the user computer for part.In situations involving remote computers, remote computer can pass through the network of any kind --- including local area network (LAN)Or wide area network (WAN)-is connected to subscriber computer, or, it may be connected to outer computer (such as utilize Internet serviceProvider is connected by internet).
Flow chart and block diagram in attached drawing, illustrate the method and computer program product according to the various embodiments of the disclosureArchitecture, function and operation in the cards.In this regard, each box in flowchart or block diagram can represent oneA part of module, program segment or code, a part of the module, program segment or code include it is one or more for realizingThe executable instruction of defined logic function.It should also be noted that in some implementations as replacements, function marked in the boxIt can also can occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated can actually baseOriginally it is performed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.It is also noted thatIt is the combination of each box in block diagram and or flow chart and the box in block diagram and or flow chart, can uses and execute ruleThe dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instructionIt closes to realize.
Be described in the embodiment of the present disclosure involved module, unit can be realized by way of software, can also be withIt is realized by way of hardware.Wherein, module, the title of unit are not constituted under certain conditions to the module or unit sheetThe restriction of body.
Above description is only the preferred embodiment of the disclosure and the explanation to institute's application technology principle.Those skilled in the artMember is it should be appreciated that the open scope involved in the disclosure, however it is not limited to technology made of the specific combination of above-mentioned technical characteristicScheme, while should also cover in the case where not departing from design disclosed above, it is carried out by above-mentioned technical characteristic or its equivalent featureAny combination and the other technical solutions formed.Such as features described above has similar function with (but being not limited to) disclosed in the disclosureCan technical characteristic replaced mutually and the technical solution that is formed.