WO2017045538A1 - 基于http协议的缓存、请求、响应方法及相应装置 - Google Patents

基于http协议的缓存、请求、响应方法及相应装置 Download PDF

Info

Publication number
WO2017045538A1
WO2017045538A1 PCT/CN2016/097998 CN2016097998W WO2017045538A1 WO 2017045538 A1 WO2017045538 A1 WO 2017045538A1 CN 2016097998 W CN2016097998 W CN 2016097998W WO 2017045538 A1 WO2017045538 A1 WO 2017045538A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
content
message
time
http
Prior art date
Application number
PCT/CN2016/097998
Other languages
English (en)
French (fr)
Inventor
张紫荣
周哲
Original Assignee
阿里巴巴集团控股有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2017045538A1 publication Critical patent/WO2017045538A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/40Support for services or applications
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching

Definitions

  • the present application relates to the field of the Internet, and in particular, to a cache method, a request method, a response method, a cache device, a request device, a response device, and a webpage access system based on the HTTP protocol.
  • a proxy server is usually deployed on the side close to the client between the client and the source server, thereby caching the network content on the source server by setting a cache service on the proxy server, so that the user is near Get web content.
  • the network content obtained by the user is transmitted based on the HTTP (Hyper Text Transfer Protocol) protocol.
  • the HTTP protocol-based caching service is set on the proxy server.
  • the HTTP protocol is an abbreviation of the Hyper Text Transfer Protocol. It is the most widely used network protocol on the Internet and is used to provide a request and response between the client and the server.
  • the HTTP protocol provides a standard set of caching mechanisms that are implemented by setting the specified fields of messages based on the HTTP protocol.
  • the specified fields related to the cache are: a cache control field (Cache-Control field), a cache compile control field (Pragma field), and a cache expiration control field (Expires field).
  • the cache control field is set by the source server to specify whether the browser and the proxy server can cache the content, and is used to specify the value of the cache time; the cache control field can also be set by the client to specify the client to initiate The request does not use the cached content, but directly obtains the latest content on the source server; the cache compilation control field is set by the client to specify that the client-initiated request does not use the cached content, but directly obtains the latest content on the source server.
  • the priority is lower than the same setting corresponding to the cache control field; the cache expiration control field is set by the source server to specify the value of the cache time, which has a lower priority than the cache time set by the cache control field.
  • the standard caching mechanism provided by the HTTP protocol as described above has the following problems:
  • the proxy server cannot actively set the cache time of the content, and can only follow the settings of the source server. For example, if the source server does not set the cache time for the content, the content will not be cached in the proxy server, and the content that the user needs to access still needs to be returned by the source server, resulting in low proxy cache hit rate, slow user access speed, and large return traffic. problem.
  • the proxy server cannot update the cached content in time. For content that has been updated but not expired by the source server, the source server needs to actively refresh the proxy cache or the client is forced to refresh. Otherwise, the client access will get expired data, affecting the content aging. Sex and user experience.
  • the present application provides a caching method, a request method, a response method, a caching device, a requesting device, a response device, and a webpage accessing system based on the HTTP protocol, so as to solve the caching method under the standard caching mechanism provided by the existing HTTP protocol.
  • the proxy server actively sets the cache time, and the proxy server cannot update the cached content in time.
  • the HTTP protocol-based caching method provided by the present application includes:
  • the HTTP packet carries a content type field; the corresponding value of the content type field is used to describe a data category of the content of the packet in the HTTP packet;
  • the local cache parameter includes a content secondary update probability and a local cache time.
  • the steps to describe the differentiation settings include:
  • the local cache time is calculated by using the content secondary update probability as a parameter, so that the length of the local cache time is consistent with the height of the updated frequency.
  • the setting the second update probability of the content according to the corresponding value of the content type field is the content of the message in the HTTP packet described by the corresponding value of the content type field.
  • the data category can reflect the frequency at which the HTTP message is updated on the original server, and the difference is set based on the frequency.
  • the value range of the secondary update probability of the content corresponding to the HTTP packet includes:
  • the corresponding value of the content type field indicates that the content of the message is a type of a text message, or a type indicating that the content of the message is used to package an email message, or that the content of the message is used to connect a message
  • the frequency of the corresponding type of the message identified by the value is updated at the original server, and the content of the content corresponding to the second type of the message is updated twice.
  • the value range is set to be close to a certain interval of 100%;
  • the corresponding value of the content type field indicates that the content of the message is used to transmit the type of the audio and audio data, or indicates that the content of the message is used to transmit the type of the dynamic image data, the values are identified
  • the frequency of the corresponding type of the message is updated in the original server, and the range of the second update probability of the content corresponding to the type of the message is set to be close to a certain interval of 0%;
  • the value is The value ranges of the secondary update probability of the content corresponding to the packets of the corresponding type are set to a certain interval between the following boundaries:
  • the lower limit value of the value range is set to be higher than the corresponding value of the content type field indicating the type for transmitting audio and sound data, or the setting set when the type of the moving image data is transmitted.
  • the highest value of the range of values for the content secondary update probability is set to be higher than the corresponding value of the content type field indicating the type for transmitting audio and sound data, or the setting set when the type of the moving image data is transmitted.
  • the value ranges of the secondary update probability of the content corresponding to the types of packets are respectively set to be close to a certain interval of 100%, specifically, an interval set to >50% and ⁇ 99%;
  • the value ranges of the secondary update probability of the content corresponding to the types of messages are respectively set to a certain interval close to 0%, specifically, an interval set to ⁇ 50% and ⁇ 1%;
  • the value ranges of the secondary update probability of the content corresponding to the types of the packets are respectively set to a certain interval between the following boundaries, and specifically, the value of the secondary update probability of the content is set to 50%.
  • the specific value of the maximum value is 60 seconds
  • a minimum value is set for the local cache time, and the specific value of the minimum value is 1 second.
  • the calculating the local cache time by using the content secondary update probability as a parameter includes:
  • the local cache time is calculated as:
  • Force_ttl (1–A)cache_time, where force_ttl is the local cache time, A is the content secondary update probability, and cache_time is included by the cache control field or the corresponding value of the cache expiration control field.
  • the local cache time is calculated as:
  • Force_ttl (1 ⁇ A)max_default_cache_time, where force_ttl is the local cache time, A is the content secondary update probability, and max_default_cache_time is the maximum value preset for the local cache time.
  • the performing, by using the local cache parameter, the cache processing of the HTTP packet including:
  • the cache priority rule based on the standard cache mechanism of the HTTP protocol sets the priority of the local cache parameter to be higher than the cacheable or cached setting parameter of the HTTP protocol standard cache mechanism, and is lower than the HTTP protocol standard cache mechanism.
  • the cache instruction is set according to the local cache parameter, and a corresponding cache operation is performed.
  • the HTTP protocol-based request method provided by the present application includes:
  • the proxy server receives the HTTP request packet sent by the client, where the HTTP request packet carries the URL;
  • the cached content that has been hit is obtained, and based on the preset local proxy cache parameter, it is determined whether the cached content that has been hit expires.
  • the expired source verification instruction is sent to the source server.
  • the cached content is returned to the client.
  • the preset local proxy cache parameter includes a preset local proxy cache time in a response header of the cached HTTP packet on the proxy server, where the local proxy cache time is obtained by the following steps:
  • a content secondary update probability specific to the HTTP message where the content secondary update probability is used to reflect that the HTTP message to which it belongs is Source The frequency at which the server is updated;
  • the time when the HTTP packet is cached is used as the current cache time in a specified field in the response header of the HTTP packet, and the current cache time format is an absolute time.
  • the determining, according to the preset local proxy cache parameter, whether the cached content that has been hit expires includes:
  • force_ttl force_ttl+proxy-save-time, wherein the force_ttl is the local proxy cache time, and the proxy-save-time is the Current cache time;
  • the HTTP protocol-based response method provided by the present application includes:
  • the proxy server receives the HTTP response message from the source server
  • the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the response processing is ended;
  • the corresponding cache processing is performed according to a standard cache mechanism of the HTTP protocol, including:
  • the valid cache time is a cache time parameter of the HTTP protocol standard cache mechanism
  • the response message is buffered, and a return instruction for returning the content of the locally cached message corresponding to the response message to the client is executed, and the current response process is ended.
  • the local proxy cache parameter includes a content secondary update probability and a local proxy cache.
  • the steps of the differentiated setting include:
  • the local proxy cache time is calculated by using the content secondary update probability as a parameter, so that the length of the local proxy cache time is consistent with the updated frequency.
  • the content secondary update probability is set differently according to the data category of the message content in the response message according to the corresponding value of the content type field, which refers to the correspondence of the content type field.
  • the data type of the message content in the response message described by the value can reflect the frequency of the response message being updated on the original server, and the content corresponding to the response message is differently set according to the frequency level.
  • the range of values of the secondary update probability includes:
  • the corresponding value of the content type field indicates that the content of the message is a type of a text message, or a type indicating that the content of the message is used to package an email message, or the content of the message is used to connect a message body
  • the frequency of the corresponding type of the message identified by the value is updated at the original server, and the probability of the second update of the content corresponding to the type of the message is taken.
  • the range of values is set to be close to a certain interval of 100%;
  • the corresponding value of the content type field indicates that the content of the message is used to transmit the type of the audio and audio data, or indicates that the content of the message is used to transmit the type of the dynamic image data, the values are identified
  • the frequency of the corresponding type of the message is updated in the original server, and the range of the second update probability of the content corresponding to the type of the message is set to be close to a certain interval of 0%;
  • the value is The value ranges of the secondary update probability of the content corresponding to the packets of the corresponding type are set to a certain interval between the following boundaries:
  • the lower limit value of the value range is set to be higher than the corresponding value of the content type field indicating the type for transmitting audio and sound data, or the setting set when the type of the moving image data is transmitted.
  • the highest value of the range of values for the content secondary update probability is set to be higher than the corresponding value of the content type field indicating the type for transmitting audio and sound data, or the setting set when the type of the moving image data is transmitted.
  • the value ranges of the secondary update probability of the content corresponding to the types of packets are respectively set to be close to a certain interval of 100%, specifically, an interval set to >50% and ⁇ 99%;
  • the value ranges of the secondary update probability of the content corresponding to the types of messages are respectively set to a certain interval close to 0%, specifically, an interval set to ⁇ 50% and ⁇ 1%;
  • the value ranges of the secondary update probability of the content corresponding to the types of the packets are respectively set to a certain interval between the following boundaries, and specifically, the value of the secondary update probability of the content is set to 50%.
  • a minimum value is set for the local proxy cache time, the minimum value being 1 second.
  • the calculating the local proxy cache time by using the content secondary update probability as a parameter includes:
  • the local proxy cache time is calculated as:
  • Force_ttl (1–A)cache_time, where force_ttl is the local proxy cache time, A is the content secondary update probability, and cache_time is the corresponding value of the cache control field or the cache expired control field.
  • the local proxy cache time is calculated as:
  • Force_ttl (1 ⁇ A)max_default_cache_time, where force_ttl is the local proxy cache time, A is the content secondary update probability, and max_default_cache_time is the maximum value preset for the local proxy cache time.
  • the performing including:
  • the time when the response message is cached is used as the current cache time in a specified field in the response header of the response message, where the current cache time format is an absolute time;
  • response status code is 304, perform the following steps:
  • the step of determining whether the response message includes a content type field is continued.
  • the acquiring a new cache expiration time corresponding to the current response packet received by the proxy server includes:
  • the standard cache mechanism based on the HTTP protocol obtains a cache time parameter of the HTTP protocol standard cache mechanism from a cache control field, a cache compilation control field, or a cache expiration control field of the response message;
  • the executing the cache instruction that updates the cache expiration time refers to updating the corresponding response message. Storing the local proxy cache time in the response header of the message, or updating a corresponding field of the cache message corresponding to the HTTP protocol standard cache mechanism of the cache message corresponding to the response message, and receiving the The current time of the response message is updated as the current cache time to a specified field in which the current cache time is stored.
  • the HTTP protocol-based cache device includes:
  • the HTTP packet obtaining unit is configured to obtain an HTTP packet, where the HTTP packet carries a content type field, and the corresponding value of the content type field is used to describe a data category of the content of the packet in the HTTP packet.
  • An HTTP packet parsing unit configured to parse the HTTP packet, and obtain a corresponding value of the content type field in the packet
  • a local cache parameter setting unit configured to separately set a local cache parameter specific to the HTTP packet according to a corresponding value of the content type field
  • the cache processing unit is configured to perform corresponding cache processing on the HTTP packet based on the local cache parameter.
  • the local cache parameter setting unit includes:
  • a content secondary update probability setting subunit configured to differentially set the content secondary update probability according to the corresponding value of the content type field, where the content secondary update probability is used to reflect the HTTP packet in the source server The frequency of the frequency being updated;
  • the local cache time setting sub-unit is configured to calculate the local cache time by using the content secondary update probability as a parameter, so that the length of the local cache time is consistent with the height of the updated frequency.
  • the HTTP protocol-based requesting device includes:
  • An HTTP request message receiving unit configured to receive, by the proxy server, an HTTP request message sent by the client, where the HTTP request message carries a URL;
  • a cache hit determination unit configured to determine, by the proxy server, whether the local cache hits according to the URL
  • a cache processing unit configured to perform corresponding processing according to a standard cache mechanism of the HTTP protocol when a miss occurs; obtain a cached content that has been hit when hit, and determine the cached content that has been hit based on a preset local proxy cache parameter Whether it expires, if it expires, the expired return source verification instruction is sent to the source server, and if it has not expired, the cached content is returned to the client.
  • the response device based on the HTTP protocol provided by the application includes:
  • a response message receiving unit configured to receive, by the proxy server, an HTTP response message from the source server;
  • response message parsing unit configured to parse the response message, and determine whether the response message includes a content type field
  • a standard cache mechanism processing unit of the HTTP protocol configured to: if the response message parsing unit determines the response If the message does not contain the content type field, the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the response processing is ended.
  • a local cache rule processing unit configured to: if the response message parsing unit determines that the response message includes a content type field, obtain a corresponding value of the content type field; and according to the corresponding value difference of the content type field Setting a local proxy cache parameter specific to the response message; performing corresponding cache processing on the response message based on the local proxy cache parameter, and executing a corresponding return instruction.
  • the local cache rule processing unit includes:
  • a content type field parsing subunit configured to obtain a corresponding value of the content type field
  • a local proxy cache parameter setting sub-unit configured to differently set a local proxy cache parameter specific to the response packet according to a corresponding value of the content type field
  • the cache and return instruction processing sub-unit is configured to perform corresponding cache processing on the response message based on the local proxy cache parameter, and execute a corresponding return instruction.
  • the local proxy cache parameter setting subunit includes:
  • a content secondary update probability setting subunit configured to differentially set the content secondary update probability according to a data category of the message content in the response message described by the corresponding value of the content type field, the content The secondary update probability is used to reflect the frequency at which the response message is updated at the source server;
  • the local proxy cache time setting sub-unit is configured to calculate the local proxy cache time by using the content secondary update probability as a parameter, so that the length of the local proxy cache time is consistent with the updated frequency.
  • the HTTP protocol-based webpage access system provided by the present application includes the request device described in the above technical solution and the response device according to any one of the above technical solutions.
  • an electronic device provided by the present application includes:
  • a memory configured to store at least one of a cache device based on an HTTP protocol, a request device based on an HTTP protocol, and a response device based on an HTTP protocol,
  • the HTTP packet carries a content type field; the corresponding value of the content type field is used to describe a data category of the content of the packet in the HTTP packet;
  • the proxy server receives the HTTP request packet sent by the client, where the HTTP request packet carries the URL;
  • the cached content that has been hit is obtained, and based on the preset local proxy cache parameter, it is determined whether the cached content that has been hit expires.
  • the expired source verification instruction is sent to the source server.
  • the response device based on the HTTP protocol when executed by the processor, performs the following steps:
  • the proxy server receives the HTTP response message from the source server
  • the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the response processing is ended;
  • the HTTP protocol-based caching method, request method, and response method provided by the present application are all based on the HTTP protocol, and the standard caching mechanism provided by the HTTP protocol is improved, wherein the specific improvement of the caching method is: obtaining an HTTP packet, and parsing And obtaining, by the HTTP packet, a corresponding value of a content type field (Content-Type field) in the packet, and then setting a local cache parameter specific to the HTTP packet according to the corresponding value of the content type field, and And performing corresponding cache processing on the HTTP packet based on the local cache parameter.
  • the specific improvement of the caching method is: obtaining an HTTP packet, and parsing And obtaining, by the HTTP packet, a corresponding value of a content type field (Content-Type field) in the packet, and then setting a local cache parameter specific to the HTTP packet according to the corresponding value of the content type field, and And performing corresponding cache processing on the HTTP packet based on the local cache parameter.
  • the content type field is set by the source server and is used to describe the data category of the packet content in the HTTP packet, so as to implement a cache method for differentiating the cache based on the content of the packet on the proxy server or other device to be cached.
  • a cache method for differentiating the cache based on the content of the packet on the proxy server or other device to be cached Compared with the traditional cache method of the standard cache mechanism based on the HTTP protocol, one aspect of the present application has the following advantages:
  • the caching method described in the present application is only an improvement based on the standard HTTP protocol, so the present application
  • the caching method increases the method for actively setting the local cache by the proxy server based on the standard caching mechanism of the HTTP protocol, thereby improving the hit rate of the proxy cache and improving the user access speed.
  • the caching method described in the present application is an improvement based on the standard HTTP protocol, the caching method described in this application is applicable not only to the scenario where the proxy server actively sets the local cache, but also applies to the HTTP protocol. All application scenarios corresponding to the standard caching mechanism.
  • the local cache parameter specific to the HTTP packet to which it belongs is differentiated according to the corresponding value of the content type field, and the local cache parameter includes the content secondary update probability and the local cache time.
  • the cache method of the present application is used because the value of the content type field is used to describe the data type of the message content in the HTTP packet, and the frequency of the HTTP message is updated on the source server.
  • the set local cache time can reasonably control the frequency of the return source check, thereby ensuring that the cached content is updated in time, and also controlling the cost of the return source bandwidth.
  • FIG. 1 is a schematic flowchart of a method for caching based on the HTTP protocol provided by the first embodiment of the present application.
  • FIG. 2 is a flow chart of a specific embodiment of the steps of the differential setting in the first embodiment.
  • FIG. 3 is a flowchart of a method for requesting an HTTP protocol according to a second embodiment of the present application.
  • FIG. 4 is a flowchart of a method for responding based on the HTTP protocol provided by the third embodiment of the present application.
  • Fig. 5 is a flow chart showing a specific embodiment of the response status code identifying process in the third embodiment.
  • FIG. 6 is a flowchart of a specific implementation manner of differentially setting a local proxy cache time in the third embodiment.
  • FIG. 7 is a schematic diagram of a cache device based on the HTTP protocol provided by the fourth embodiment of the present application.
  • FIG. 8 is a schematic diagram of a request apparatus based on an HTTP protocol provided by a fifth embodiment of the present application.
  • FIG. 9 is a schematic diagram of a response device based on the HTTP protocol provided by the sixth embodiment of the present application.
  • FIG. 10 is a schematic structural diagram of a webpage access system based on the HTTP protocol provided by the seventh embodiment of the present application.
  • a caching method, a request method, a response method, and a corresponding caching device, requesting device, response device, and webpage access method based on the HTTP protocol are respectively provided, which are described in detail in the following embodiments. .
  • FIG. 1 is a schematic flowchart of a method for caching based on the HTTP protocol provided by the first embodiment of the present application.
  • the caching method includes the following steps:
  • Step 101 Acquire an HTTP packet, where the HTTP packet carries a content type field, and the corresponding value of the content type field is used to describe a data category of the packet content in the HTTP packet.
  • a standard HTTP message usually consisting of one or more headers and an optional message body.
  • the HTTP header usually includes four parts: a general header, a request header, a response header, and a physical header.
  • the message body is a field for storing the content of the message.
  • the HTTP packet obtained in this embodiment includes at least a physical header and entity information, where the entity header includes a content type field (Content-Type field), and the entity information stores the packet content of the HTTP packet.
  • the corresponding value of the content type field is used to describe the data category of the message content in the HTTP packet, thereby instructing the client to display or process the content in a suitable manner.
  • Step 102 Parse the HTTP packet, and obtain a corresponding value of the content type field in the packet.
  • the content type field format is: Content-Type: type/subtype, where the value of "type” can be divided into 7 categories:
  • the text message type (text type) is used for the text information that is represented by the standard.
  • the text information may be a plurality of character sets and or a plurality of formats; when the content type field is specifically assigned, the specific value is represented by text;
  • the multiple parts used to connect the message body constitute a message type (multipart type), which is used to connect multiple parts of the message body to form a message, which can be different types of data; when assigning values to the content type field, Express a specific value in multipart;
  • a type (message type) used to wrap an email message which is used to wrap an email (E-mail) message.
  • E-mail email
  • the type (image type) used to transmit static image data used to transmit static image data, and to specify a specific value when image is specifically assigned to the content type field;
  • the type (audio type) used to transmit audio and sound data used to transmit audio or audio data.
  • audio type used to transmit audio and sound data.
  • the specific value is represented by audio;
  • the type (video type) used to transmit the motion picture data used to transmit the motion picture data, may be a video data format edited together with the audio, and when the content type field is specifically assigned, the specific value is represented by video.
  • the data category of the message content in the HTTP message is obtained by parsing the value of "type" of the content type field.
  • Step 103 Differentiate the local cache parameter specific to the HTTP packet according to the corresponding value of the content type field.
  • the above local cache parameters include a content secondary update probability and a local cache time.
  • step of differentiating the setting includes:
  • Step 201 Differentiate the content secondary update probability according to the corresponding value of the content type field, where the content secondary update probability is used to reflect the level of the HTTP message being updated at the source server.
  • the value of "type" of the content type field is used to describe the data type of the message content in the HTTP packet, and the frequency of the message content of different data categories is different by the source server.
  • the text message type, the type used to wrap an email message, and the part used to connect the message body to form a message correspond to the type of message used to publish text or message content, while the text and message are Most easily updated by the source server;
  • the type used to transfer static image data and the type used to transfer application data and binary data are the types used to publish images and executables, and the possibility that images and executables are updated by the source server Sex is much lower than text and messages;
  • the type used to transmit audio and sound data and the type used to transmit motion picture data are the types used to publish audio and video, and audio and video content is least likely to be updated by the source server.
  • the value of the "type" of the content type field can reflect the frequency of the message content of the HTTP message being updated on the original server.
  • the so-called differentiated setting means that the value range of the secondary update probability of the content corresponding to the HTTP packet is differently set according to the frequency of the frequency, so that the secondary update probability can reflect the HTTP packet at the source server. The frequency of the frequency being updated.
  • the corresponding value of the content type field indicates that the message content is a type of a text message, or a type indicating that the message content is used to package an email message, or indicates the content of the message
  • the frequency of the corresponding type of the message identified by the value is higher in the original server, and the content corresponding to the type of the message is
  • the value range of the secondary update probability is set to be close to a certain interval of 100%.
  • the interval of >50% and ⁇ 99% is specifically set.
  • the value of the second update probability of the content corresponding to the type of the message is set to be close to a certain interval of 0%.
  • it is specifically set to an interval of ⁇ 50% and ⁇ 1%.
  • the corresponding value of the content type field indicates that the content of the message is used to transmit a type of static picture data, or indicates that the content of the message is used to transmit type of application data and binary data
  • the value of the corresponding type of the message identified by the value is medium
  • the value of the second update probability of the content corresponding to the type of the message is set to be between the following boundaries.
  • the value of the content secondary update probability is set to 50%.
  • Step 202 Calculate the local cache time by using the content secondary update probability as a parameter, so that the length of the local cache time is consistent with the height of the updated frequency.
  • the HTTP protocol provides a standard set of caching mechanisms that are implemented by setting the specified fields of messages based on the HTTP protocol.
  • the specified fields related to the cache are: a cache control field (Cache-Control field), a cache compile control field (Pragma field), and a cache expiration control field (Expires field).
  • the cache control field is set by the source server to specify whether the browser and the proxy server can cache the content, and is used to specify the value of the cache time; the cache control field can also be set by the client to specify the client to initiate The request does not use the cached content, but directly obtains the latest content on the source server; the cache compilation control field is set by the client to specify that the client-initiated request does not use the cached content, but directly obtains the latest content on the source server.
  • the priority is lower than the same setting corresponding to the cache control field; the cache expiration control field is set by the source server to specify the value of the cache time, which has a lower priority than the cache time set by the cache control field.
  • the cache control field, the cache compile control field, and the cache expiration control field are all set by the source server or the client, and the proxy server or other cache device is based on the obtained HTTP packet.
  • the values of these fields are used for corresponding cache processing, wherein the cache time obtained by the fields is a key parameter for performing cache processing.
  • the caching method described in the present application implements a method of locally setting a cache on a proxy server or other caching device based on the HTTP protocol standard caching mechanism.
  • the key point is how to actively calculate the cache by a proxy server or other caching device.
  • Time parameter this embodiment uses the following steps to calculate:
  • the method includes: obtaining the cached control field, whether the content can be cached, and setting the cache time; whether the value of the content can be cached under the cache compile control field; and obtaining the expiration under the cache expiration control field.
  • the value of time (HTTP-date).
  • the priority rule of the standard cache mechanism based on the HTTP protocol determines whether there is a setting of the content that cannot be cached in the field value obtained in the above step 202-1), and then determines the cache control field or the cache expiration control. Whether the corresponding value of the field contains a valid cache time. If yes, the valid cache time is obtained, where the cache control field specifies a cache time priority higher than a cache time specified by the cache expiration control field.
  • Force_ttl (1–A)cache_time, where force_ttl is the local cache time, A is the content secondary update probability, and cache_time is included by the corresponding value of the cache control field or the cache expiration control field. The relative time corresponding to the effective cache time.
  • the valid cache time included in the corresponding value of the cache expiration control field is an absolute time format. In the calculation, the cache time is converted into a relative time and then calculated.
  • Force_ttl (1 ⁇ A)max_default_cache_time, where force_ttl is the local cache time, A is the content secondary update probability, and max_default_cache_time is the maximum value preset for the local cache time.
  • the maximum value is set to 60 seconds that is typically recommended by Internet applications.
  • the Internet application usually has a suggested minimum value for the cache time. Since the parameter A used in the above calculation step has a value range of 1% to 99%, the force_ttl obtained by the above two calculations of the local cache time, that is, the formula of force_ttl is obtained. It may be less than the recommended minimum value, so you need to set a minimum local cache time min_default_cache_time to limit it.
  • the minimum value is configured as 1 second recommended by the Internet application, and when the local cache time obtained from the two formulas for calculating force_ttl is less than the minimum value, Then take the minimum value as the local cache time. Similarly, if the local cache time obtained from the two formulas for calculating force_ttl is greater than the maximum value configured in this embodiment, the maximum value is taken as the local cache time.
  • the proxy server or the cache device can also actively set the local cache time, thereby eliminating the need to frequently obtain the requested content from the source server, and at the same time ensuring that the cache device is reasonable.
  • the frequency of the cache is updated, that is, the frequency of the return source check can be reasonably controlled.
  • Step 104 Perform corresponding cache processing on the HTTP packet based on the local cache parameter.
  • Step 104 is a specific step of the cache processing, including the following two steps:
  • Cache priority rule based on the HTTP protocol standard cache mechanism, setting the local cache parameter with a higher priority than the cacheable or cache setting parameter of the HTTP protocol standard cache mechanism, and lower than the HTTP protocol
  • the standard cache mechanism is not cacheable or does not use cache setting parameters.
  • the standard caching mechanism further includes a corresponding cache priority rule.
  • the priority is set to be higher than the cacheable or cache setting parameter of the HTTP protocol standard caching mechanism, and is lower than the HTTP protocol standard caching mechanism.
  • Cache or no cache setting parameters that is, the local cache time priority is higher than the cache time set by the cache control field or the cache expiration control field in the HTTP message header, and other operations follow the HTTP protocol standard cache mechanism.
  • the cache method described in the present application follows the HTTP protocol standard cache mechanism to perform corresponding cache instruction setting and corresponding cache operation.
  • a caching method based on the HTTP protocol involves interaction with the client direction and interaction with the source server, and the corresponding application further provides a request method based on the HTTP protocol.
  • FIG. 3 is a flowchart of a method for requesting an HTTP protocol according to a second embodiment of the present application.
  • This embodiment assumes a scenario for deploying a proxy server between a client and a source server, and setting a cache service on the proxy server, but does not exclude the standard cache mechanism corresponding to applying the request method described in the present application to the HTTP protocol. Other scenes.
  • the request method refers to a method for the proxy server to process the request from the client, including the following steps:
  • Step 301 The proxy server receives an HTTP request packet sent by the client, where the HTTP request packet carries a URL.
  • the proxy server is classified by the controller and can be divided into a forward proxy and a reverse proxy.
  • the forward proxy mode source service The server does not perceive the existence of the client, but the client can force the cached content of the proxy server to obtain the content of the request from the source server; the reverse proxy mode client does not perceive the existence of the source server, but the proxy server serves as the source.
  • the server's client, and the source server controls the proxy server's caching proxy service.
  • the proxy server receives the HTTP request packet sent by the client in the forward proxy mode, the URL (Uniform Resource Locator) carried by the HTTP request packet is the source server as the host address.
  • URL Uniform Resource Locator
  • the URL of the corresponding request content on the source server if the proxy server receives the HTTP request message sent by the client in the reverse proxy mode, the URL carried by the HTTP request message is cached on the proxy server with the proxy server as the host address.
  • the URL of the corresponding content if the proxy server receives the HTTP request message sent by the client in the reverse proxy mode, the URL carried by the HTTP request message is cached on the proxy server with the proxy server as the host address.
  • Step 302 The proxy server determines, according to the URL, whether the local cache hits.
  • this step should be based on the HTTP protocol standard caching mechanism.
  • the setting if it is included, should be processed according to the standard caching mechanism of the HTTP protocol. If not, the step of determining whether the local cache is hit according to the URL is executed. This allows the proxy server to have the cache setting priority higher than the HTTP cache cache mechanism's use cache setting parameter, and is lower than the HTTP protocol standard cache mechanism's unused cache setting parameter. For example, if the cache control field and the cache compile control field of the request message header do not include no-cache or no-store settings, perform the local judgment according to the URL as described in this step. Whether the cache hits.
  • Step 303 If the result of the determination in step 302 is a miss, the corresponding processing is performed based on the standard cache mechanism of the HTTP protocol.
  • the corresponding processing of the standard caching mechanism based on the HTTP protocol refers to the cache control field, the cache compile control field, and the cache expiration control field of the HTTP request message, and other fields involved in the HTTP protocol standard caching mechanism or related rules. Processing. For example, for the forward proxy, it is further determined whether the corresponding value of the cache control field, the cache compile control field, or the cache expiration control field of the HTTP request message does not use the cache configuration, and then performs corresponding processing.
  • Step 304 If the result of the determination in step 302 is a hit, the corresponding processing is performed based on the preset local cache parameter, which specifically includes the following steps:
  • the pre-set local proxy cache parameter includes a preset local proxy cache time in a response header of the cached HTTP packet on the proxy server, and the local proxy cache time is obtained by the following steps:
  • the “type” value of the content type field is used to describe the data category of the message content in the HTTP message, and the message content of different data categories is updated by the source server.
  • the frequency of the difference is different.
  • the so-called difference setting means that the value range of the secondary update probability of the content corresponding to the HTTP message is differently set according to the frequency of the frequency, so that the second update probability can reflect the The frequency at which the HTTP message is updated on the source server.
  • the step of determining whether the cached content that has been hit expires based on the preset local proxy cache parameter is specifically performed as follows:
  • step 304-1 For the standard cache mechanism compatible with the HTTP protocol, before performing step 304-1), it is executed to determine whether the message response header corresponding to the cached content that has been hit contains a content type field, and if not, the standard based on the HTTP protocol.
  • the caching mechanism processes the corresponding processing and ends the request processing flow; if it is included, it starts the execution step 304-1).
  • step 304-2) If the result of the determination in step 304-1) is expired, the expired return source verification instruction is sent to the source server.
  • step 304-3 If the result of the determination in step 304-1) is not expired, the cached content is returned to the client.
  • a request method based on the HTTP protocol is provided.
  • the client does not perceive the specific details of the cache setting and processing on the proxy server, and the packet returned to the client does not include the response header.
  • Local proxy cache parameter in .
  • the present application also provides a response method based on the HTTP protocol.
  • FIG. 4 is a flowchart of a method for responding based on the HTTP protocol provided by the third embodiment of the present application.
  • This embodiment assumes a scenario for deploying a proxy server between a client and a source server, and setting a cache service on the proxy server, but does not exclude other methods corresponding to the standard cache mechanism of the HTTP protocol applied to the response method described in the present application. Scenes.
  • the response method refers to a method for the proxy server to process the response packet from the source server, including the following steps:
  • Step 401 The proxy server receives an HTTP response message from the source server.
  • FIG. 5 is a flowchart of a specific implementation manner of a response status code identification process in the third embodiment, and the specific steps are as follows:
  • Step 501 Acquire a response status code carried in the response packet.
  • Step 502 Determine a category of the response status code.
  • Step 503 If the response status code is 304, the source server determines that the content has not changed, and may continue to use the cached content in the proxy server, and specifically includes the following steps: executing the local cache report corresponding to the response packet. The content of the text is returned to the return instruction of the client; the new cache expiration time corresponding to the current response message received by the proxy server is acquired; the cache instruction for updating the cache expiration time is executed; and the response processing is ended.
  • Step 504 If the response status code is 200, it indicates that the content is acquired by the proxy server for the first time, or that the source server determines that the content has been updated, and the proxy server needs to re-cache the content. In this case, the steps of caching the content described below need to be continued.
  • Step 402 Parse the response message, and determine whether the response message includes a content type field.
  • the specified fields related to the cache are: a cache control field (Cache-Control field), The cache compile control field (Pragma field) and the cache expiration control field (Expires field).
  • the cache control field, the cache compile control field, and the cache expiration control field of the HTTP response message should be determined first. Whether the value includes a setting that is not cached, if it is included, it should be processed according to the standard cache mechanism of the HTTP protocol. If not, the step of determining whether the response message includes a content type field is performed. This allows the proxy server to have the cache setting priority higher than the cacheable setting parameter of the HTTP protocol standard caching mechanism and lower than the non-cacheable setting parameter of the HTTP protocol standard caching mechanism. For example, if the cache control field or the cache compile control field of the response packet header does not include a no-cache or a no-store setting, the response message described in this step is executed. Whether to include a content type field.
  • Step 403 If the result of the determination in step 402 is not included, the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the current response processing is ended.
  • the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the specific implementation manner is as follows:
  • the cache compile control field, and the cache expiration control field includes a non-cacheable setting or a valid cache time is not set; the valid cache time is an HTTP protocol standard cache mechanism. Cache time parameters.
  • Step 404 If the result of the determination in step 402 is included, the step of performing the following cache setting is performed;
  • Step 405 Acquire a corresponding value of the content type field.
  • Step 406 Differentiate the local proxy cache parameter specific to the response message according to the corresponding value of the content type field.
  • the local proxy cache parameter includes a content secondary update probability and a local proxy cache time.
  • FIG. 6 is a flowchart of a specific implementation manner of differentially setting a local proxy cache time in the third embodiment.
  • Step 601 Differentiate the content secondary update probability according to the data category of the message content in the response message described by the corresponding value of the content type field, where the content secondary update probability is used to reflect the Response The frequency at which the message is updated on the source server.
  • the “type” value of the content type field is used to describe the data category of the message content in the HTTP message, and the message content of different data categories is updated by the source server.
  • the frequency is different.
  • the specific meaning of the "type" value is described in the description of the first embodiment.
  • the so-called differentiated setting means that the value range of the secondary update probability of the content corresponding to the HTTP packet is differently set according to the frequency of the frequency, so that the secondary update probability can reflect the HTTP packet at the source server.
  • the frequency of the frequency being updated.
  • the corresponding value of the content type field indicates that the message content is a type of a text message, or a type indicating that the message content is used to package an email message, or the content of the message is
  • the frequency of the corresponding type of the message identified by the value is updated at the original server, and the content corresponding to the type of the message is twice.
  • the value range of the update probability is set to be close to a certain interval of 100%.
  • the interval of >50% and ⁇ 99% is specifically set.
  • the value of the second update probability of the content corresponding to the type of the message is set to be close to a certain interval of 0%.
  • it is specifically set to an interval of ⁇ 50% and ⁇ 1%.
  • the corresponding value of the content type field indicates that the content of the message is used to transmit a type of static picture data, or indicates that the content of the message is used to transmit type of application data and binary data
  • the value of the corresponding type of the message identified by the value is medium
  • the value of the second update probability of the content corresponding to the type of the message is set to be between the following boundaries.
  • the value of the content secondary update probability is set to 50%.
  • Step 602 Calculate the local proxy cache time by using the content secondary update probability as a parameter, so that the length of the local proxy cache time is consistent with the height of the updated frequency.
  • the method includes: obtaining the cached control field, whether the content can be cached, and setting the cache time; whether the value of the content can be cached under the cache compile control field; and obtaining the expiration under the cache expiration control field.
  • Time (HTTP-date) value is a value that specifies the time at which the content can be cached.
  • the priority rule of the standard cache mechanism based on the HTTP protocol determines whether there is a setting of the content that cannot be cached in the field value obtained in the above step 602-1), and then determines the cache control field or the cache expiration control. Whether the corresponding value of the field contains a valid cache time. If yes, the valid cache time is obtained, where the cache control field specifies a cache time priority higher than a cache time specified by the cache expiration control field.
  • step 602-3) If the result of the above step 602-2) is included, the calculation method of the local proxy cache time is:
  • Force_ttl (1–A)cache_time, where force_ttl is the local proxy cache time, A is the content secondary update probability, and cache_time is included by the corresponding value of the cache control field or the cache expiration control field. The relative time corresponding to the valid cache time.
  • the valid cache time included in the corresponding value of the cache expiration control field is an absolute time format. In the calculation, the cache time is converted into a relative time and then calculated.
  • step 602-2 If the result of the above step 602-2) is not included, the calculation method of the local proxy cache time is:
  • Force_ttl (1 ⁇ A)max_default_cache_time, where force_ttl is the local proxy cache time, A is the content secondary update probability, and max_default_cache_time is the maximum value preset for the local proxy cache time.
  • the maximum value is configured to be 60 seconds that is typically recommended by Internet applications.
  • the Internet applications usually have a suggested minimum value for the cache time. Since the parameter A used in the above calculation step has a value range of 1% to 99%, the above two calculations of the local proxy cache time, that is, the formula of force_ttl are obtained. Force_ttl may be less than the recommended minimum value, so you need to set a minimum min_default_cache_time of the local proxy cache time in advance. In this embodiment, the minimum value is configured as 1 second recommended by the Internet application. When the force_ttl obtained from the two formulas for calculating force_ttl is less than the minimum value, the minimum value is taken as the local proxy cache time. Similarly, if you get the local proxy from the above two formulas that calculate force_ttl When the cache time is greater than the maximum value set in this embodiment, the maximum value is taken as the local proxy cache time.
  • the proxy server or the cache device can also actively set the local proxy cache time, thereby eliminating the need to frequently obtain the requested content from the source server, and at the same time ensuring the proxy server or the cache device. Updating the cache content at a reasonable frequency can reasonably control the frequency of the return source check.
  • Step 407 Perform corresponding cache processing on the response message based on the local proxy cache parameter, and execute a corresponding return instruction. This is achieved by the following steps:
  • the determination of whether the content type field is included by step 402 ensures that the priority of the local proxy cache time parameter is higher than the corresponding parameter set by the HTTP protocol standard cache mechanism, and is compatible with HTTP. Intrinsic cache handling of the standard caching mechanism of the protocol.
  • the step of acquiring a new cache expiration time corresponding to the current response packet received by the proxy server, and performing a cache instruction for updating the cache expiration time includes the following steps:
  • the method of the step of setting the local proxy cache parameter is the same as the step of step 601 to step 602. For details, refer to step 601 to step 602, and details are not described herein again.
  • the standard caching mechanism based on the HTTP protocol obtains a cache time parameter of the HTTP protocol standard caching mechanism from a cache control, a cache compile control, or a cache expiration control field of the response message.
  • the caching instruction for performing the update of the cache expiration time refers to updating the local proxy cache time in the response header of the cached message corresponding to the response packet, or updating the response packet
  • Corresponding fields of the cache time parameter of the HTTP protocol standard cache mechanism are stored in the corresponding cached message, and the current time of receiving the response message is updated as the current cache time to the storage of the current cache time. Field in.
  • the present application further provides a cache device, a request device, and a response device based on the HTTP protocol, which are described below. Since the device embodiment is substantially similar to the method embodiment, the description is relatively simple, and the relevant portions can be referred to the description of the method embodiment. The device embodiments described below are merely illustrative.
  • FIG. 7 is a schematic diagram of a cache device based on the HTTP protocol provided by the fourth embodiment of the present application.
  • a cache device based on the HTTP protocol in this embodiment includes: an HTTP packet obtaining unit 7-1, an HTTP packet parsing unit 7-2, a local cache parameter setting unit 7-3, and a cache processing unit 7-4.
  • the HTTP packet obtaining unit 7-1 is configured to obtain an HTTP packet, where the HTTP packet carries a content type field, and the corresponding value of the content type field is used to describe the content of the packet in the HTTP packet. Data category.
  • the HTTP packet parsing unit 7-2 is configured to parse the HTTP packet, and obtain a corresponding value of the content type field in the packet.
  • the local cache parameter setting unit 7-3 is configured to differentiate the local cache parameter specific to the HTTP message according to the corresponding value of the content type field.
  • the local cache parameter setting unit 7-3 includes a content secondary update probability setting sub-unit 7-3-1 and a local cache time setting sub-unit 7-3-2.
  • the content secondary update probability setting sub-unit 7-3-1 is configured to differentiate the content secondary update probability according to the corresponding value of the content type field, where the content secondary update probability is used to reflect the Indicates the frequency at which the HTTP message is updated on the source server.
  • the local cache time setting sub-unit 7-3-2 is configured to calculate the local cache time by using the content secondary update probability as a parameter, so that the length of the local cache time and the updated frequency are high or low Consistent.
  • the cache processing unit 7-4 is configured to perform corresponding cache processing on the HTTP packet based on the local cache parameter.
  • FIG. 8 is a schematic diagram of an HTTP protocol-based requesting apparatus according to a fifth embodiment of the present application.
  • the request device of the HTTP protocol includes: an HTTP request message receiving unit 8-1, a cache hit determining unit 8-2, and a cache processing unit 8-3.
  • the HTTP request message receiving unit 8-1 is configured to receive, by the proxy server, an HTTP request message sent by the client, where the HTTP request message carries a URL.
  • the cache hit determination unit 8-2 is configured to determine, by the proxy server, whether the local cache hits according to the URL.
  • the cache processing unit 8-3 is configured to perform corresponding processing according to a standard cache mechanism of the HTTP protocol when a miss occurs; when hit, obtain the cached content that has been hit, and determine that the hit has been hit based on the preset local proxy cache parameter. Whether the cached content expires, if it expires, sending an expired return source verification instruction to the source server, and if not expired, returning the cached content to the client.
  • FIG. 9 is a schematic diagram of a response device based on the HTTP protocol provided by the sixth embodiment of the present application.
  • the response device based on the HTTP protocol in this embodiment includes: a response message receiving unit 9-1, a response message parsing unit 9-2, a standard cache mechanism processing unit 9-3 of the HTTP protocol, and a local cache rule processing unit. 9-4.
  • the response message receiving unit 9-1 is configured to receive, by the proxy server, an HTTP response message from the source server.
  • the response message parsing unit 9-2 is configured to parse the response message, and determine whether the response message includes a content type field.
  • the standard cache mechanism processing unit 9-3 of the HTTP protocol is configured to: if the response message parsing unit determines that the response message does not include a content type field, perform corresponding cache processing according to a standard cache mechanism of the HTTP protocol, And end this response processing.
  • the local cache rule processing unit 9-4 is configured to: if the response message parsing unit determines that the response message includes a content type field, obtain a corresponding value of the content type field; according to the content type field And correspondingly setting a local proxy cache parameter specific to the response message; performing corresponding cache processing on the response packet based on the local proxy cache parameter, and executing a corresponding return instruction.
  • the local cache rule processing unit 9-4 includes: a content type field parsing subunit 9-4-1, a local proxy cache parameter setting subunit 9-4-2, a cache and a return instruction processing subunit 9-4-3 .
  • the content type field parsing sub-unit 9-4-1 is configured to obtain a corresponding value of the content type field.
  • the local proxy cache parameter setting subunit 9-4-2 is configured to differentiate the local proxy cache parameter specific to the response packet according to the corresponding value of the content type field.
  • the local proxy cache parameter setting subunit 9-4-2 includes a content secondary update probability setting subunit 9-4-2-1 and a local proxy cache time setting subunit 9-4-2-2.
  • the content secondary update probability setting subunit 9-4-2-1 is configured to differentiate the data category of the message content in the response message according to the corresponding value of the content type field.
  • the content secondary update probability, the content secondary update probability is used to reflect the level of the response message being updated at the source server.
  • the local proxy cache time setting sub-unit 9-4-2-2 is configured to calculate the local proxy cache time by using the content secondary update probability as a parameter, so that the local proxy cache time is different from the It is consistent with the level of the updated frequency.
  • the cache and return instruction processing sub-unit 9-4-3 is configured to perform corresponding cache processing on the response message based on the local proxy cache parameter, and execute a corresponding return instruction.
  • FIG. 10 is a schematic structural diagram of a webpage access system based on the HTTP protocol provided by the seventh embodiment of the present application.
  • the webpage access system based on the HTTP protocol includes: a client 1001, a proxy server 1002, and a source server 1003.
  • the client 1001 sends a request message to the proxy server 1002, the message carries a URL to obtain content corresponding to the URL; after receiving the request message, the proxy server 1002 processes the request message, if the local has If the cached content includes the content corresponding to the request and the cached content has not expired, the locally cached content corresponding to the request is returned to the client, if the locally cached content does not include the content or cache corresponding to the request.
  • the source server 1003 continues to initiate the request; after receiving the request sent by the proxy server 1002, the source server 1003 returns a corresponding response message to the proxy server 1002; after receiving the response message, the proxy server 1002 The response message is processed and the content corresponding to the client request is returned to the client.
  • the proxy server 1002 further includes the requesting device and the responding device described in the present application, and the requesting device completes the processing of the request packet, and the responding device completes the processing of the response packet.
  • the foregoing provides an HTTP device-based caching method, a request method, a response method, and an embodiment of a cache device, a request device, a response device, and a response.
  • the application further provides an electronic device, where the electronic device includes:
  • a memory configured to store at least one of a cache device based on an HTTP protocol, a request device based on an HTTP protocol, and a response device based on an HTTP protocol,
  • the HTTP packet carries a content type field; the corresponding value of the content type field is used to describe a data category of the content of the packet in the HTTP packet;
  • the proxy server receives the HTTP request packet sent by the client, where the HTTP request packet carries the URL;
  • the cached content that has been hit is obtained, and based on the preset local proxy cache parameter, it is determined whether the cached content that has been hit expires.
  • the expired source verification instruction is sent to the source server.
  • the response device based on the HTTP protocol when executed by the processor, performs the following steps:
  • the proxy server receives the HTTP response message from the source server
  • the corresponding cache processing is performed according to the standard cache mechanism of the HTTP protocol, and the response processing is ended;
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
  • RAM random access memory
  • ROM read only memory
  • Memory is an example of a computer readable medium.
  • Computer readable media including both permanent and non-persistent, removable and non-removable media may be implemented by any method or technology.
  • the information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory.
  • computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
  • embodiments of the present application can be provided as a method, system, or computer program product.
  • the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment in combination of software and hardware.
  • the application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Multimedia (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本申请提供了基于HTTP协议的缓存方法、请求方法、响应方法及相应装置。其中,所述缓存方法包括:获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。

Description

基于HTTP协议的缓存、请求、响应方法及相应装置
本申请要求2015年09月14日递交的申请号为201510583636.8、发明名称为“基于HTTP协议的缓存、请求、响应方法及相应装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及互联网领域,尤其涉及一种基于HTTP协议的缓存方法、请求方法、响应方法、缓存装置、请求装置、响应装置,以及网页访问系统。
背景技术
近年来,由于互联网技术发展迅猛,用户通过互联网进行交互的内容从以文字、图像、文件此类数据量较小的数据为主,发展为越来越多的涉及到在线视频和音频此类数据量较大的数据;另外,由于互联网用户规模急剧增长,使网络中数据流量进一步激增,给网络的带宽带来巨大的压力。为了缓解网络带宽的巨大压力,通常会在客户端和源服务器之间靠近客户端的一侧,部署代理服务器,从而通过在代理服务器上设置缓存服务对源服务器上的网络内容进行缓存,使用户就近获取网络内容。通常用户获取的网络内容是基于HTTP(超文本传输协议,Hyper Text Transfer Protocol)协议传输的,相应的,在代理服务器上设置的是基于HTTP协议的缓存服务。
HTTP协议是超文本传输协议(Hyper Text Transfer Protocol)的缩写,是互联网上应用最为广泛的一种网络协议,用于提供客户端和服务器端之间进行请求和应答的标准。HTTP协议提供一套标准的缓存机制,该缓存机制通过对基于HTTP协议的报文的指定字段进行设置实现。标准HTTP协议中,涉及缓存的指定字段有:缓存控制字段(Cache-Control字段)、缓存编译控制字段(Pragma字段)和缓存过期控制字段(Expires字段)。其中,缓存控制字段是由源服务器设置,用于指定浏览器以及代理服务器是否可以缓存该内容,同时用于指定缓存时间的值;缓存控制字段也可以由客户端设置,用于指定客户端发起的请求不使用缓存内容,而是直接获取源服务器上最新的内容;缓存编译控制字段由客户端设置,用于指定客户端发起的请求不使用缓存内容,而是直接获取源服务器上最新的内容,其优先级低于缓存控制字段对应的相同设置;缓存过期控制字段由源服务器设置,用于指定缓存时间的值,其优先级低于缓存控制字段所设置的缓存时间。HTTP协议所提供的如上所述的标准缓存机制有如下问题:
1.代理服务器无法主动设置内容的缓存时间,只能遵循源服务器的设置。例如,如果源服务器没有对内容设置缓存时间,内容将无法在代理服务器缓存,用户所需访问的内容仍旧需要源服务器返回,从而导致代理缓存命中率低、用户访问速度慢以及回源流量大等问题。
2.代理服务器不能及时更新已缓存内容,对于源服务器已经更新但尚未过期的内容,需要源服务器主动刷新代理缓存或者客户端强制刷新,否则客户端访问就会拿到过期的数据,影响内容时效性和用户体验。
发明内容
本申请提供一种基于HTTP协议的缓存方法、请求方法、响应方法、缓存装置、请求装置、响应装置及网页访问系统,以解决基于现有的HTTP协议所提供的标准缓存机制下的缓存方法不能由代理服务器主动设置缓存时间,不能由代理服务器及时更新已缓存内容的问题。
为解决上述技术问题,本申请提供的基于HTTP协议的缓存方法,包括:
获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
优选的,在所述根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数的步骤中,所述本地缓存参数包括内容二次更新概率和本地缓存时间,所述差异化设置的步骤包括:
根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低;
以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
优选的,所述根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,是指所述内容类型字段的对应取值所描述的所述HTTP报文中报文内容的数据类别能反映所述HTTP报文在原服务器被更新频率的高低,以此频率高低为依据差异化设置该 HTTP报文对应的所述内容二次更新概率的取值范围,具体包括:
若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或表示所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间;
若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间;
若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型,或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:
所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;
所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
可选的,所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间,具体是设置为>50%且≤99%的区间;
所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间,具体是设置为<50%且≥1%的区间;
所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间,具体是将所述内容二次更新概率的取值设置为50%。
可选的,执行所述以所述内容二次更新概率为参数,计算所述本地缓存时间的步骤前,执行以下步骤:
为所述本地缓存时间设置最大值,所述最大值的具体数值为60秒;
为所述本地缓存时间设置最小值,所述最小值的具体数值为1秒。
优选的,所述以所述内容二次更新概率为参数,计算所述本地缓存时间,包括:
获取所述HTTP报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值;
判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间;
若包含,则所述本地缓存时间的计算方法是:
force_ttl=(1–A)cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者所述缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间;
若不包含,则所述本地缓存时间的计算方法是:
force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地缓存时间预先设置的所述最大值。
可选的,所述基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理,包括:
基于HTTP协议标准缓存机制的缓存优先级规则,设置所述本地缓存参数的优先级高于所述HTTP协议标准缓存机制的可缓存或使用缓存设置参数,且低于所述HTTP协议标准缓存机制的不可缓存或不使用缓存设置参数;
根据所述本地缓存参数设置缓存指令,并进行相应的缓存操作。
为解决上述技术问题,本申请提供的基于HTTP协议的请求方法,包括:
代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
所述代理服务器根据所述URL判断本地缓存是否命中,
若未命中,则基于HTTP协议的标准缓存机制进行相应处理;
若命中,则获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,
若过期,则向源服务器发送过期回源校验指令,
若未过期,则将所述缓存内容返回给所述客户端。
可选的,所述预先设置的本地代理缓存参数,包括所述代理服务器上已缓存的HTTP报文的响应头中预设的本地代理缓存时间,所述本地代理缓存时间通过以下步骤获取:
根据所述已缓存的HTTP报文的内容类型字段的对应取值差异化设置所述HTTP报文专属的内容二次更新概率,所述内容二次更新概率用于反映其所属的HTTP报文在源 服务器被更新频率的高低;
以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致;
将所述本地代理缓存时间写入所述HTTP报文的响应头中的指定字段中;
将所述HTTP报文被缓存的时间作为当前缓存时间写入所述HTTP报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间。
可选的,所述基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,包括:
根据已命中的所述缓存内容对应的HTTP报文的响应头,提取所述本地代理缓存时间,以及提取所述缓存内容被缓存时的所述当前缓存时间;
将所述本地代理缓存时间的格式由相对时间转换为绝对时间:force_ttl=force_ttl+proxy-save-time,其中,所述force_ttl为所述本地代理缓存时间,所述proxy-save-time为所述当前缓存时间;
判断格式转换后的所述本地代理缓存时间是否小于所述HTTP请求报文到来的时间;
若小于,则过期;
若不小于,则未过期。
为解决上述技术问题,本申请提供的基于HTTP协议的响应方法,包括:
代理服务器接收来自源服务器的HTTP响应报文;
解析所述响应报文,判断所述响应报文是否包含内容类型字段;
若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
若包含,则进入以下步骤;
获取所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
可选的,所述若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,包括:
获取所述响应报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值;
判断所述缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值是否包括不可缓存设置或没有设置有效的缓存时间;所述有效的缓存时间为HTTP协议标准缓存机制的缓存时间参数;
若判断结果为是,则将所述响应报文的内容返回给所述客户端,结束本次响应处理;
若判断结果为否,则缓存所述响应报文,并执行将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令,结束本次响应处理。
优选的,在所述根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数的步骤中,所述本地代理缓存参数包括内容二次更新概率和本地代理缓存时间,所述差异化设置的步骤包括:
根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应报文在源服务器被更新频率的高低;
以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
优选的,所述根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,是指所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别能反映所述响应报文在原服务器被更新频率的高低,以此频率高低为依据差异化设置该响应报文对应的所述内容二次更新概率的取值范围,具体包括:
若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间;
若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间;
若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型,或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:
所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;
所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
可选的,所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间,具体是设置为>50%且≤99%的区间;
所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间,具体是设置为<50%且≥1%的区间;
所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间,具体是将所述内容二次更新概率的取值设置为50%。
可选的,执行所述以所述内容二次更新概率为参数,计算所述本地代理缓存时间的步骤前,执行以下步骤:
为所述本地代理缓存时间设置最大值,所述最大值具体数值为60秒;
为所述本地代理缓存时间设置最小值,所述最小值具体数值为1秒。
优选的,所述以所述内容二次更新概率为参数,计算所述本地代理缓存时间,包括:
获取所述响应报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值;
判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间;
若包含,则所述本地代理缓存时间的计算方法是:
force_ttl=(1–A)cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者所述缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间;
若不包含,则所述本地代理缓存时间的计算方法是:
force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地代理缓存时间预先设置的所述最大值。
可选的,所述基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令,包括:
将所述本地代理缓存时间写入所述响应报文的响应头中的指定字段中;
将所述响应报文被缓存的时间作为当前缓存时间写入所述响应报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间;
缓存所述响应报文;
执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令,结束本次响应处理。
可选的,在执行所述判断所述响应报文是否包含内容类型字段的步骤前,执行以下步骤:
获取所述响应报文携带的响应状态码;
判断所述响应状态码的类别,
若所述响应状态码是304,则执行以下步骤:
执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令;获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间;执行更新缓存过期时间的缓存指令;结束本次响应处理;
若所述响应状态码是200,则继续执行所述判断所述响应报文是否包含内容类型字段的步骤。
可选的,所述获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间,包括:
判断所述响应报文是否包含内容类型字段;
若包含,则执行所述根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数的步骤,进而获取所述本地代理缓存时间参数;
若不包含,则基于HTTP协议的标准缓存机制从所述响应报文的缓存控制字段、缓存编译控制字段或缓存过期控制字段中获取所述HTTP协议标准缓存机制的缓存时间参数;
相应的,所述执行更新缓存过期时间的缓存指令,是指更新所述响应报文对应的缓 存报文的响应头中的所述本地代理缓存时间、或者更新所述响应报文对应的缓存报文的储存有所述HTTP协议标准缓存机制的缓存时间参数的相应字段,以及将接收所述响应报文的当前时间作为所述当前缓存时间更新到存储所述当前缓存时间的指定字段中。
相应的,本申请提供的基于HTTP协议的缓存装置,包括:
HTTP报文获取单元,用于获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
HTTP报文解析单元,用于解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
本地缓存参数设置单元,用于根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
缓存处理单元,用于基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
优选的,所述本地缓存参数设置单元包括:
内容二次更新概率设置子单元,用于根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低;
本地缓存时间设置子单元,用于以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
相应的,本申请提供的基于HTTP协议的请求装置,包括:
HTTP请求报文接收单元,用于代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
缓存命中判断单元,用于所述代理服务器根据所述URL判断本地缓存是否命中;
缓存处理单元,用于在未命中时,基于HTTP协议的标准缓存机制进行相应处理;在命中时,获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,若过期,则向源服务器发送过期回源校验指令,若未过期,则将所述缓存内容返回给所述客户端。
相应的,本申请提供的基于HTTP协议的响应装置,包括:
响应报文接收单元,用于代理服务器接收来自源服务器的HTTP响应报文;
响应报文解析单元,用于解析所述响应报文,判断所述响应报文是否包含内容类型字段;
HTTP协议的标准缓存机制处理单元,用于若所述响应报文解析单元判断所述响应 报文不包含内容类型字段,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
本地缓存规则处理单元,用于若所述响应报文解析单元判断所述响应报文包含内容类型字段,则获取所述内容类型字段的对应取值;根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
可选的,所述本地缓存规则处理单元包括:
内容类型字段解析子单元,用于获取所述内容类型字段的对应取值;
本地代理缓存参数设置子单元,用于根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
缓存及返回指令处理子单元,用于基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
优选的,所述本地代理缓存参数设置子单元包括:
内容二次更新概率设置子单元,用于根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应报文在源服务器被更新频率的高低;
本地代理缓存时间设置子单元,用于以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
为解决上述技术问题,本申请提供的基于HTTP协议的网页访问系统,包括上述技术方案所述的请求装置和上述技术方案的任一所述的响应装置。
为解决上述技术问题,本申请提供的一种电子设备,包括:
显示器;
处理器;以及
存储器,所述存储器被配置成存储基于HTTP协议的缓存装置、基于HTTP协议的请求装置、基于HTTP协议的响应装置中的至少一种装置,
所述基于HTTP协议的缓存装置被所述处理器执行时,执行如下步骤:
获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参 数;
基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理;
所述基于HTTP协议的请求装置,被所述处理器执行时,执行如下步骤:
代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
所述代理服务器根据所述URL判断本地缓存是否命中,
若未命中,则基于HTTP协议的标准缓存机制进行相应处理;
若命中,则获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,
若过期,则向源服务器发送过期回源校验指令,
若未过期,则将所述缓存内容返回给所述客户端;
所述基于HTTP协议的响应装置,被所述处理器执行时,执行如下步骤:
代理服务器接收来自源服务器的HTTP响应报文;
解析所述响应报文,判断所述响应报文是否包含内容类型字段;
若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
若包含,则进入以下步骤;
获取所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
本申请提供的基于HTTP协议的缓存方法、请求方法、响应方法均基于HTTP协议,并对HTTP协议所提供的标准缓存机制进行了改进,其中缓存方法的具体改进为:获取HTTP报文,通过解析所述HTTP报文获取该报文中内容类型字段(Content-Type字段)的对应取值,继而根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数,并基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。所述内容类型字段由源服务器设置,用于描述HTTP报文中报文内容的数据类别,从而在待进行缓存的代理服务器或其它设备上实现了基于报文内容进行差异化设置缓存的缓存方法,相比传统基于HTTP协议的标准缓存机制的缓存方法,本申请的其中一个方面有如下优点:
1、由于标准的HTTP报文都包括内容类型字段,该字段不涉及HTTP协议的标准缓存机制,本申请所述的缓存方法仅是在遵循标准HTTP协议的基础之上进行的改进,因此本申请所述的缓存方法在遵循HTTP协议的标准缓存机制的基础上增加了由代理服务器主动设置本地缓存的方法,从而提升代理缓存的命中率,改善用户访问速度。另外,由于本申请所述的缓存方法是在遵循标准HTTP协议的基础之上进行的改进,因此本申请所述的缓存方法不仅适用于由代理服务器主动设置本地缓存的场景,还适用于HTTP协议的标准缓存机制对应的所有应用场景。
2、在本申请所述的缓存方法中,是根据内容类型字段的对应取值差异化设置其所属的HTTP报文专属的本地缓存参数,该本地缓存参数包括内容二次更新概率和本地缓存时间。由于内容类型字段的对应取值用于描述其所述的HTTP报文中报文内容的数据类别,能够反映该HTTP报文在源服务器被更新频率的高低,因此本申请所述的缓存方法所设置的本地缓存时间能够合理的控制回源校验的频度,进而确保已缓存内容及时更新,同时也控制了回源带宽成本。
附图说明
图1是本申请第一实施例提供的基于HTTP协议的缓存方法的流程示意图。
图2是第一实施例中差异化设置的步骤的具体实施方式的流程图。
图3是本申请第二实施例提供的基于HTTP协议的请求方法的流程图。
图4是本申请第三实施例提供的基于HTTP协议的响应方法的流程图。
图5是第三实施例中响应状态码识别处理的具体实施方式的流程图。
图6是第三实施例中差异化设置本地代理缓存时间的具体实施方式的流程图。
图7是本申请第四实施例提供的基于HTTP协议的缓存装置的示意图。
图8是本申请第五实施例提供的基于HTTP协议的请求装置的示意图。
图9是本申请第六实施例提供的基于HTTP协议的响应装置的示意图。
图10是本申请第七实施例提供的基于HTTP协议的网页访问系统的结构示意图。
具体实施方式
在下面的描述中阐述了很多具体细节以便于充分理解本申请。但是本申请能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本申请内涵的情况下做类似推广,因此本申请不受下面公开的具体实施的限制。
在本申请中,分别提供了一种基于HTTP协议的缓存方法、请求方法、响应方法,和相应的缓存装置、请求装置、响应装置,以及网页访问方法,在下面的实施例中逐一进行详细说明。
请参看图1,其为本申请第一实施例提供的基于HTTP协议的缓存方法的流程示意图。
所述缓存方法包括如下步骤:
步骤101:获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别。
一个标准的HTTP报文,通常由一个或多个头部和可选的消息体组成。HTTP头部通常包括通用头、请求头、响应头和实体头四个部分,消息体即为储存报文内容的字段。在本实施例中获取的HTTP报文至少包括实体头及实体信息,其中,实体头包括内容类型字段(Content-Type字段),实体信息储存有该HTTP报文的报文内容。内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别,进而指示客户端使用合适的方式来展现或处理内容。
步骤102:解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值。
在HTTP协议中,内容类型字段格式为:Content-Type:type/subtype,其中“type”的值可以分为7大类:
文本消息类型(text类型),用于标准化地表示的文本信息,文本信息可以是多种字符集和或者多种格式的;在给内容类型字段具体赋值时,以text表示具体的值;
用于连接消息体的多个部分构成一个消息的类型(multipart类型),用于连接消息体的多个部分构成一个消息,这些部分可以是不同类型的数据;在给内容类型字段具体赋值时,以multipart表示具体的值;
用于包装一个电子邮件消息的类型(message类型),用于包装一个电子邮件(E-mail)消息,在给内容类型字段具体赋值时,以message表示具体的值;
用于传输静态图片数据的类型(image类型),用于传输静态图片数据,在给内容类型字段具体赋值时,以image表示具体的值;
用于传输应用程序数据及二进制数据的类型(application类型),用于传输应用程序数据或者二进制数据,在给内容类型字段具体赋值时,以application表示具体的值;
用于传输音频及声音数据的类型(audio类型),用于传输音频或者音声数据,在给内容类型字段具体赋值时,以audio表示具体的值;
用于传输动态影像数据的类型(video类型),用于传输动态影像数据,可以是与音频编辑在一起的视频数据格式,在给内容类型字段具体赋值时,以video表示具体的值。
在本实施例中,通过解析内容类型字段的“type”的值获取HTTP报文中报文内容的数据类别。
步骤103:根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数。
上述本地缓存参数包括内容二次更新概率和本地缓存时间。
图2是第一实施例中差异化设置的步骤的具体实施方式的流程图。在本实施例中,差异化设置的步骤包括:
步骤201:根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低。
如步骤101所述,内容类型字段的“type”取值用于描述的所述HTTP报文中报文内容的数据类别,而不同数据类别的报文内容被源服务器更新的频率高低是不同的。通常,文本消息类型、用于包装一个电子邮件消息的类型和用于连接消息体的多个部分构成一个消息的类型对应的报文内容是发布文字或消息内容使用的类型,而文字和消息是最容易被源服务器更新的;用于传输静态图片数据的类型和用于传输应用程序数据及二进制数据的类型是发布图像和可执行程序使用的类型,图像和可执行程序被源服务器更新的可能性相对于文字和消息低很多;用于传输音频及声音数据的类型和用于传输动态影像数据的类型是发布音频和视频使用的类型,音频和视频内容被源服务器更新的可能性最低。因此,内容类型字段的“type”取值能反映所述HTTP报文的报文内容在原服务器被更新频率的高低。所谓差异化设置是指以此频率高低为依据差异化设置该HTTP报文对应的所述内容二次更新概率的取值范围,从而使上述二次更新概率能够反映所述HTTP报文在源服务器被更新频率的高低。本实施例差异化设置上述内容二次更新概率的具体步骤如下:
201-1)若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或表示所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间。
在本实施例中,具体设置为>50%且≤99%的区间。
201-2)若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间。
在本实施例中,具体设置为<50%且≥1%的区间。
201-3)若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型,或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
在本实施例中,具体是将所述内容二次更新概率的取值设置为50%。
步骤202:以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
在说明具体计算方法前,先对HTTP协议的标准缓存机制进行说明。
HTTP协议提供一套标准的缓存机制,该缓存机制通过对基于HTTP协议的报文的指定字段进行设置实现。标准HTTP协议中,涉及缓存的指定字段有:缓存控制字段(Cache-Control字段)、缓存编译控制字段(Pragma字段)和缓存过期控制字段(Expires字段)。其中,缓存控制字段是由源服务器设置,用于指定浏览器以及代理服务器是否可以缓存该内容,同时用于指定缓存时间的值;缓存控制字段也可以由客户端设置,用于指定客户端发起的请求不使用缓存内容,而是直接获取源服务器上最新的内容;缓存编译控制字段由客户端设置,用于指定客户端发起的请求不使用缓存内容,而是直接获取源服务器上最新的内容,其优先级低于缓存控制字段对应的相同设置;缓存过期控制字段由源服务器设置,用于指定缓存时间的值,其优先级低于缓存控制字段所设置的缓存时间。
结合上述说明可知,缓存控制字段、缓存编译控制字段和缓存过期控制字段都是由源服务器或客户端进行设置的,由代理服务器或其它缓存装置根据所获取的HTTP报文 的这些字段取值来进行相应的缓存处理,其中,由该些字段获取的缓存时间是进行缓存处理的关键参数。本申请所述的缓存方法,是在遵循HTTP协议标准缓存机制的基础上实现在代理服务器或其它缓存装置本地进行缓存设置的方法,关键之处就在于如何由代理服务器或其它缓存装置主动计算缓存时间参数,本实施例采用以下步骤进行计算:
202-1)获取所述HTTP报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值。
在本实施例中,包括获取缓存控制字段下是否可以缓存该内容、设置缓存时间这两个取值;获取缓存编译控制字段下是否可以缓存该内容的取值;获取缓存过期控制字段下的过期时间(HTTP-date)的取值。
202-2)判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间。
在本实施例中,基于HTTP协议的标准缓存机制的优先级规则对在上述步骤202-1)里获取的字段取值判断是否有不可缓存该内容的设置,继而判断缓存控制字段或者缓存过期控制字段的对应取值是否包含有效的缓存时间,若包含,则获取该有效的缓存时间,其中缓存控制字段指定的缓存时间优先级高于缓存过期控制字段指定的缓存时间。
202-3)若上述步骤202-2)判断结果为包含,则所述本地缓存时间的计算方法是:
force_ttl=(1–A)cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间。
上述缓存过期控制字段的对应取值所包含的所述有效的缓存时间是绝对时间格式,在计算时,需将该缓存时间转换为相对时间再进行计算。
202-4)若上述步骤202-2)判断结果为不包含,则所述本地缓存时间的计算方法是:
force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地缓存时间预先设置的所述最大值。在本实施例中,该最大值设置为互联网应用通常建议的60秒。
互联网应用通常对缓存时间有一个建议的最小值,由于上述计算步骤所使用的参数A的取值范围是1%至99%,使得通过上述两个计算本地缓存时间,即force_ttl的公式得到的force_ttl可能会小于该建议的最小值,因此还需预先设置一个本地缓存时间的最小值min_default_cache_time来进行限制。在本实施例中,该最小值配置为互联网应用通常建议的1秒,当从上述两个计算force_ttl的公式得到的本地缓存时间小于该最小值时, 则取该最小值为本地缓存时间。同样,若从上述两个计算force_ttl的公式得到的本地缓存时间大于本实施例所配置的上述最大值时,则取该最大值为本地缓存时间。
通过上述计算步骤,在源服务器没有设置缓存时间的情况下,代理服务器或缓存装置也可以主动设置本地缓存时间,从而不需要频繁的向源服务器获取请求内容,同时又保证缓存装置以一个合理的频度更新缓存内容,即能够合理的控制回源校验的频度。
步骤104:基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
步骤104是缓存处理的具体步骤,包括以下两步:
104-1)基于HTTP协议标准缓存机制的缓存优先级规则,设置所述本地缓存参数的优先级高于所述HTTP协议标准缓存机制的可缓存或使用缓存设置参数,且低于所述HTTP协议标准缓存机制的不可缓存或不使用缓存设置参数。
如步骤103中对HTTP协议标准缓存机制的说明可知,有多个字段涉及缓存设置,该标准缓存机制还包括相应的缓存优先级规则。对于本申请所述的缓存方法得到的本地缓存时间,将其优先级设置为高于所述HTTP协议标准缓存机制的可缓存或使用缓存设置参数,且低于所述HTTP协议标准缓存机制的不可缓存或不使用缓存设置参数,即本地缓存时间优先级高于HTTP报文头部里缓存控制字段或者缓存过期控制字段所设置的缓存时间,其它操作则遵循HTTP协议标准缓存机制。
104-2)根据所述本地缓存参数设置缓存指令,并进行相应的缓存操作。
以本申请所述的缓存方法在上述步骤104-1)规定的缓存优先级规则下,遵循HTTP协议标准缓存机制进行相应的缓存指令设置和相应的缓存操作。
在上述的实施例中,提供了一种基于HTTP协议的缓存方法。该缓存方法在实际应用中,涉及到与客户端方向的交互,以及与源服务器的交互,相应的本申请还提供一种基于HTTP协议的请求方法。
请参看图3,其为本申请第二实施例提供的基于HTTP协议的请求方法的流程图。本实施例假定用于在客户端和源服务器之间部署代理服务器,并在代理服务器上设置缓存服务的场景,但不排除将本申请所述的请求方法应用于HTTP协议的标准缓存机制所对应的其他场景。
所述请求方法是指代理服务器对来自客户端的请求进行处理的方法,包括如下步骤:
步骤301:代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL。
代理服务器按控制方分类,可分为正向代理和反向代理。其中,正向代理方式源服 务器不感知客户端的存在,但客户端可强制绕过代理服务器的缓存内容,从源服务器获取其请求的内容;反向代理方式客户端不感知源服务器的存在,而是由代理服务器作为源服务器的客户端,并由源服务器控制代理服务器的缓存代理服务。相应的,若代理服务器以正向代理方式接收到的客户端发来的HTTP请求报文,该HTTP请求报文携带的URL(统一资源定位符,Uniform Resource Locator)是以源服务器为主机地址的源服务器上相应请求内容的URL;若代理服务器以反向代理方式接收到的客户端发来的HTTP请求报文,该HTTP请求报文携带的URL是以代理服务器为主机地址的代理服务器上缓存的相应内容的URL。
步骤302:所述代理服务器根据所述URL判断本地缓存是否命中。
本步骤的具体实施,应基于HTTP协议标准缓存机制,在判断本地缓存是否命中之前,先行判断HTTP请求报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段的取值是否包含不使用缓存的设置,若包含则应基于HTTP协议的标准缓存机制进行相应处理,若不包含则执行上述根据所述URL判断本地缓存是否命中的步骤。这样使得代理服务器在本地进行缓存设置的优先级高于HTTP协议标准缓存机制的使用缓存设置参数,且低于HTTP协议标准缓存机制的不使用缓存设置参数。例如,请求报文头部的缓存控制字段和缓存编译控制字段均不包括不缓存(no-cache)或不使用缓存(no-store)设置,则执行本步骤所述的根据所述URL判断本地缓存是否命中。
步骤303:若步骤302判断结果为未命中,则基于HTTP协议的标准缓存机制进行相应处理。
基于HTTP协议的标准缓存机制进行相应处理具体是指以HTTP请求报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段,及HTTP协议标准缓存机制涉及的其它字段或涉及的相关规则进行相应的处理。例如,对于正向代理而言,进一步判断HTTP请求报文的缓存控制字段、缓存编译控制字段或缓存过期控制字段的相应取值是否包含不使用缓存配置,进而进行相应的处理。
步骤304:若步骤302判断结果为命中,则基于预先设置的本地缓存参数进行相应处理,具体包括以下步骤:
304-1)获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期。
上述预先设置的本地代理缓存参数包括所述代理服务器上已缓存的HTTP报文的响应头中预设的本地代理缓存时间,该本地代理缓存时间通过以下步骤获取:
1)根据所述已缓存的HTTP报文的内容类型字段的对应取值差异化设置所述HTTP报文专属的内容二次更新概率,所述内容二次更新概率用于反映其所属的HTTP报文在源服务器被更新频率的高低。
如本申请的第一实施例所述,内容类型字段的“type”取值用于描述的所述HTTP报文中报文内容的数据类别,而不同数据类别的报文内容被源服务器更新的频率高低是不同的,所谓差异化设置是指以此频率高低为依据差异化设置该HTTP报文对应的所述内容二次更新概率的取值范围,从而使上述二次更新概率能够反映所述HTTP报文在源服务器被更新频率的高低。
2)以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
3)将所述本地代理缓存时间写入所述HTTP报文的响应头中的指定字段中。
4)将所述HTTP报文被缓存的时间作为当前缓存时间写入所述HTTP报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间。
上述基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期的步骤具体执行如下:
1)根据已命中的所述缓存内容对应的HTTP报文的响应头,提取所述本地代理缓存时间,以及提取所述缓存内容被缓存时的所述当前缓存时间。
解析已命中的所述缓存内容,获取其对应的HTTP报文的响应头的指定字段取值,从而提取上述以所述内容二次更新概率为参数计算得到的本地代理缓存时间,以及提取该缓存内容被缓存时所记录的当前缓存时间。
2)将所述本地代理缓存时间的格式由相对时间转换为绝对时间:force_ttl=force_ttl+proxy-save-time,其中,所述force_ttl为所述本地代理缓存时间,所述proxy-save-time为所述当前缓存时间。
3)判断格式转换后的所述本地代理缓存时间是否小于所述HTTP请求报文到来的时间。
4)若上述判断结果为小于,则过期。
5)若上述判断结果为不小于,则未过期。
另外,为兼容HTTP协议的标准缓存机制,在执行步骤304-1)之前,执行判断已命中的所述缓存内容对应的报文响应头是否包含内容类型字段,若没有包含则基于HTTP协议的标准缓存机制进行相应处理,并结束请求处理流程;若包含则开始执行步骤 304-1)。
304-2)若步骤304-1)判断结果为过期,则向源服务器发送过期回源校验指令。
304-3)若步骤304-1)判断结果为未过期,则将所述缓存内容返回给所述客户端。
在上述的实施例中,提供了一种基于HTTP协议的请求方法,在该请求方法中,客户端不感知代理服务器上对缓存设置及处理的具体细节,返回给客户端的报文不包括响应头中的本地代理缓存参数。与该请求方法相对应,本申请还提供一种基于HTTP协议的响应方法。
请参看图4,其为本申请第三实施例提供的基于HTTP协议的响应方法的流程图。本实施例假定用于在客户端和源服务器之间部署代理服务器,在代理服务器上设置缓存服务的场景,但不排除将本申请所述的响应方法应用于HTTP协议的标准缓存机制对应的其他场景。
所述响应方法是指代理服务器对来自源服务器的响应报文进行处理的方法,包括如下步骤:
步骤401:代理服务器接收来自源服务器的HTTP响应报文。
如本申请的请求方法可知,代理服务器在接收客户端HTTP请求报文后,经过处理,会以两种形式继续向源站发送消息,一种是缓存未命中进一步向源站请求获取内容,另一种是缓存命中但过期需进行回源校验。与此相对应,源服务器返回的也有不同形式的消息,具体是哪种消息由接收的HTTP响应报文所携带的响应状态码来区分。图5是第三实施例中响应状态码识别处理的具体实施方式的流程图,具体步骤如下:
步骤501:获取所述响应报文携带的响应状态码。
步骤502:判断所述响应状态码的类别。
步骤503:若所述响应状态码是304,则说明源服务器判断内容没有改变,可以继续使用代理服务器中的缓存内容,具体包括以下步骤:执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令;获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间;执行更新缓存过期时间的缓存指令;结束本次响应处理。
步骤504:若所述响应状态码是200,则说明该内容是第一次被代理服务器获取,或说明源服务器判断内容已更新,需要代理服务器重新缓存该内容。这种情况需要继续执行下述缓存该内容的步骤。
步骤402:解析所述响应报文,判断所述响应报文是否包含内容类型字段。
标准HTTP协议中,涉及缓存的指定字段有:缓存控制字段(Cache-Control字段)、 缓存编译控制字段(Pragma字段)和缓存过期控制字段(Expires字段)。
在对上述响应状态码进行识别处理步骤后,且在上述判断所述响应报文是否包含内容类型字段步骤前,应当先行判断HTTP响应报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段的取值是否包含不缓存的设置,若包含则应基于HTTP协议的标准缓存机制进行相应处理,若不包含则执行上述判断所述响应报文是否包含内容类型字段的步骤。这样使得代理服务器在本地进行缓存设置的优先级高于HTTP协议标准缓存机制的可缓存设置参数,且低于HTTP协议标准缓存机制的不可缓存设置参数。例如,响应报文头部的缓存控制字段或缓存编译控制字段均不包括不缓存(no-cache)或不使用缓存(no-store)设置,则执行本步骤所述的判断所述响应报文是否包含内容类型字段。
步骤403:若步骤402判断结果为不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理。
所述按HTTP协议的标准缓存机制进行相应的缓存处理,具体实施方式如下:
403-1)获取所述响应报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值。
403-2)判断所述缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值是否包括不可缓存设置或没有设置有效的缓存时间;所述有效的缓存时间为HTTP协议标准缓存机制的缓存时间参数。
403-3)若判断结果为是,则将所述响应报文的内容返回给所述客户端,结束本次响应处理。
403-4)若判断结果为否,则缓存所述响应报文,并执行将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令,结束本次响应处理。
步骤404:若步骤402判断结果为包含,则执行下述缓存设置的步骤;
步骤405:获取所述内容类型字段的对应取值。
步骤406:根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数。
所述本地代理缓存参数包括内容二次更新概率和本地代理缓存时间,
图6是第三实施例中差异化设置本地代理缓存时间的具体实施方式的流程图。
差异化设置本地代理缓存时间的具体步骤如下:
步骤601:根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应 报文在源服务器被更新频率的高低。
如本申请的第一实施例所述,内容类型字段的“type”取值用于描述的所述HTTP报文中报文内容的数据类别,而不同数据类别的报文内容被源服务器更新的频率高低是不同的,“type”取值的具体含义参见第一实施例的描述。所谓差异化设置是指以此频率高低为依据差异化设置该HTTP报文对应的所述内容二次更新概率的取值范围,从而使上述二次更新概率能够反映所述HTTP报文在源服务器被更新频率的高低。具体步骤执行如下:
601-1)若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间。
在本实施例中,具体设置为>50%且≤99%的区间。
601-2)若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间。
在本实施例中,具体设置为<50%且≥1%的区间。
601-3)若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型,或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
在本实施例中,具体是将所述内容二次更新概率的取值设置为50%。
步骤602:以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。以下是本地代理缓存时间的 具体计算步骤:
602-1)获取所述响应报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值。
在本实施例中,包括获取缓存控制字段下是否可以缓存该内容、设置缓存时间这两个取值;获取缓存编译控制字段下是否可以缓存该内容的取值;获取缓存过期控制字段下的过期时间(HTTP-date)取值。
602-2)判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间。
在本实施例中,基于HTTP协议的标准缓存机制的优先级规则对在上述步骤602-1)里获取的字段取值判断是否有不可缓存该内容的设置,继而判断缓存控制字段或者缓存过期控制字段的对应取值是否包含有效的缓存时间,若包含,则获取该有效的缓存时间,其中缓存控制字段指定的缓存时间优先级高于缓存过期控制字段指定的缓存时间。
602-3)若上述步骤602-2)判断结果为包含,则所述本地代理缓存时间的计算方法是:
force_ttl=(1–A)cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间。
上述缓存过期控制字段的对应取值所包含的所述有效的缓存时间是绝对时间格式,在计算时,需将该缓存时间转换为相对时间再进行计算。
602-4)若上述步骤602-2)判断结果为不包含,则所述本地代理缓存时间的计算方法是:
force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地代理缓存时间预先设置的所述最大值。在本实施例中,该最大值配置为互联网应用通常建议的60秒。
互联网应用通常对缓存时间有一个建议的最小值,由于上述计算步骤所使用的参数A的取值范围是1%至99%,因此通过上述两个计算本地代理缓存时间,即force_ttl的公式得到的force_ttl可能会小于该建议的最小值,因此还需预先设置一个本地代理缓存时间的最小值min_default_cache_time。在本实施例中,该最小值配置为互联网应用通常建议的1秒,当从上述两个计算force_ttl的公式得到的force_ttl小于该最小值时,则取该最小值为本地代理缓存时间。同样,若从上述两个计算force_ttl的公式得到的本地代理 缓存时间大于本实施例所设置的上述最大值时,则取该最大值为本地代理缓存时间。
通过上述计算步骤,在源服务器没有设置缓存时间的情况下,代理服务器或缓存装置也可以主动设置本地代理缓存时间,从而不需要频繁的向源服务器获取请求内容,同时又保证代理服务器或缓存装置以一个合理的频度更新缓存内容,即能够合理的控制回源校验的频度。
步骤407:基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。具体由以下步骤实现:
407-1)将所述本地代理缓存时间写入所述响应报文的响应头中的指定字段中。
407-2)将所述响应报文被缓存的时间作为当前缓存时间写入所述响应报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间。
407-3)缓存所述响应报文。
407-4)执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令,结束本次响应处理。
如上所述响应方法的具体实施中,通过步骤402对是否包含内容类型字段的判断,既保证了上述本地代理缓存时间参数的优先级高于HTTP协议标准缓存机制设置的相应参数,又兼容了HTTP协议的标准缓存机制的固有缓存处理。
在上述步骤503中,获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间,以及执行更新缓存过期时间的缓存指令的步骤,具体包括以下步骤:
503-1)判断所述响应报文是否包含内容类型字段。
503-2)若包含,则执行所述根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数的步骤,进而获取所述本地代理缓存时间参数。
本步骤差异化设置所述本地代理缓存参数的方法同步骤601至步骤602所述的步骤,详细步骤请参考步骤601至步骤602,此处不再赘述。
503-3)若不包含,则基于HTTP协议的标准缓存机制从所述响应报文的缓存控制、缓存编译控制或缓存过期控制字段中获取所述HTTP协议标准缓存机制的缓存时间参数。
503-4)相应的,所述执行更新缓存过期时间的缓存指令,是指更新所述响应报文对应的缓存报文的响应头中的所述本地代理缓存时间、或者更新所述响应报文对应的缓存报文的储存有所述HTTP协议标准缓存机制的缓存时间参数的相应字段,以及将接收所述响应报文的当前时间作为所述当前缓存时间更新到存储所述当前缓存时间的指定字段 中。
以上提供了一种基于HTTP协议的缓存方法、请求方法和响应方法,相应的,本申请还提供一种基于HTTP协议的缓存装置、请求装置和响应装置,下面进行一一描述。由于装置实施例基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。下述描述的装置实施例仅仅是示意性的。
请参看图7,其为本申请第四实施例提供的基于HTTP协议的缓存装置的示意图。
本实施例的一种基于HTTP协议的缓存装置,包括:HTTP报文获取单元7-1、HTTP报文解析单元7-2、本地缓存参数设置单元7-3,以及缓存处理单元7-4。
所述HTTP报文获取单元7-1,用于获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别。
所述HTTP报文解析单元7-2,用于解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值。
所述本地缓存参数设置单元7-3,用于根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数。
所述本地缓存参数设置单元7-3包括内容二次更新概率设置子单元7-3-1和本地缓存时间设置子单元7-3-2。
所述内容二次更新概率设置子单元7-3-1,用于根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低。
所述本地缓存时间设置子单元7-3-2,用于以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
所述缓存处理单元7-4,用于基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
请参看图8,其为本申请第五实施例提供的基于HTTP协议的请求装置的示意图。
本实施例的一种基于HTTP协议的请求装置,包括:HTTP请求报文接收单元8-1、缓存命中判断单元8-2、缓存处理单元8-3。
所述HTTP请求报文接收单元8-1,用于代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL。
所述缓存命中判断单元8-2,用于所述代理服务器根据所述URL判断本地缓存是否命中。
所述缓存处理单元8-3,用于在未命中时,基于HTTP协议的标准缓存机制进行相应处理;在命中时,获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,若过期,则向源服务器发送过期回源校验指令,若未过期,则将所述缓存内容返回给所述客户端。
请参看图9,其为本申请第六实施例提供的基于HTTP协议的响应装置的示意图。
本实施例的一种基于HTTP协议的响应装置,包括:响应报文接收单元9-1、响应报文解析单元9-2、HTTP协议的标准缓存机制处理单元9-3、本地缓存规则处理单元9-4。
所述响应报文接收单元9-1,用于代理服务器接收来自源服务器的HTTP响应报文。
所述响应报文解析单元9-2,用于解析所述响应报文,判断所述响应报文是否包含内容类型字段。
所述HTTP协议的标准缓存机制处理单元9-3,用于若所述响应报文解析单元判断所述响应报文不包含内容类型字段,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理。
所述本地缓存规则处理单元9-4,用于若所述响应报文解析单元判断所述响应报文包含内容类型字段,则获取所述内容类型字段的对应取值;根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
所述本地缓存规则处理单元9-4,包括:内容类型字段解析子单元9-4-1、本地代理缓存参数设置子单元9-4-2、缓存及返回指令处理子单元9-4-3。
所述内容类型字段解析子单元9-4-1,用于获取所述内容类型字段的对应取值。
所述本地代理缓存参数设置子单元9-4-2,用于根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数。
所述本地代理缓存参数设置子单元9-4-2,包括:内容二次更新概率设置子单元9-4-2-1和本地代理缓存时间设置子单元9-4-2-2。
所述内容二次更新概率设置子单元9-4-2-1,用于根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应报文在源服务器被更新频率的高低。
所述本地代理缓存时间设置子单元9-4-2-2,用于以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
所述缓存及返回指令处理子单元9-4-3,用于基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
请参看图10,图10是本申请第七实施例提供的基于HTTP协议的网页访问系统的结构示意图。
在本实施例中,所述基于HTTP协议的网页访问系统包括:客户端1001、代理服务器1002、源服务器1003。客户端1001向代理服务器1002发起请求报文,该报文携带有一个URL,以期获取与该URL对应的内容;代理服务器1002接收到该请求报文后,对请求报文进行处理,如果本地已缓存的内容中包含与该请求相应的内容且缓存内容未过期,则将本地缓存的与该请求相应的内容返回给客户端,如果本地已缓存的内容中不包含与该请求相应的内容或缓存内容过期,则向源服务器1003继续发起请求;源服务器1003接收到代理服务器1002发来的请求后,返回给代理服务器1002一个相应的响应报文;代理服务器1002接收到该响应报文后,对响应报文进行处理,并将与客户端请求相应的内容返回给客户端。
其中,在本实施例中,代理服务器1002进一步包括本申请中所述的请求装置和响应装置,由请求装置完成上述对请求报文的处理,由响应装置完成上述对响应报文的处理。
上述分别提供了一种基于HTTP协议的缓存方法、请求方法、响应方法,及缓存装置、请求装置、响应装置、的实施例,响应的,本申请还提供一种电子设备,该电子设备包括:
显示器;
处理器;以及
存储器,所述存储器被配置成存储基于HTTP协议的缓存装置、基于HTTP协议的请求装置、基于HTTP协议的响应装置中的至少一种装置,
所述基于HTTP协议的缓存装置被所述处理器执行时,执行如下步骤:
获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理;
所述基于HTTP协议的请求装置,被所述处理器执行时,执行如下步骤:
代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
所述代理服务器根据所述URL判断本地缓存是否命中,
若未命中,则基于HTTP协议的标准缓存机制进行相应处理;
若命中,则获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,
若过期,则向源服务器发送过期回源校验指令,
若未过期,则将所述缓存内容返回给所述客户端;
所述基于HTTP协议的响应装置,被所述处理器执行时,执行如下步骤:
代理服务器接收来自源服务器的HTTP响应报文;
解析所述响应报文,判断所述响应报文是否包含内容类型字段;
若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
若包含,则进入以下步骤;
获取所述内容类型字段的对应取值;
根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
本申请虽然以较佳实施例公开如上,但其并不是用来限定本申请,任何本领域技术人员在不脱离本申请的精神和范围内,都可以做出可能的变动和修改,因此本申请的保护范围应当以本申请权利要求所界定的范围为准。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
1、计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存 储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
2、本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。

