Disclosure of Invention
The invention aims to provide a fragment data caching method, an access method, a device, a terminal and a storage medium, and aims to solve the problem that fragment or segment data cannot be normally cached due to the fact that the prior art cannot provide a method for effectively caching the fragment or segment data in a file.
In one aspect, the present invention provides a fragment data caching method, including the following steps:
receiving an HTTP request for requesting to access appointed fragment data;
acquiring parameter values of preset request parameters from the HTTP request, wherein the request parameters comprise a request address, a request method and a request range;
acquiring a preset cache information list according to the request address, and searching the cache information of the designated fragment data in the cache information list according to the request method and the request range;
when the cache information is not found, sending the HTTP request to the server, receiving the response of the server to the HTTP request, and storing the response to a preset storage unit;
generating cache information corresponding to the response according to the address information of the storage unit and the request parameter;
and adding the cache information corresponding to the response into the cache information list.
On the other hand, the invention also provides an access method of the fragmented data, which comprises the following steps:
receiving an HTTP request for requesting to access appointed fragment data;
acquiring parameter values of preset request parameters from the HTTP request, wherein the request parameters comprise a request address, a request method and a request range;
according to the request address, obtaining a cache information list of cached data, and according to the request method and the request range, searching the cache information of the designated fragment data in the cache information list;
and when the cache information is found, acquiring the cached designated fragment data according to the cache information.
On the other hand, the invention also provides a device for caching fragmented data, which comprises:
a request receiving unit, configured to receive an HTTP request requesting access to specified fragmented data;
the value acquisition unit is used for acquiring parameter values of preset request parameters from the HTTP request, wherein the request parameters comprise a request address, a request method and a request range;
the information searching unit is used for acquiring a preset cache information list according to the request address and searching the cache information of the designated fragment data in the cache information list according to the request method and the request range;
the response storage unit is used for sending the HTTP request to the server when the cache information is not found, receiving the response of the server to the HTTP request, and storing the response to a preset storage unit;
the information generating unit is used for generating cache information corresponding to the response according to the address information of the storage unit and the request parameter; and
and the information adding unit is used for adding the cache information corresponding to the response into the cache information list.
In another aspect, the present invention also provides a computing device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method as described above when executing the computer program.
In another aspect, the present invention also provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method as described above.
When an HTTP request requesting access to appointed fragmented data is received, parameter values including a request address, a request method and a request range parameter are obtained from the HTTP request, a preset cache information list is obtained according to the request address, cache information of the appointed fragmented data in the cache information list is searched according to the request method and the request range, when the cache information is not searched, the HTTP request is sent to a server, the response of the server to the HTTP request is received, the response is stored to a preset storage unit, cache information corresponding to the response is generated according to the address information of the storage unit and the request parameter, and finally the cache information corresponding to the response is added to the cache information list, so that caching of the fragmented data is achieved, and when a subsequent user accesses the fragmented data, the access efficiency is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The following detailed description of specific implementations of the present invention is provided in conjunction with specific embodiments:
the first embodiment is as follows:
fig. 1 shows an implementation flow of a fragment data caching method according to an embodiment of the present invention, and for convenience of description, only parts related to the embodiment of the present invention are shown, which are detailed as follows:
in step S101, an HTTP request requesting access to the designated fragmented data is received;
the embodiment of the invention is suitable for computing equipment, in particular to a client in a client/server (C/S) mode, wherein the client is connected with a server through a network, receives a request of a user, sends an HTTP request to the server through the network and operates (accesses) a target file. In this embodiment of the present invention, the HTTP request is a request for operating specified fragmented data of the target file, where the specified fragmented data is a part of the target file stored on the server, that is, requests to access data in a specified Range in the target file on the server, and specifically, the specified Range is specified by a request Range (e.g., a Range parameter) in a header of the HTTP request.
In step S102, obtaining parameter values of preset request parameters from the HTTP request, where the request parameters include a request address, a request method, and a request range;
in the embodiment of the invention, after the client receives the HTTP request of the user, the parameter value of the preset request parameter is obtained from the HTTP request, and the request parameter comprises the request address, the request method and the request range, so that the request parameter settings of different request methods in the HTTP request are unified, and the response efficiency of the HTTP request is improved.
In the request parameters of the HTTP request, the request address is an address, for example, a URL (Uniform Resource Locator) address, of a Resource or data (target file) to be requested to access, the request method specifies what operation the client wants to perform on the target file on the server, and the request scope specifies a scope of the target file to be requested to operate or access, that is, a location of the fragmented data in the target file. Preferably, the request method includes a GET method and a HEAD method, so that the fragment data obtained by the GET method is cached in the following, and response efficiency when the fragment data is accessed again is improved. In addition, the request header information of the HTTP request can be acquired through the HEAD method, and the validity of the resource or the hyperlink can be detected through caching the request header information. Here, in order to unify the request parameter settings of different request methods in the HTTP request, when the request method in the HTTP request is the HEAD method, the range of the request range may be set to a range in which a start value and an end value are the same, such as 0 to 0, so as to simplify the parameter configuration when the request method is the HEAD method, and improve the access efficiency of the subsequent cache.
In step S103, a preset cache information list is obtained according to the request address, and cache information of the designated fragment data in the cache information list is searched according to the request method and the request range;
the embodiment of the invention sets a cache information list at the client for recording the cache information of the fragment data at the client, and the cache information list can be any table, file and the like capable of recording the cache information. Specifically, the cache information list may include a plurality of cache information items, each cache information item may correspond to cache information of one piece of fragmented data, and the cache information item may include a request address, a request method, and request range parameter information in an HTPP request responded by the server, and may further include a cache address of the fragmented data at the client. Preferably, the method may further include obtaining an identification number through operation of the request address and the request method, so as to quickly find the corresponding cache information item through the identification number, and further finally determine whether the requested fragment data is cached through the request range parameter.
Specifically, when the cache information of the designated fragment data in the cache information list is searched, the cache information list corresponding to the request address is first obtained, and when the cache information list corresponding to the request address is not obtained, it is determined that the cache information is not searched. And when the cache information list corresponding to the request address is acquired, matching the request method in the acquired cache information list, and when the request method is not matched, determining that the cache information is not found. And when the request method is matched, acquiring the corresponding cache information item, and searching the cache information item corresponding to the request range in the HTTP request in the acquired cache information item. When the cache information item corresponding to the request range in the HTTP request is searched for in the obtained cache information item, specifically, a start value and an end value of the request range in the HTTP request may be compared with a start value and an end value of the request range in the cache information item, when the start value of the request range in the HTTP request is greater than or equal to the start value of the request range in the cache information item and the end value is less than or equal to the end value of the request range in the cache information item, it is determined that the corresponding cache information item is searched for, otherwise, it is determined that the corresponding cache information item is not searched for. When the cache information item is not found, determining that the cache information is not found, and quickly positioning the cache information of the designated fragment data in the client cache information list according to the request address, the request method and the request range in the HTTP request.
In step S104, when the cache information is not found, sending an HTTP request to the server, receiving a response from the server to the HTTP request, and storing the response in a preset storage unit;
in the embodiment of the invention, when the cache information of the specified fragment data at the client is not found, the client sends an HTTP request to the server, the server obtains a target file requested to be accessed by the client according to a request address in the HTTP request after receiving the HTTP request, then executes a corresponding request method for the specified fragment data in a corresponding range of the target file according to a request range, and then returns a corresponding response to the client. And the client receives the response to the HTTP request returned by the server and stores the response to a preset storage unit of the client. Specifically, when the response data is stored in a preset storage unit, for example, when the request method in the HTTP request is the GET method, the requested data may be stored, and when the request method in the HTTP request is the HEAD method, only the response header information of the request is stored.
In step S105, generating cache information corresponding to a response according to the address information of the storage unit and the request parameter;
after the response of the server is stored in the storage unit of the client, the client generates cache information corresponding to the response according to the address information of the storage unit and the request parameter in the HTTP request.
Specifically, when the cache information corresponding to the response is generated, the request address, the request method, and the request range parameter information in the HTPP request may be set in the cache information, and the cache address of the fragmented data at the client may also be set in the cache information. Preferably, when the cache information is generated, an identification number is obtained through operation of a request address and a request method, and the identification number is added to the cache information, so that the cache information can be searched quickly through the identification number in the following process, and the cache (fragmented data) is finally positioned through a request range. Of course, when the cache information is generated, the information such as the validity period of the cache may also be set.
In step S106, the cache information corresponding to the response is added to the cache information list.
After the cache information corresponding to the response is added to the cache information list, the cache information becomes a cache information item in the cache information list, and subsequently, when an HTTP request requesting to access the same fragmented data is received, the list can be acquired to acquire the cached fragmented data.
When an HTTP request for requesting to access specified fragment data is received, the embodiment of the invention acquires parameter values comprising a request address, a request method and a request range parameter from the HTTP request, obtaining a preset cache information list according to the request address, searching the cache information of the appointed fragment data in the cache information list according to the request method and the request range, when the cache information is not found, sending an HTTP request to the server, receiving the response of the server to the HTTP request, storing the response to a preset storage unit, generating cache information corresponding to the response according to the address information of the storage unit and the request parameter, and finally adding the cache information corresponding to the response into a cache information list, thereby not needing to change the server, the cache of the fragment data can be realized, and the access efficiency is improved when the subsequent user accesses the fragment data.
Example two:
fig. 2 shows an implementation flow of the method for accessing fragmented data according to the second embodiment of the present invention, and for convenience of description, only the parts related to the second embodiment of the present invention are shown, which are detailed as follows:
in step S201, an HTTP request requesting access to the designated fragmented data is received;
the embodiment of the invention is suitable for computing equipment, in particular to a client in a client/server (C/S) mode, wherein the client is connected with a server through a network, receives a request of a user, sends an HTTP request to the server through the network and operates (accesses) a target file. In this embodiment of the present invention, the HTTP request is an HTTP request for operating specified fragment data of the target file, where the specified fragment data is a part of the target file stored on the server, that is, requests to access data in a specified Range in the target file on the server, and specifically, the specified Range is specified by a request Range (for example, a Range parameter) in a header of the HTTP request.
In step S202, parameter values of preset request parameters are obtained from the HTTP request, where the request parameters include a request address, a request method, and a request range;
in the embodiment of the invention, after the client receives the HTTP request of the user, the parameter value of the preset request parameter is obtained from the HTTP request, and the request parameter comprises the request address, the request method and the request range, so that the request parameter settings of different request methods in the HTTP request are unified, and the response efficiency of the HTTP request is improved.
In the request parameters of the HTTP request, the request address is an address of a request for accessing a resource or data (a target file), the request method specifies what operation the client wants to perform on the target file on the server, and the request range specifies a range of the target file requested to operate or access, that is, a position of the fragmented data in the target file. Preferably, the request method includes a GET method and a HEAD method, so that the fragment data obtained by the GET method is cached in the following, and response efficiency when the fragment data is accessed again is improved. In addition, the request header information of the HTTP request can be acquired through the HEAD method, and the validity or accessibility of the resource or the hyperlink can be detected through caching the request header information. Here, in order to unify the request parameter settings of different request methods in the HTTP request, when the request method in the HTTP request is the HEAD method, the range of the request range may be set to a range in which a start value and an end value are the same, such as 0 to 0, so as to simplify the parameter configuration when the request method is the HEAD method, and improve the access efficiency of the subsequent cache.
In step S203, a preset cache information list is obtained according to the request address, and cache information of the designated fragment data in the cache information list is searched according to the request method and the request range;
the embodiment of the invention sets a cache information list at the client for recording the cache information of the fragment data at the client, and the cache information list can be any table, file and the like capable of recording the cache information. Specifically, the cache information list may include a plurality of cache information items, each cache information item may correspond to cache information of one piece of fragmented data, and the cache information item may include a request address, a request method, and request range parameter information in an HTPP request responded by the server, and may further include a cache address of the fragmented data at the client. Preferably, the method may further include obtaining an identification number through operation of the request address and the request method, so as to quickly find the corresponding cache information item through the identification number, and further finally determine whether the requested fragment data is cached through the request range parameter.
Specifically, when searching for the cache information of the designated fragment data in the cache information list, firstly, according to the request address in the HTTP request, obtaining the cache information list corresponding to the request address, matching the request method in the obtained cache information list, when the request method is matched in the cache information list, obtaining the corresponding cache information item, searching for the cache information item corresponding to the request range in the HTTP request in the obtained cache information item, when the request is found, obtaining the cache information in the searched cache information item, and determining the obtained cache information as the cache information of the designated fragment data in the cache information list, thereby quickly locating the cache information of the designated fragment data in the client cache information list according to the request address, the request method, and the request range in the HTTP request. When the cache information item corresponding to the request range in the HTTP request is searched for in the obtained cache information item, specifically, a start value and an end value of the request range in the HTTP request may be compared with a start value and an end value of the request range in the cache information item, and when the start value of the request range in the HTTP request is greater than or equal to the start value of the request range in the cache information item and the end value is less than or equal to the end value of the request range in the cache information item, it is determined that the cache information item is the cache information corresponding to the designated fragment data.
In step S204, when the cache information is found, the cached designated fragment data is obtained according to the cache information.
In the embodiment of the invention, after the cache information is found, the address information of the storage unit for storing the specified fragment data is obtained from the cache information, and the cached specified fragment data is read according to the address information. Specifically, when the start value of the request range in the HTTP request is greater than the start value of the request range in the cache information item and the end value is less than the end value of the request range in the cache information item, it indicates that the cached data covers the fragmented data that the user wants to access, at this time, the cache data corresponding to the cache information item is obtained, and the fragmented data corresponding to the request range in the HTTP request is intercepted from the obtained cache data according to the request range (i.e., the start value and the end value of the request range) in the HTTP request, so as to accurately obtain the cached specified fragmented data.
Further, after the fragment data corresponding to the request range in the HTTP request is intercepted, the fragment data may be stored in a storage unit (cache memory) of the client, cache information corresponding to the fragment data is generated according to the address information of the storage unit and the request parameter in the HTTP request, and then the generated cache information is added to a cache information list, so that the latest accessed fragment data of the user is cached, and the hit rate of subsequent caches is improved.
According to the embodiment of the invention, when an HTTP request requesting to access the designated fragment data is received, parameter values including a request address, a request method and a request range parameter are obtained from the HTTP request, a preset cache information list is obtained according to the request address, cache information of the designated fragment data in the cache information list is searched according to the request method and the request range, and when the cache information is searched, the cached designated fragment data is obtained according to the cache information, so that the cached fragment data is used for responding to the fragment data request of a user, the fragment data request is not required to be obtained from a server, and the access efficiency of the fragment data is improved.
Example three:
fig. 3 shows a structure of a fragment data caching apparatus according to a third embodiment of the present invention, and for convenience of description, only a part related to the third embodiment of the present invention is shown, where the structure includes:
a request receiving unit 31, configured to receive an HTTP request requesting access to specified fragmented data;
a value obtaining unit 32, configured to obtain parameter values of preset request parameters from the HTTP request, where the request parameters include a request address, a request method, and a request range;
an information searching unit 33, configured to obtain a preset cache information list according to the request address, and search for cache information of the designated fragment data in the cache information list according to the request method and the request range;
a response storage unit 34, configured to send the HTTP request to the server when the cache information is not found, accept a response of the server to the HTTP request, and store the response in a preset storage unit;
an information generating unit 35, configured to generate cache information corresponding to the response according to the address information of the storage unit and the request parameter; and
an information adding unit 36, configured to add the cache information corresponding to the response to the cache information list.
In the embodiment of the present invention, each unit of the cache apparatus may be implemented by a corresponding hardware or software unit, and each unit may be an independent software or hardware unit, or may be integrated into a software or hardware unit, which is not limited herein. For the specific implementation of each unit, reference may be made to the description of the implementation of the first unit, which is not described herein again.
Example four:
fig. 4 shows a structure of a computing device according to a fourth embodiment of the present invention, and for convenience of explanation, only a part related to the embodiment of the present invention is shown.
Computing device 4 of an embodiment of the present invention includes a processor 40, a memory 41, and a computer program 42 stored in memory 41 and executable on processor 40. The processor 40, when executing the computer program 42, implements the steps in the various method embodiments described above, such as the steps S101 to S106 shown in fig. 1. Alternatively, the processor 40, when executing the computer program 42, implements the functions of the units in the above-described device embodiments, such as the functions of the units 31 to 36 shown in fig. 3.
The computing device of the embodiment of the invention can be a personal computer, a mobile device and other networking devices using an HTTP protocol. The steps implemented when the processor 40 in the computing device 4 executes the computer program 42 to implement the method can refer to the description of the foregoing method embodiments, and are not described herein again.
Example five:
in an embodiment of the present invention, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps in the above-described method embodiments, e.g., steps S101 to S106 shown in fig. 1. Alternatively, the computer program may be adapted to perform the functions of the units of the above-described embodiments of the apparatus, such as the functions of the units 31 to 36 shown in fig. 3, when executed by the processor.
When an HTTP request for requesting to access specified fragment data is received, the embodiment of the invention acquires parameter values comprising a request address, a request method and a request range parameter from the HTTP request, obtaining a preset cache information list according to the request address, searching the cache information of the appointed fragment data in the cache information list according to the request method and the request range, when the cache information is not found, sending an HTTP request to the server, receiving the response of the server to the HTTP request, storing the response to a preset storage unit, generating cache information corresponding to the response according to the address information of the storage unit and the request parameter, and finally adding the cache information corresponding to the response into a cache information list, thereby not needing to change the server, the cache of the fragment data can be realized, and the access efficiency is improved when the subsequent user accesses the fragment data.
The computer readable storage medium of the embodiments of the present invention may include any entity or device capable of carrying computer program code, a recording medium, such as a ROM/RAM, a magnetic disk, an optical disk, a flash memory, or the like.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.