The content of the invention
The present invention provides a kind of file cache device, system and method, at least to solve the above problems.
According to an aspect of the invention, there is provided a kind of file cache device, including:Receiving module, for receiving visitor
Family end sends the call request being used for from server calls file data;Processing module, for according to call request from server
Download file data, and cache file data.
Preferably, this document buffer storage further includes:Computing module, the preset storage for calculating storage file data are empty
Between memory capacity;Removing module, in the case of exceeding memory capacity in the file size of buffered file data,
File data beyond part is deleted.
Preferably, include in receiving module and processing module:Preset interface specification.
Preferably, preset interface specification includes:The title and storage location of client storage file data.
Preferably, the operating system that file cache device can be applicable in includes:IOS systems, android system and
Winphone systems.
Preferably, the client that file cache device can be applicable in includes:Tablet computer, smart mobile phone, laptop
And desktop computer.
According to another aspect of the present invention, there is provided a kind of file cache system, including:Client, for centre
Link block sends the call request being used for from server calls file data;Middle link block, for receiving call request,
File data, and cache file data are downloaded from server according to call request;Server, for being provided to middle link block
File data.
Preferably, middle link block can be compiled as static library libv8.a or dynamic base libv8.so.
Preferably, middle link block includes:Setfile interfaces, vperform interfaces, getpercentage interfaces,
Canceltransf interfaces and resumetransfer interfaces.
Still another aspect according to the present invention, there is provided a kind of file caching method, including:Receive the use that client is sent
In the call request from server calls file data;File data, and cache file are downloaded from server according to call request
Data.
Preferably, after cache file data, further include:Calculate the storage of the preset memory space of storage file data
Capacity;In the case where the file size of buffered file data exceedes memory capacity, to the file data beyond part
Deleted.
By the present invention, using adding middle link block between clients and servers, and in middle link block
The interface specification used is needed during upper profile data call, client passes through on middle link block invoking server
File data mode, solve in correlation technique and the mode of same buffered mechanism is developed under different operating system cause out
Send out cost excessive, the problem of development time is long, and then it is effectively saved the effect of development time and development cost.
Embodiment
Come that the present invention will be described in detail below with reference to attached drawing and in conjunction with the embodiments.It should be noted that do not conflicting
In the case of, the feature in embodiment and embodiment in the application can be mutually combined.
Present embodiments provide a kind of file cache device.Fig. 1 is file cache device according to embodiments of the present invention
Structure diagram, as shown in Figure 1, the device can include:Receiving module 10 and processing module 20.Wherein, receiving module 10, are used for
Receive client and send the call request being used for from server calls file data;Processing module 20, is connected to receiving module 10,
For downloading file data, and cache file data from server according to call request.
By above-mentioned file cache device, client can be made directly to be sent to this document buffer storage and call asking for data
Ask, then by this document buffer storage after server downloads to corresponding file, caching process is carried out to file, this document delays
Cryopreservation device can be adapted for a variety of clients and several operation systems, in this way, different clients can be saved using more behaviour
In the case of making system multilingual, with the information exchange between multi-platform different language, avoid re-defining interface.
In practical applications, this document buffer storage can be set between clients and servers, to play centre
The effect of caching.Of course, it is possible to carry out different settings according to different demand, for example, it is also possible to by this document buffer storage
It is separately positioned on client and server.
In the present embodiment, may each comprise in receiving module 10 and processing module 20:Preset interface specification.Need to illustrate
, which includes unified content(It is provided with connecing accordingly for various operating systems or multilingual
Mouth specification)Preferably, preset interface specification can include:The title and storage location of client storage file data.
Preferably, the operating system that file cache device provided in this embodiment can be applicable in includes:IOS systems,
Android system and Winphone systems.
Preferably, the client that file cache device provided in this embodiment can be applicable in includes:Tablet computer, intelligent hand
Machine, laptop and desktop computer.
Fig. 2 is the structure diagram of file cache device according to the preferred embodiment of the invention, as shown in Fig. 2, this document delays
Cryopreservation device can also include:Computing module 30, is connected to processing module 20, and the preset storage for calculating storage file data is empty
Between memory capacity;Removing module 40, is connected to computing module 30, for surpassing in the file size of buffered file data
In the case of crossing memory capacity, the file data beyond part is deleted.
By the preferred embodiment, when the size of the file data cached in file cache device has reached preset caching
During the capacity in space, this, which means that, can not carry out more file storage operations again, therefore, in the calculating of computing module 30
As a result the capacity of preset spatial cache is exceeded, removing module 40 just deletes subsequently received file data.
Fig. 3 is the structure diagram of file cache system according to embodiments of the present invention, as shown in figure 3, this document caches
System can include:Client, for sending the call request being used for from server calls file data to middle link block;
Middle link block, for receiving call request, file data, and cache file number are downloaded according to call request from server
According to;Server, for providing file data to middle link block.
In this document caching system, middle link block is equivalent to above-mentioned file cache device, the work(of the two in fact
Can be identical.
In the present embodiment, middle link block can be compiled as static library libv8.a or dynamic base libv8.so.
Preferably, middle link block can include:Setfile interfaces, vperform interfaces, getpercentage connect
Mouth, canceltransf interfaces and resumetransfer interfaces.
Fig. 4 is file caching method flow diagram according to embodiments of the present invention, as shown in figure 4, this document caching side
Method comprises the following steps(Step S402- steps S404):
Step S402, receives the call request being used for from server calls file data that client is sent;
Step S404, file data, and cache file data are downloaded according to call request from server.
In the present embodiment, after step S404 is performed, the preset memory space of storage file data can also be calculated
Memory capacity;In the case where the file size of buffered file data exceedes memory capacity, to the text beyond part
Number of packages is according to being deleted.
File cache device, the system and method provided using above-described embodiment, can solve in correlation technique in difference
The mode of same buffered mechanism is developed under operating system causes the problem of development cost is excessive, and the development time is long, and then
It is effectively saved the effect of development time and development cost.
File cache device, system and the side provided with reference to Fig. 5 and Fig. 6 and preferred embodiment above-described embodiment
Method is described in further detail.
The thinking of the proposition of this preferred embodiment is to set link block among one(Function is filled with above-mentioned file cache
Put, for convenience of description, hereinafter referred to as middleware), middleware is mainly responsible for data packet(json)Download and caching with file.It is logical
Difference according to client operating system can be accomplished by crossing the middleware, which is compiled as static library(libv8.a)Or
Dynamic base(libv8.so), while a set of interface specification is defined, for client call.Client is by calling the side of middleware
Method, obtains server data bag or file, and after middleware downloading data bag and file, caching process is carried out to file.
In this way, the client for being configured with multiple operating system different language and multi-platform different language can be saved
Between communication interaction, interface re-defines, and avoids the overlapping development of code, and client does not have to carry out the slow of local file again
Deposit processing.Moreover, being said in terms of overall technology framework, the code degree of coupling is reduced, says, greatlys save out in terms of development cost
The time of hair and cost.
In the preferred embodiment, client directly can send call request to middleware, below will be to client tune
It is described with the course of work of middleware, Fig. 5 is the work of client call middleware according to the preferred embodiment of the invention
Process schematic, the process are as follows:
(1)Initialize middleware(Initial method:VPACK createvpack(void));
(2)Set data packet(Call method:int setvpack(VPACK p,VPACK_MEMBp_memb,memb_
value));
(3)Set file download parameters(int setvfile(VPACK p,string lfp,string lfn,string
rfp,string rfn,vintdir,vint fnew));
(4)Setting is asked to middleware, middleware vperform methods at the same time, and with Platform communication, platform returns middle
The FTP of part file(File Transfer P72872rotocol, File Transfer Protocol)Address, middleware call download module,
By file deposit client designated position(The position lfp that client is set in request);
(5)Client call middleware caching process interface, cache interface include parameter(It is automatic manually to set, cache greatly
Small setting, cache file type are set);
(6)Middleware is handled file and data according to setting.
In order to be better understood the downloading process of this document or data and file data to download cached
Process, may be referred to Fig. 6 here, Fig. 6 be client in file cache system according to the preferred embodiment of the invention, middleware,
Server carries out the course of work schematic diagram of FTP downloads, and the course of work of client call middleware is described below, its
In also introduce middleware each interface function.The course of work is as follows:
(1)Client call setvfile interfaces;
int setvfile(VPACK p,string lfp,string lfn,string rfp,string rfn,vint
dir,vint fnew)
Wherein, the parameter declaration of setvfile interfaces:
VPACK p; //
string lfp;// local file path
string lfn;// local file title
string rfp;// telefile path
string rfn;// telefile title
vint dir;// upload or download mark
vint fnew;// whether breakpoint transmission mark
The function declaration of setvfile interfaces:File transmission property, including local file path are set, and ftp uploads path;
If the multiple files of upload/download, need to repeatedly call setvfile.
Wherein, the upload path of FTP is by interface document treaty rule.
(2)Middleware setvfile interfaces judge file attribute;
Wherein, the function declaration of setvfile interfaces:
Judge that file whether there is, if it does not, returning to mistake;
Determine whether to allow breakpoint transmission, branch is as follows:
Allow breakpoint transmission, then judge whether file changes, branch is as follows:
It is unchanged, fnew attributes are set to resume file;
Change, fnew attributes are set not resume file;
Do not allow breakpoint transmission, fnew attributes are set not resume file.
Return to whether operation succeeds.
(3)Client call vperform interfaces;
Int vperform(int sd,VPACK sendp,VPACK recvp,int(*pCBperform)(int n,
int stat));
Wherein, the parameter declaration of vperform interfaces:
Int sd //
VPACK sendp //
VPACK recvp //
int(*pCBperform)(int n,int stat)//
Wherein, the function declaration of vperform interfaces:File is transmitted, is reported according to the transmission received, is carried out in next step
Operation;(4)Middleware vperform interfaces are responsible for the upload or download of file;
Wherein, the function declaration of vperform interfaces:
Main thread, sends json request bags, receiving platform return value, is transmitted to client to platform;
Vfile chained lists are read, each vfile creates a sub-line journey, startup file upload/download;
Each file upload/download progress is obtained, is write in corresponding vflie;
All Files transfers, and file transmission report is sent respectively to platform and client.
(5)Middleware getpercentage interface feedback file transmission speeds;
int getpercentage(VPACK p,int n);
Wherein, the parameter declaration of getpercentage interfaces:
VPACK p; //
Int n; //
Wherein, the function declaration of getpercentage interfaces:Return to the transmission progress of n-th of file.
(6)Middleware canceltransf Interface Control File is transmitted;
int canceltransfer(VPACK p,int n,int bpc)
Wherein, the parameter declaration of canceltransf interfaces:
VPACK p; //
Int n; //
Int bpc; //
Wherein, the function declaration of canceltransf interfaces:Cancel or suspense file transmission, parameter bpc are controlled whether temporarily
Stop:
If pause, breakpoint is recorded;
If not pause, breakpoint is not recorded, file has been transmitted in deletion.
(7)Middleware resumetransfer interfaces resume file;
int resumetransfer(VPACK p,int n,int(*pCBresume)(int n,int stat));
Wherein, the parameter declaration of resumetransfer interfaces:
VPACK p; //
Int n; //
int(*pCBresume)(int n,int stat); //
Wherein, the function declaration of resumetransfer interfaces:File is resumed, file is transmitted, and call back function is adjusted
With.
(8)Platform receives josn bags, returns to handling result;
(9)Middleware calls cache interfaces to judge data cached size, temporally clears data.
By this preferred embodiment, the storehouse called in client development process can eliminate many language and platform and lead to
Repeat step during letter interaction conversion, for example, code is write in exploitation only consumes seldom time, but terminal and platform into
When the joint debugging of row function and code dock but often it is longer than the time of exploitation very much, and add the centre of this preferred embodiment offer
After part, development time and cost can be more effectively saved.
It can be seen from the above description that the present invention realizes following technique effect:Using in client and server
Between add middle link block, and need the interface used to advise during profile data call in middle link block
Model, client are solved in correlation technique in difference by way of the file data on middle link block invoking server
The mode of same buffered mechanism is developed under operating system causes the problem of development cost is excessive, and the development time is long, and then
It is effectively saved the effect of development time and development cost.
Obviously, those skilled in the art should be understood that above-mentioned each module of the invention or each step can be with general
Computing device realize that they can be concentrated on single computing device, or be distributed in multiple computing devices and formed
Network on, alternatively, they can be realized with the program code that computing device can perform, it is thus possible to which they are stored
Performed in the storage device by computing device, and in some cases, can be with different from shown in order execution herein
The step of going out or describing, they are either fabricated to each integrated circuit modules respectively or by multiple modules in them or
Step is fabricated to single integrated circuit module to realize.Combined in this way, the present invention is not restricted to any specific hardware and software.
The foregoing is only a preferred embodiment of the present invention, is not intended to limit the invention, for the skill of this area
For art personnel, the invention may be variously modified and varied.Within the spirit and principles of the invention, that is made any repaiies
Change, equivalent substitution, improvement etc., should all be included in the protection scope of the present invention.