Claims (28)

  1. 一种基于HTTP协议的缓存方法,其特征在于,包括:
    获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
    解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
    根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
    基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
  2. 根据权利要求1所述的缓存方法,其特征在于,在所述根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数的步骤中,所述本地缓存参数包括内容二次更新概率和本地缓存时间,所述差异化设置的步骤包括:
    根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低;
    以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
  3. 根据权利要求2所述的缓存方法,其特征在于,所述根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,是指所述内容类型字段的对应取值所描述的所述HTTP报文中报文内容的数据类别能反映所述HTTP报文在原服务器被更新频率的高低,以此频率高低为依据差异化设置该HTTP报文对应的所述内容二次更新概率的取值范围,具体包括:
    若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或表示所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间;
    若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间;
    若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型, 或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:
    所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;
    所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
  4. 根据权利要求3所述的缓存方法,其特征在于,包括:
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间,具体是设置为>50%且≤99%的区间;
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间,具体是设置为<50%且≥1%的区间;
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间,具体是将所述内容二次更新概率的取值设置为50%。
  5. 根据权利要求2所述的缓存方法,其特征在于,执行所述以所述内容二次更新概率为参数,计算所述本地缓存时间的步骤前,执行以下步骤:
    为所述本地缓存时间设置最大值,所述最大值的具体数值为60秒;
    为所述本地缓存时间设置最小值,所述最小值的具体数值为1秒。
  6. 根据权利要求5所述的缓存方法,其特征在于,所述以所述内容二次更新概率为参数,计算所述本地缓存时间,包括:
    获取所述HTTP报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值;
    判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间;
    若包含,则所述本地缓存时间的计算方法是:
    force_ttl=(1–A)cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者所述缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间;
    若不包含,则所述本地缓存时间的计算方法是:
    force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地缓存时间预先设置的所述最大值。
  7. 根据权利要求1所述的缓存方法,其特征在于,所述基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理,包括:
    基于HTTP协议标准缓存机制的缓存优先级规则,设置所述本地缓存参数的优先级高于所述HTTP协议标准缓存机制的可缓存或使用缓存设置参数,且低于所述HTTP协议标准缓存机制的不可缓存或不使用缓存设置参数;
    根据所述本地缓存参数设置缓存指令,并进行相应的缓存操作。
  8. 一种基于HTTP协议的请求方法,其特征在于,包括:
    代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
    所述代理服务器根据所述URL判断本地缓存是否命中,
    若未命中,则基于HTTP协议的标准缓存机制进行相应处理;
    若命中,则获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,
    若过期,则向源服务器发送过期回源校验指令,
    若未过期,则将所述缓存内容返回给所述客户端。
  9. 根据权利要求8所述的请求方法,其特征在于,所述预先设置的本地代理缓存参数,包括所述代理服务器上已缓存的HTTP报文的响应头中预设的本地代理缓存时间,所述本地代理缓存时间通过以下步骤获取:
    根据所述已缓存的HTTP报文的内容类型字段的对应取值差异化设置所述HTTP报文专属的内容二次更新概率,所述内容二次更新概率用于反映其所属的HTTP报文在源服务器被更新频率的高低;
    以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致;
    将所述本地代理缓存时间写入所述HTTP报文的响应头中的指定字段中;
    将所述HTTP报文被缓存的时间作为当前缓存时间写入所述HTTP报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间。
  10. 根据权利要求9所述的请求方法,其特征在于,所述基于预先设置的本地代理 缓存参数判断已命中的所述缓存内容是否过期,包括:
    根据已命中的所述缓存内容对应的HTTP报文的响应头,提取所述本地代理缓存时间,以及提取所述缓存内容被缓存时的所述当前缓存时间;
    将所述本地代理缓存时间的格式由相对时间转换为绝对时间:force_ttl=force_ttl+proxy-save-time,其中,所述force_ttl为所述本地代理缓存时间,所述proxy-save-time为所述当前缓存时间;
    判断格式转换后的所述本地代理缓存时间是否小于所述HTTP请求报文到来的时间;
    若小于,则过期;
    若不小于,则未过期。
  11. 一种基于HTTP协议的响应方法,其特征在于,包括:
    代理服务器接收来自源服务器的HTTP响应报文;
    解析所述响应报文,判断所述响应报文是否包含内容类型字段;
    若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
    若包含,则进入以下步骤;
    获取所述内容类型字段的对应取值;
    根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
    基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
  12. 根据权利要求11所述的响应方法,其特征在于,所述若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,包括:
    获取所述响应报文的缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值;
    判断所述缓存控制字段、缓存编译控制字段和缓存过期控制字段的对应取值是否包括不可缓存设置或没有设置有效的缓存时间;所述有效的缓存时间为HTTP协议标准缓存机制的缓存时间参数;
    若判断结果为是,则将所述响应报文的内容返回给所述客户端,结束本次响应处理;
    若判断结果为否,则缓存所述响应报文,并执行将所述响应报文对应的本地缓存报 文的内容返回给所述客户端的返回指令,结束本次响应处理。
  13. 根据权利要求11所述的响应方法,其特征在于,在所述根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数的步骤中,所述本地代理缓存参数包括内容二次更新概率和本地代理缓存时间,所述差异化设置的步骤包括:
    根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应报文在源服务器被更新频率的高低;
    以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
  14. 根据权利要求13所述的响应方法,其特征在于,所述根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,是指所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别能反映所述响应报文在原服务器被更新频率的高低,以此频率高低为依据差异化设置该响应报文对应的所述内容二次更新概率的取值范围,具体包括:
    若所述内容类型字段的对应取值表示所述报文内容为文本消息的类型、或表示所述报文内容用于包装一个电子邮件消息的类型、或所述报文内容用于连接消息体的多个部分构成一个消息的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较高,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间;
    若所述内容类型字段的对应取值表示所述报文内容用于传输音频及声音数据的类型时,或表示所述报文内容用于传输动态影像数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率较低,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间;
    若所述内容类型字段的对应取值表示所述报文内容用于传输静态图片数据的类型,或表示所述报文内容用于传输应用程序数据及二进制数据的类型时,该些取值所标识的相应种类的报文在原服务器被更新的频率中等,则该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间:
    所述取值范围的上限值设置为低于所述内容类型字段的对应取值表示文本消息类型、或表示用于包装一个电子邮件消息的类型、或表示用于连接消息体的多个部分构成一个消息的类型时所设置的所述内容二次更新概率的取值范围的最低值;
    所述取值范围的下限值设置为高于所述内容类型字段的对应取值表示用于传输音频及声音数据的类型时,或表示用于传输动态影像数据的类型时所设置的所述内容二次更新概率的取值范围的最高值。
  15. 根据权利要求14所述的响应方法,其特征在于,包括:
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近100%的某个区间,具体是设置为>50%且≤99%的区间;
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为靠近0%的某个区间,具体是设置为<50%且≥1%的区间;
    所述该些种类的报文对应的所述内容二次更新概率的取值范围分别设置为介于如下边界之间的某一区间,具体是将所述内容二次更新概率的取值设置为50%。
  16. 根据权利要求13所述的响应方法,其特征在于,执行所述以所述内容二次更新概率为参数,计算所述本地代理缓存时间的步骤前,执行以下步骤:
    为所述本地代理缓存时间设置最大值,所述最大值具体数值为60秒;
    为所述本地代理缓存时间设置最小值,所述最小值具体数值为1秒。
  17. 根据权利要求16所述的响应方法,其特征在于,所述以所述内容二次更新概率为参数,计算所述本地代理缓存时间,包括:
    获取所述响应报文所携带的用于制定缓存机制的缓存控制字段或者缓存编译控制字段或者缓存过期控制字段的对应取值;
    判断所述缓存控制字段或者所述缓存过期控制字段的对应取值是否包含有效的缓存时间;
    若包含,则所述本地代理缓存时间的计算方法是:
    force_ttl=(1–A)cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,cache_time是由所述缓存控制字段或者所述缓存过期控制字段的对应取值所包含的所述有效的缓存时间所对应的相对时间;
    若不包含,则所述本地代理缓存时间的计算方法是:
    force_ttl=(1–A)max_default_cache_time,其中,force_ttl是所述本地代理缓存时间,A是所述内容二次更新概率,max_default_cache_time是为所述本地代理缓存时间预先设置的所述最大值。
  18. 根据权利要求13所述的响应方法,其特征在于,所述基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令,包括:
    将所述本地代理缓存时间写入所述响应报文的响应头中的指定字段中;
    将所述响应报文被缓存的时间作为当前缓存时间写入所述响应报文的响应头中的指定字段中,所述当前缓存时间格式为绝对时间;
    缓存所述响应报文;
    执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令,结束本次响应处理。
  19. 根据权利要求12或权利要求18所述的响应方法,其特征在于,在执行所述判断所述响应报文是否包含内容类型字段的步骤前,执行以下步骤:
    获取所述响应报文携带的响应状态码;
    判断所述响应状态码的类别,
    若所述响应状态码是304,则执行以下步骤:
    执行所述将所述响应报文对应的本地缓存报文的内容返回给所述客户端的返回指令;获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间;执行更新缓存过期时间的缓存指令;结束本次响应处理;
    若所述响应状态码是200,则继续执行所述判断所述响应报文是否包含内容类型字段的步骤。
  20. 根据权利要求书19所述的响应方法,其特征在于,所述获取所述代理服务器接收的当前响应报文对应的新的缓存过期时间,包括:
    判断所述响应报文是否包含内容类型字段;
    若包含,则执行所述根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数的步骤,进而获取所述本地代理缓存时间参数;
    若不包含,则基于HTTP协议的标准缓存机制从所述响应报文的缓存控制字段、缓存编译控制字段或缓存过期控制字段中获取所述HTTP协议标准缓存机制的缓存时间参数;
    相应的,所述执行更新缓存过期时间的缓存指令,是指更新所述响应报文对应的缓存报文的响应头中的所述本地代理缓存时间、或者更新所述响应报文对应的缓存报文的储存有所述HTTP协议标准缓存机制的缓存时间参数的相应字段,以及将接收所述响应报文的当前时间作为所述当前缓存时间更新到存储所述当前缓存时间的指定字段中。
  21. 一种基于HTTP协议的缓存装置,其特征在于,包括:
    HTTP报文获取单元,用于获取HTTP报文,所述HTTP报文携带有内容类型字段; 所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
    HTTP报文解析单元,用于解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
    本地缓存参数设置单元,用于根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
    缓存处理单元,用于基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理。
  22. 根据权利要求21所述的缓存装置,其特征在于,所述本地缓存参数设置单元包括:
    内容二次更新概率设置子单元,用于根据所述内容类型字段的对应取值差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述HTTP报文在源服务器被更新频率的高低;
    本地缓存时间设置子单元,用于以所述内容二次更新概率为参数,计算所述本地缓存时间,使所述本地缓存时间的长短与所述被更新频率的高低相一致。
  23. 一种基于HTTP协议的请求装置,其特征在于,包括:
    HTTP请求报文接收单元,用于代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
    缓存命中判断单元,用于所述代理服务器根据所述URL判断本地缓存是否命中;
    缓存处理单元,用于在未命中时,基于HTTP协议的标准缓存机制进行相应处理;在命中时,获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,若过期,则向源服务器发送过期回源校验指令,若未过期,则将所述缓存内容返回给所述客户端。
  24. 一种基于HTTP协议的响应装置,其特征在于,包括:
    响应报文接收单元,用于代理服务器接收来自源服务器的HTTP响应报文;
    响应报文解析单元,用于解析所述响应报文,判断所述响应报文是否包含内容类型字段;
    HTTP协议的标准缓存机制处理单元,用于若所述响应报文解析单元判断所述响应报文不包含内容类型字段,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
    本地缓存规则处理单元,用于若所述响应报文解析单元判断所述响应报文包含内容类型字段,则获取所述内容类型字段的对应取值;根据所述内容类型字段的对应取值差 异化设置所述响应报文专属的本地代理缓存参数;基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
  25. 根据权利要求24所述的响应装置,其特征在于,所述本地缓存规则处理单元包括:
    内容类型字段解析子单元,用于获取所述内容类型字段的对应取值;
    本地代理缓存参数设置子单元,用于根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
    缓存及返回指令处理子单元,用于基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
  26. 根据权利要求25所述的响应装置,其特征在于,所述本地代理缓存参数设置子单元包括:
    内容二次更新概率设置子单元,用于根据所述内容类型字段的对应取值所描述的所述响应报文中报文内容的数据类别差异化设置所述内容二次更新概率,所述内容二次更新概率用于反映所述响应报文在源服务器被更新频率的高低;
    本地代理缓存时间设置子单元,用于以所述内容二次更新概率为参数,计算所述本地代理缓存时间,使所述本地代理缓存时间的长短与所述被更新频率的高低相一致。
  27. 一种基于HTTP协议的网页访问系统,其特征在于,包括权利要求23所述的请求装置和权利要求24至26任一所述的响应装置。
  28. 一种电子设备,其特征在于,包括:
    显示器;
    处理器;以及
    存储器,所述存储器被配置成存储基于HTTP协议的缓存装置、基于HTTP协议的请求装置、基于HTTP协议的响应装置中的至少一种装置,
    所述基于HTTP协议的缓存装置被所述处理器执行时,执行如下步骤:
    获取HTTP报文,所述HTTP报文携带有内容类型字段;所述内容类型字段的对应取值用于描述所述HTTP报文中报文内容的数据类别;
    解析所述HTTP报文,获取该报文中所述内容类型字段的对应取值;
    根据所述内容类型字段的对应取值差异化设置所述HTTP报文专属的本地缓存参数;
    基于所述本地缓存参数对所述HTTP报文进行相应的缓存处理;
    所述基于HTTP协议的请求装置,被所述处理器执行时,执行如下步骤:
    代理服务器接收客户端发来的HTTP请求报文,所述HTTP请求报文携带URL;
    所述代理服务器根据所述URL判断本地缓存是否命中,
    若未命中,则基于HTTP协议的标准缓存机制进行相应处理;
    若命中,则获取已命中的缓存内容,并基于预先设置的本地代理缓存参数判断已命中的所述缓存内容是否过期,
    若过期,则向源服务器发送过期回源校验指令,
    若未过期,则将所述缓存内容返回给所述客户端;
    所述基于HTTP协议的响应装置,被所述处理器执行时,执行如下步骤:
    代理服务器接收来自源服务器的HTTP响应报文;
    解析所述响应报文,判断所述响应报文是否包含内容类型字段;
    若不包含,则按HTTP协议的标准缓存机制进行相应的缓存处理,并结束本次响应处理;
    若包含,则进入以下步骤;
    获取所述内容类型字段的对应取值;
    根据所述内容类型字段的对应取值差异化设置所述响应报文专属的本地代理缓存参数;
    基于所述本地代理缓存参数对所述响应报文进行相应的缓存处理,并执行相应的返回指令。
PCT/CN2016/097998 2015-09-14 2016-09-05 基于http协议的缓存、请求、响应方法及相应装置 WO2017045538A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510583636.8 2015-09-14
CN201510583636.8A CN106534243B (zh) 2015-09-14 2015-09-14 基于http协议的缓存、请求、响应方法及相应装置

Publications (1)

Publication Number Publication Date
WO2017045538A1 true WO2017045538A1 (zh) 2017-03-23

Family

ID=58288596

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/097998 WO2017045538A1 (zh) 2015-09-14 2016-09-05 基于http协议的缓存、请求、响应方法及相应装置

Country Status (2)

Country Link
CN (1) CN106534243B (zh)
WO (1) WO2017045538A1 (zh)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110263010A (zh) * 2019-05-31 2019-09-20 广东睿江云计算股份有限公司 一种缓存文件自动更新方法及装置
CN110427323A (zh) * 2019-07-29 2019-11-08 天津车之家数据信息技术有限公司 一种应用测试方法、装置、代理服务器和系统
CN110489063A (zh) * 2019-08-27 2019-11-22 北京奇艺世纪科技有限公司 缓存过期时间的设置方法、装置、电子设备及存储介质
CN113055494A (zh) * 2021-03-30 2021-06-29 中国工商银行股份有限公司 通讯方法及通讯装置
CN114938393A (zh) * 2022-05-06 2022-08-23 中富通集团股份有限公司 一种机房数据交互方法及系统和存储介质
CN117149719A (zh) * 2023-07-31 2023-12-01 云达信息技术有限公司 基于web架构的服务端数据处理、装置、设备及介质

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108280111B (zh) * 2017-06-13 2020-11-24 阿里巴巴(中国)有限公司 页面处理方法、装置、用户终端以及存储介质
CN108282510A (zh) * 2017-06-13 2018-07-13 广州市动景计算机科技有限公司 缓存资源处理方法、装置、用户终端以及存储介质
CN109600403B (zh) * 2017-09-30 2021-11-02 北京国双科技有限公司 一种发送信息的方法及装置
CN109218395B (zh) * 2018-08-01 2020-05-12 阿里巴巴集团控股有限公司 缓存页面的分类、获取方法及装置和电子设备
CN109547421A (zh) * 2018-11-08 2019-03-29 锐捷网络股份有限公司 一种审计url的方法及装置
CN110472169A (zh) * 2019-07-12 2019-11-19 平安普惠企业管理有限公司 缓存配置方法、装置、计算机设备和存储介质
CN112055020A (zh) * 2020-09-04 2020-12-08 北京明朝万达科技股份有限公司 报文筛选方法、装置及数据传输系统
CN112995291B (zh) * 2021-02-05 2023-02-21 厦门市美亚柏科信息股份有限公司 一种基于代理的http报文采集方法、终端设备及存储介质
US11811734B2 (en) * 2021-06-17 2023-11-07 Prosimo Inc Protocol switching for connections to zero-trust proxy
CN117555822B (zh) * 2024-01-10 2024-06-14 深圳市雁联计算系统有限公司 一种通用缓存方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6965968B1 (en) * 2003-02-27 2005-11-15 Finjan Software Ltd. Policy-based caching
CN102026290A (zh) * 2010-12-16 2011-04-20 华为终端有限公司 一种无线移动网关及该无线移动网关响应用户访问的方法
CN102111449A (zh) * 2011-02-23 2011-06-29 北京蓝汛通信技术有限责任公司 一种更新数据的方法、装置和系统
CN102170479A (zh) * 2011-05-21 2011-08-31 成都市华为赛门铁克科技有限公司 Web缓存的更新方法及Web缓存的更新装置
CN103067467A (zh) * 2012-12-21 2013-04-24 深信服网络科技(深圳)有限公司 缓存方法及装置

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8612993B2 (en) * 2008-02-21 2013-12-17 Microsoft Corporation Identity persistence via executable scripts

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6965968B1 (en) * 2003-02-27 2005-11-15 Finjan Software Ltd. Policy-based caching
CN102026290A (zh) * 2010-12-16 2011-04-20 华为终端有限公司 一种无线移动网关及该无线移动网关响应用户访问的方法
CN102111449A (zh) * 2011-02-23 2011-06-29 北京蓝汛通信技术有限责任公司 一种更新数据的方法、装置和系统
CN102170479A (zh) * 2011-05-21 2011-08-31 成都市华为赛门铁克科技有限公司 Web缓存的更新方法及Web缓存的更新装置
CN103067467A (zh) * 2012-12-21 2013-04-24 深信服网络科技(深圳)有限公司 缓存方法及装置

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110263010A (zh) * 2019-05-31 2019-09-20 广东睿江云计算股份有限公司 一种缓存文件自动更新方法及装置
CN110263010B (zh) * 2019-05-31 2023-05-02 广东睿江云计算股份有限公司 一种缓存文件自动更新方法及装置
CN110427323A (zh) * 2019-07-29 2019-11-08 天津车之家数据信息技术有限公司 一种应用测试方法、装置、代理服务器和系统
CN110489063A (zh) * 2019-08-27 2019-11-22 北京奇艺世纪科技有限公司 缓存过期时间的设置方法、装置、电子设备及存储介质
CN110489063B (zh) * 2019-08-27 2023-12-19 北京奇艺世纪科技有限公司 缓存过期时间的设置方法、装置、电子设备及存储介质
CN113055494A (zh) * 2021-03-30 2021-06-29 中国工商银行股份有限公司 通讯方法及通讯装置
CN114938393A (zh) * 2022-05-06 2022-08-23 中富通集团股份有限公司 一种机房数据交互方法及系统和存储介质
CN114938393B (zh) * 2022-05-06 2024-04-19 中富通集团股份有限公司 一种机房数据交互方法及系统和存储介质
CN117149719A (zh) * 2023-07-31 2023-12-01 云达信息技术有限公司 基于web架构的服务端数据处理、装置、设备及介质
CN117149719B (zh) * 2023-07-31 2024-04-30 云达信息技术有限公司 基于web架构的服务端数据处理、装置、设备及介质

Also Published As

Publication number Publication date
CN106534243A (zh) 2017-03-22
CN106534243B (zh) 2020-02-18

Similar Documents

Publication Publication Date Title
WO2017045538A1 (zh) 基于http协议的缓存、请求、响应方法及相应装置
US20180019961A1 (en) Message processing method, processing server, terminal, and storage medium
Grigorik Making the web faster with HTTP 2.0
US10110507B2 (en) Push-based transmission of resources and correlated network quality estimation
KR101964927B1 (ko) 캐싱 프록시 방법 및 장치
TWI565258B (zh) 過濾https傳輸內容的系統、方法及裝置
US8577961B2 (en) Methods and apparatus for obtaining content with reduced access times
WO2017080459A1 (zh) 服务内容的缓存及提供方法、装置、系统和存储介质
CN109640113B (zh) 一种拖拉视频数据的处理方法及代理服务器
WO2015039559A1 (zh) 页面重定向方法、路由设备、终端设备及系统
CN102882974A (zh) 一种通过网站识别版本号节省网站访问资源的方法
US20170188055A1 (en) Video transmission method, gateway device, and video transmission system
WO2016107391A1 (zh) 缓存方法、缓存边缘服务器、缓存核心服务器和缓存系统
KR102036579B1 (ko) 무선 통신 시스템에서 웹 서비스 제공 방법 및 장치
WO2022127319A1 (zh) 数据刷新的方法、装置、电子设备及计算机可读存储介质
WO2015196442A1 (zh) 一种网页优化的设备及方法
CN103618799B (zh) 浏览器缓存处理方法、系统及代理服务器
US20160308924A1 (en) Method, apparatus, and system for delivering network video
WO2017020597A1 (zh) 一种资源缓存方法及装置
CN116996578B (zh) 基于内容分发网络的资源处理方法和装置
KR101650829B1 (ko) 대상을 획득하는 방법, 장치, 및 시스템
US20200092346A1 (en) Data buffering method and apparatus in adaptive streaming service
WO2017097027A1 (zh) 基于因特网内容适配协议的数据处理方法、装置和系统
WO2017092356A1 (zh) 用于提供服务数据的服务器、方法及系统
WO2015165034A1 (zh) 加载网页的方法和装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16845652

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16845652

Country of ref document: EP

Kind code of ref document: A1