CN117493397A - Request response method and device and electronic equipment - Google Patents

Request response method and device and electronic equipment Download PDF

Info

Publication number
CN117493397A
CN117493397A CN202311464605.1A CN202311464605A CN117493397A CN 117493397 A CN117493397 A CN 117493397A CN 202311464605 A CN202311464605 A CN 202311464605A CN 117493397 A CN117493397 A CN 117493397A
Authority
CN
China
Prior art keywords
target resource
service
resource
cache
request
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202311464605.1A
Other languages
Chinese (zh)
Inventor
陈伟
付科
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202311464605.1A priority Critical patent/CN117493397A/en
Publication of CN117493397A publication Critical patent/CN117493397A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9538Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • 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
    • H04L67/5682Policies or rules for updating, deleting or replacing the stored data

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a request response method, a request response device and electronic equipment, wherein the method comprises the steps that when a first service receives a target resource request, if the target resource exists in a cache of the first service, the target resource request is the first resource request after the target resource is out of date, and the first service returns the target resource returned by a second service to an initiator of the request; when the target resource request is not the first resource request after the target resource is expired, returning the target resource inquired in the cache to the initiator of each request; by the method, the response efficiency of the plurality of resource requests for the target resource can be improved, the response time of the plurality of resource requests for the target resource is shortened as a whole, and the utilization rate of communication resources is improved.

Description

Request response method and device and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a request response method, a request response device, and an electronic device.
Background
In a scenario where the amount of access requests is large in a short time, such as entertainment, game distribution, and operation, if a service (assumed to be service a) receives a plurality of requests for a first resource (the first resource may be an image resource, a text resource, an audio resource, a web page, or the like) in a short time, and the first resource is provided by another service (assumed to be service B) different from service a, the service B is accessed multiple times in a short time, resulting in a large amount of network resources being occupied, and the utilization of communication resources is not high.
Disclosure of Invention
In view of this, the embodiments of the present application provide a request response method, apparatus, and electronic device, so as to solve the problem in the related art that the utilization rate of communication resources is not high in a scenario of cross-service request resources.
The embodiment of the application is realized by adopting the following technical scheme:
in a first aspect, an embodiment of the present application provides a request response method, applied to an electronic device deploying a first service, where the method includes: if the first service receives a target resource request for requesting a target resource, inquiring the target resource in a cache of the first service; if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request; if the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource; receiving a target resource returned by the second service in response to the data request; and returning the target resource returned by the second service to the initiator of the target resource request, and updating the validity period of the target resource in the cache.
In a second aspect, an embodiment of the present application provides a request response device, including: the query module is used for querying the target resource in the cache of the first service if the first service receives a target resource request for requesting the target resource; the execution module is used for sending the target resource in the cache to an initiator of the target resource request if the target resource is inquired in the cache and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date; and if the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource; the receiving module is used for receiving a target resource returned by the second service in response to the data request; and the output module is used for returning the target resource returned by the second service to the initiator of the target resource request and updating the validity period of the target resource in the cache.
In some embodiments, the execution module includes a locking unit and a sending unit, where the locking unit is configured to lock the target resource request if the target resource is queried in the cache and it is determined that the target resource request is a resource request that first requests the target resource after the target resource in the cache expires; the sending unit is used for responding to the successful locking of the target resource request and sending a data request to a second service providing the target resource; the output module further comprises an unlocking unit, wherein the unlocking unit is used for unlocking the locked target resource request.
In some embodiments, the execution module is further configured to send a data request to the second service if the target resource is not queried in the cache; the output module is further used for setting a validity period for the target resource and storing the target resource returned by the second service into the cache.
In some embodiments, the resources in the cache are stored in the form of key value pairs, and the request response device further includes a cache management module, where the cache management module is configured to release a key occupied by a reference resource in the cache and delete the reference resource in the cache if the key in the cache reaches a key capacity threshold of the cache; creating a new key in the cache based on the resource identification of the target resource; the output module is further used for taking the validity period set for the target resource and the target resource as the value of the new key, and storing the new key into the cache.
In some embodiments, the cache management module is further configured to determine a frequency of use parameter of each resource in the cache during the first period of time; and taking the resource with the minimum frequency of use parameter in the cache as a reference resource.
In some embodiments, the execution module is further configured to send the target resource queried from the cache to the initiator of the target resource request if the target resource is queried in the cache and the target resource in the cache is determined to be within the validity period.
In some embodiments, the request response device further includes a policy validation module for determining a second service providing the target resource if the first service receives the target resource request for requesting the target resource; if the resource updating frequency of the second service is smaller than the updating frequency threshold value, searching a target resource in the cache of the first service; and if the resource updating frequency of the second service is not less than the updating frequency threshold, sending a data request to the second service so that the second service returns the target resource obtained by query in response to the data request.
In a third aspect, an embodiment of the present application provides an electronic device, including: one or more processors; a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs configured to perform the method as described above.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium having program code stored thereon, the program code being executable by a processor to perform the above method.
In a fifth aspect, embodiments of the present application provide a computer program product comprising a computer program/instruction which, when executed by a processor, performs the steps of the above method.
According to the request response method, the device and the electronic equipment, after the first service receives the target resource request for requesting the target resource, if the target resource is queried in the cache of the first service and the target resource request is the resource request for requesting the target resource first after the target resource in the cache expires, the first service sends the data request to the second service for providing the target resource according to the target resource request, and updates the validity period of the target resource in the cache of the first service according to the target resource returned by the second service, so that timeliness of the target resource is ensured; if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request; in the process of processing the resource request of the first request target resource after the expiration of the target resource in the cache (namely, in the process of sending the data request to the second service and waiting for the return result of the second service), the target resource in the cache is utilized to respond to other requests for the target resource, and all the resource requests for the target resource are not required to wait for the return result of the second service, and only the resource request of the first request target resource is required to wait for the return result of the second service after the expiration of the target resource, so that the response efficiency to a plurality of resource requests for the target resource can be improved under the condition that the target resource in the cache is expired, the response time of the plurality of resource requests for the target resource is shortened as a whole, the user experience is improved, and the first service only needs to send the data request to the second service once when the first service receives the plurality of resource requests for the target resource in a period, and the utilization rate of communication resources between the first service and the second service can be improved.
These and other aspects of the present application will be more readily apparent from the following description of the embodiments.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly introduced below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 illustrates a request response flow diagram for a cache-less policy.
FIG. 2 illustrates a request response flow diagram for a single cache policy.
Fig. 3 shows a request response flow diagram of a local caching policy.
Fig. 4 is a schematic flow chart of a request response method according to an embodiment of the present application.
Fig. 5 shows a schematic flow chart of step S130 in fig. 4 according to an embodiment of the present application.
Fig. 6 shows a further flowchart of a request response method according to an embodiment of the present application.
Fig. 7 is a schematic flow chart of a request response method according to an embodiment of the present application.
Fig. 8 is a schematic flow chart of a request response method according to an embodiment of the present application.
Fig. 9 shows a schematic flow chart of step S241 in fig. 7 provided in an embodiment of the present application.
Fig. 10 shows a schematic diagram of a scenario involved in a request response method provided in an embodiment of the present application.
Fig. 11 shows a flowchart related to a request response method provided in an embodiment of the present application.
Fig. 12 is a schematic diagram of a request access process according to an embodiment of the present application.
Fig. 13 shows a schematic diagram of a request response device provided in an embodiment of the present application.
Fig. 14 shows a schematic diagram of an electronic device provided in an embodiment of the present application.
Detailed Description
Embodiments of the present application are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar elements or elements having like or similar functions throughout. The embodiments described below by referring to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present application.
In order to better understand the technical solutions of the present application, the following will make a clear and complete description of the technical solutions of the embodiments of the present application with reference to the drawings in the embodiments of the present application. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
To facilitate an understanding of the present solution, several terms are explained below:
cache (cache): is a buffer area for data exchange and is a temporary place for storing data; in this application, a cache is a memory on an electronic device for storing temporary data, where the cache data is also called memory data.
Key-value pair: implementation of mappings in a logarithmic concept in a programming language; wherein a key (key) is used as a unique identifier, as an index to the element, and a value (value) represents the stored data.
Service: an application program implementing one or more business functions. Services may typically provide some functionality to users locally and over a network, such as: network interactions, image classification, voice classification, text recognition, etc.
Service services: a service for handling client accesses.
Downstream services: if the service a needs to call the service B in the running process, the service B is the service on which the service a depends, i.e. the service B is the downstream service of the service a. In a specific embodiment, the downstream service on which a service depends may be one or more, the downstream service on which a service (assumed to be service a) depends may be a service on which service a directly depends, or may be a service on which service a indirectly depends, for example, if service a may directly call service B, service B is a downstream service on which service a directly depends, if service a needs to call service C first and then call service B by service C, service C is a downstream service on which service a directly depends, and service B is a downstream service on which service a indirectly depends.
In a scenario where the amount of access requests is large in a short time, if a service (assumed to be service a) receives a plurality of requests requesting a first resource (the first resource may be an image resource, a text resource, an audio resource, a web page, etc.) in a short time, and the first resource is provided by another service (assumed to be service B) different from service a, in the related art, in order to ensure an orderly response of the plurality of requests, the service a generally sends data requests for the first resource to the service B in sequence, and then returns the first resource to the initiator of the request according to the first resource returned by service B, so as to realize the orderly response of the plurality of requests. It can be seen that in this case, service a needs to call service B multiple times to query the first resource.
In some business scenarios, such as entertainment, game release, operation activities, etc., the frequency of modifying the resources provided by the service B is low, and the first resources queried by the service a for multiple times of invoking the service B in a shorter period of time are actually the same, so that in a shorter period of time, the service a invokes the service B for multiple requests for requesting the same first resources respectively to query the first resources with low frequency of modifying, and there is a problem that the network bandwidth occupied by invoking the service B is more, and multiple times of invoking the service B requests the same resources, resulting in low utilization rate of communication resources.
At present, in order to solve the above problem, the request is often processed by the following three policies, including no cache (no cache) policy, single cache (single cache) policy, and local cache (local cache) policy, where the processing flows of the three policies are specifically explained as follows:
scheme one: in a no cache policy, that is, when the service a receives multiple resource requests for the same resource (assuming that the resource is the first resource) in a first period of time, for each resource request, a data request is initiated to a downstream service that provides the first resource, and the first resource returned by the downstream service is sent to the request initiator, where the returned first resource is not cached.
The processing flow is shown in fig. 1, fig. 1 shows a request response flow diagram without a cache policy, if a service a receives three resource requests for a first resource in a first time period, namely, a request 1, a request 2 and a request 3 in fig. 1, after receiving the request 1, the service a initiates a data request to a downstream service (namely, a service B), and after receiving the first resource returned by the service B, the service a sends the first resource returned by the service B to an initiator of the request 1; similarly, the processing for request 2 and request 3 is similar to request 1.
It can be seen that, if a processing mode without a cache policy is adopted, the number of times that the service a is requested to be accessed, that is, the number of times that the service B is accessed by the service a; for example, if service a receives 100 resource requests for the first resource in the first period, service a will be accessed 100 times, i.e., the access amount of service a is 100, and service B will be accessed 100 times by service a, i.e., the access amount of service B is also 100.
Obviously, by adopting a processing strategy without cache, each resource request can execute a complete access flow (namely, request to access service A-service A to access service B-service B to return request data to service A-service A to send the data returned by service B to the initiator of the request), so that the resource obtained by the initiator of each resource request is the latest resource returned by service B; however, since the resource modification frequency of the service B is low, the resources returned in a period of time are the same, and a complete access flow occupies a large amount of system resources and network bandwidth, on one hand, the utilization rate of communication resources is low, and on the other hand, since the service a needs to call the service B in sequence for each of a plurality of resource requests, the waiting time of part of the resource requests in the plurality of resource requests is long, the response delay of part of the resource requests is long, and the user experience is poor.
Scheme II: a single flight (single) policy, that is, a plurality of resource requests for a first resource in a first period of time are sent to a downstream service providing the first resource by initiating a data request for the resource request of the first request for the first resource in a blocking manner, and the first resource returned by the downstream service is sent to all the resource requests for the first resource in the first period of time; in other words, a plurality of resource requests for the first resource within the first time period are treated as one resource request.
The operation process is shown in fig. 2, fig. 2 shows a request response flow diagram of a single cache policy, if service a receives three resource requests for a first resource in a first period of time, service a locks 3 resource requests (i.e. 3 resource requests wait for processing to form a blocking process), and respectively determines whether each resource request is a resource request for first requesting the first resource in the first period of time, if the resource request for first requesting the first resource in the first period of time is the first resource request, service a initiates a data request to service B according to the resource request, and after receiving the first resource returned by service B, writes the first resource returned by service B into a cache, and unlocks all resource requests for the first resource in the first period of time, and service a returns the first resource in the cache to an initiator of each resource request by reading the first resource in the cache.
Obviously, compared with a non-cache strategy, the single cache strategy greatly reduces the access amount of the service B; for example, if service a receives 100 resource requests for the first resource in the first period of time, the access amount of service a is 100, and service B is accessed according to the first resource request requesting the first resource, and after service B returns to the first resource, the remaining 99 resource requests can obtain the first resource by reading the service cache, so the access amount of service B is 1.
Scheme III: a local cache (local cache) policy considers that the modification frequency of the service B is low, that is, the request result is the same within a period of time, so that the first resource is cached in the local of the service a, and the validity period of the cache is increased; after the service A receives the request, the first resource in the effective period is directly returned to the initiator of the request by inquiring the first resource in the local cache, so that the request for the service B is further reduced.
The operation process is shown in fig. 3, fig. 3 shows a flow diagram of a local cache, when a service a receives a plurality of resource requests for a first resource in a first period of time, the service a reads the local cache, and if the first resource of the request exists in the local cache of the service a and the first resource in the cache is not expired, the service a directly sends the first resource in the cache to each resource request initiator; if the first resource requested exists in the cache, but the first resource in the cache has expired, or the first resource requested does not exist in the cache, the service A locks the 3 resource requests and initiates a data request to the service B, after the service B returns the first resource, the service B unlocks the 3 resource requests and sends the first resource returned by the service B to the initiator of each resource request.
For example, if there are 100 resource requests for the first resource in every 100ms, the service a takes 100ms to request for the service B, the validity period of the first resource returned by the service B is 1s, and the access amount of the service a is 100 in [0,100ms ]), where, if the first resource does not exist in the cache of the service a, the service a needs to access the service B to perform the data request, that is, the access amount of the service B is 1; and in [100ms,1000 ms), the amount of resource requests received by the service a for the first resource is 900, but since the first resource already exists in the cache of the service a at this time and the first resource is in the validity period, the service a directly sends the first resource in the cache to the initiator of each resource request, so that the access amount of the service B is 0.
Obviously, as long as the request time of receiving the resource request for the first resource is within the validity period of the first resource in the cache, the first resource can be directly read from the cache and returned to the initiator of the resource request; compared with a non-buffer strategy and a single-buffer strategy, the local buffer strategy can reduce the access quantity of the service B to a greater extent. However, after the validity period of the first resource in the cache is exceeded, the service B still needs to be accessed again to request to obtain the first resource, so that the waiting time for the request to respond is too long due to the expiration of the resource in the cache in the actual running process.
Therefore, in order to reduce the waiting response time of a request as much as possible, improve the response speed of the request and improve the utilization rate of communication resources, the application provides a request response method, a device and an electronic device, and the method is applied to the electronic device for deploying the first service and comprises the following steps: if the first service receives a target resource request for requesting the target resource, inquiring the target resource in a cache of the first service; if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request; if the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource; receiving a target resource returned by the second service in response to the data request; and returning the target resource returned by the second service to the initiator of the target resource request, and updating the validity period of the target resource in the cache.
According to the request response method provided by the application, after the first service receives the target resource request for requesting the target resource, if the target resource is queried in the cache of the first service, and the target resource request is the first resource request for requesting the target resource after the target resource in the cache expires, the first service sends a data request to the second service for providing the target resource according to the target resource request, and updates the effective period of the target resource in the cache of the first service according to the target resource returned by the second service, so that the timeliness of the target resource is ensured; if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request; in the process of processing the resource request of the first request target resource after the expiration of the target resource in the cache (namely, in the process of sending the data request to the second service and waiting for the return result of the second service), the target resource in the cache is utilized to respond to other requests for the target resource, and all the resource requests for the target resource are not required to wait for the return result of the second service, and only the resource request of the first request target resource is required to wait for the return result of the second service after the expiration of the target resource, so that the response efficiency to a plurality of resource requests for the target resource can be improved under the condition that the target resource in the cache is expired, the response time of the plurality of resource requests for the target resource is shortened as a whole, the user experience is improved, and the first service only needs to send the data request to the second service once when the first service receives the plurality of resource requests for the target resource in the first time period, and the utilization rate of communication resources between the first service and the second service can be improved.
Embodiments of the present application will be described in detail below with reference to the accompanying drawings.
As shown in fig. 4, fig. 4 is a flowchart of a request response method provided in an embodiment of the present application, where the request response method is applied to an electronic device deploying a first service, and the method includes:
s110, if the first service receives a target resource request for requesting the target resource, the target resource is queried in a cache of the first service.
The target resource request refers to a resource request currently pending by the first service, and the resource requested by the target resource request is referred to as a target resource. The target resource may be a web page, blog, video, audio, article, etc. In this application, the target resource is provided by a service different from the first service, and for convenience of distinction, the service providing the target resource is referred to as a second service, which is understood to be a downstream service on which the first service depends, and may be a downstream service on which the first service directly depends or may be a downstream service on which the first service indirectly depends.
In this application, a cache is deployed for a first service, which may store resources acquired from other services (e.g., a second service) for a responded to resource request. The first service and the second service may be disposed in the same electronic device, or may be disposed in different electronic devices, which is not particularly limited herein.
It should be noted that, the target resource in the cache of the first service is provided by the downstream service of the first service, that is, the second service in the present application, and of course, different resources in the cache of the first service may be provided by the same service or may be provided by different services. Thus, the complete acquisition procedure of each resource in the cache of the first service should include (illustrated as acquiring the second resource): the first service receives a resource request for requesting the second resource, accesses the service providing the second resource (supposing to be a third service) according to the resource request, receives the access request of the first service and returns the second resource, and receives the second resource returned by the third service and stores the second resource in the cache.
Further, the first service may serve one resource request or may serve multiple resource requests; of course, when the first service serves multiple resource requests, the cache of the first service may include resources requested by each of the multiple resource requests.
In some embodiments, each resource in the cache may be stored in association with a resource identifier corresponding to the resource. Because the target resource request contains the resource identifier of the target resource, for example, the A-type request is used for requesting the 'address' resource, and the B-type request is used for requesting the 'image' resource, after receiving the target resource request, the first service acquires the resource identifier of the target resource from the target resource request, further queries whether the resource identifier of the target resource exists in the cache, and determines that the target resource exists in the cache if the resource identifier of the target resource is queried in the cache; otherwise, if the resource identification of the target resource is not queried in the cache, determining that the target resource does not exist in the cache.
S120, if the target resource is queried in the cache, and it is determined that the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache expires, the target resource in the cache is sent to the initiator of the target resource request.
The buffer memory of the first service also stores the valid period or valid time corresponding to each resource; the starting time of the validity period of each resource in the cache can be the time when the resource is written into the cache, or the time when the first service calls other downstream services to acquire the resource, the duration of the validity period of the resource can be preset, and the duration of the validity period of different types of resources can be the same or different. The end time of the validity period of a resource (or the expiration time of the corresponding resource) is the sum of the start time of the validity period and the duration of the validity period.
Therefore, under the condition that the target resource is queried in the cache, whether the target resource in the cache is out of date or not can be determined based on the validity period of the target resource in the cache and the time for querying the target resource in the cache, namely, if the time for querying the target resource in the cache is not within the validity period of the target resource, the target resource in the cache is determined to be out of date.
In some embodiments, a request processing log of the first service may be obtained, where the request processing log includes at least a request time of each resource request received by the first service and a resource identifier of a resource requested by the resource request, when the first service receives a target resource request, queries a target resource in a cache and determines that the target resource is out of date, queries the request processing log, and determines that the target resource request is not a resource request for requesting the target resource for the first time after the target resource is out of date if it is determined that there are other resource requests for requesting the target resource from an expiration time of the target resource in the cache to a request time of the target resource request according to the request processing log; if it is determined, according to the request processing log, that no other resource requests for requesting the target resource exist between the expiration time of the target resource in the cache and the request time of the target resource request, the target resource request is determined to be the resource request for requesting the target resource first after the expiration of the target resource.
In some embodiments, a time sequence of each resource in the cache may be generated based on the request processing log of the first service and the validity period (including the start time and the expiration time of the validity period) of each resource in the cache, where a time sequence of each resource includes the start time and the expiration time of the validity period of each resource and the request time of the resource request requesting the resource, thereby, in a case where the first service determines that the target resource exists in the cache and the target resource has expired, querying in the time sequence of the target resource whether there is another request time between the expiration time of the target resource and the request time of the target resource request, and if there is a request time indicating that the target resource request is not the resource request of the first request target resource after the expiration of the target resource in the cache; otherwise, if the target resource does not exist, the target resource request is the resource request for requesting the target resource for the first time after the target resource in the cache expires. In this embodiment, a time sequence is generated for each resource in the cache in a targeted manner, so that, for a target resource request, a query is performed in the time sequence corresponding to the target resource, thereby improving query efficiency and improving efficiency of determining whether the target resource request is a resource request for requesting the target resource for the first time after the target resource in the cache expires.
In other embodiments, considering that the first service may query the target resource in the cache of the first service according to the target resource request, and the queried target resource is still in an expired state, it represents that only the following two cases exist at this time: after the target resource in the cache expires, until the first service receives the target resource request, the first service does not receive the resource request for requesting the target resource, so that the first service does not send a data request to the second service, and the target resource in the cache is still in an expired state; after the target resource expires, the first service receives other resource requests (for convenience of distinguishing, referred to as first resource requests) requesting the target resource before the first service receives the target resource request, but the processing of the first resource request is not finished, that is, the second service is being accessed but the target resource is not returned to the first service, so that the first service fails to update the validity period of the target resource in the cache, and the queried target resource is still in an expired state. Therefore, the first service can be set to access the second service through a single thread, that is, the first service can only have one request to access the second service for the same resource provided on the second service at the same time, after the first service receives the resource request for requesting the target resource, if it is determined that the target resource needs to be requested to the second service, the resource request can be locked, and then a data request is sent to the second service to request the second service to return to the target resource in response to the data request. On this basis, the first service, after receiving the target resource request, may query whether there is a resource request locked for requesting the target resource, to determine whether the target resource request is the first resource request after expiration of the target resource.
For example, when the first service determines that the target resource in the cache has expired based on the target resource request, determining whether there is a locked resource request for requesting the target resource currently, if so, indicating that other resource requests for requesting the target resource are received before the expiration time of the target resource in the cache reaches the time when the target resource request is received, thereby determining that the current target resource request is not the resource request for requesting the target resource first after the target resource in the cache expires; otherwise, it may be determined that the current target resource request is a resource request that first requests the target resource in the cache after the target resource expires.
According to the method provided by the embodiment of the invention, when the target resource request is not the first resource request for requesting the target resource after the target resource in the cache is out of date, the target resource in the cache is sent to the initiator of the target resource request, so that the timely response to the target resource request is realized, the condition that the target resource request can be responded only after other resource requests for requesting the target resource, which are received before the target resource request, are required to be responded is avoided, and the efficiency for responding the target resource request is improved.
It should be noted that, since the target resource queried in the cache, that is, the target resource exceeding the validity period is returned, if the target resource changes after expiration, the target resource received by the requester is inconsistent with the real target resource at the moment. However, considering that the modification frequency of the target resource provided by the second service is low, the probability of the target resource changing is low in a short time, so that the probability of the target resource unchanged after the target resource in the cache is out of date is high, and the probability of the target resource returned to the requester is high.
S130, if the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource.
The method for determining that the target resource request is the first resource request for requesting the target resource after the expiration of the target resource in the cache may refer to the specific description of step S120 in the foregoing embodiment, which is not described herein again.
It should be noted that, in the process of the second service responding to the data request for requesting the target resource, if the first service also receives the resource requests for other request target resources, according to the description in step S120, the resource requests for other request target resources are determined to be not the resource request for the first request target resource after the expiration of the target resource in the cache, so as to directly send the target resource in the cache to the initiator of the other request target resource.
In some embodiments, in order to avoid interference of other resource requests, a locking manner is used to ensure normal access of the target resource request, as shown in fig. 5, fig. 5 shows a schematic flow chart of step S130 in fig. 4 provided in the embodiment of the present application, and step S130 includes the following steps S131-132:
s131, if the target resource is queried in the cache and the target resource request is the first resource request for requesting the target resource after the target resource in the cache is out of date, locking the target resource request.
Wherein locking is a specific operation that lets resource requests wait to be responded to; specifically, the target resource request is indicated as being currently processed by locking the target resource request.
For example, if the first service receives the resource request 1 and the resource request 2 for requesting different resources, and locks the resource request 1 first, and does not lock the resource request 2, at this time, the resource request 1 waits to be responded, that is, the first service sends a data request to the second service according to the resource request 1, and returns to the initiator of the resource request 1 after receiving the target resource returned by the second service; the resource request 2 is not locked, the first service does not process the resource request 2 temporarily, but after the processing of the resource request 1 is completed, the resource request 1 is unlocked, then the resource request 2 is locked, and the surface is processing the resource request 2.
And S132, responding to successful locking of the target resource request, and sending a data request to a second service providing the target resource.
S140, receiving a target resource returned by the second service in response to the data request.
It should be noted that, if the target resource is not updated, that is, the target resource returned by the second service in response to the data request is the same as the target resource queried in the cache of the first service; if the target resource is updated, namely the target resource returned by the second service in response to the data request is different from the target resource inquired in the cache of the first service.
Of course, if a locking operation as in steps S131-S132 is employed in step S130, then after step S140, the locked target resource request needs to be unlocked, representing that the target resource request is completed, while facilitating the locking operation of the next resource request by the first service.
S150, returning the target resource returned by the second service to the initiator of the target resource request, and updating the validity period of the target resource in the cache.
It should be noted that, when the target resource returned by the second service is the same as the target resource queried in the cache of the first service, in order to reduce the updated data volume, only the validity period of the target resource in the cache may be updated; when the target resource returned by the second service is different from the target resource inquired in the cache of the first service, the target resource in the cache needs to be updated at the same time of updating the validity period of the target resource in the cache, namely, the target resource in the cache is updated to the target resource returned by the second service. The starting time of the validity period of the target resource in the updated cache may be the time when the second service returns to the target resource, so that the updated expiration time may be correspondingly determined based on the new starting time and the preset duration of the validity period.
Of course, in other embodiments, after receiving the target resource returned by the second service, the first service may directly replace the target resource queried in the cache by using the target resource returned by the second service, and update the validity period corresponding to the target resource, without comparing the target resource returned by the second service with the target resource in the cache.
According to the method provided by the embodiment of the application, after the first service receives the target resource request for requesting the target resource, if the target resource is queried in the cache of the first service, and the target resource request is the first resource request for requesting the target resource after the target resource in the cache expires, the first service sends the data request to the second service for providing the target resource according to the target resource request, and updates the validity period of the target resource in the cache of the first service according to the target resource returned by the second service, so that the timeliness of the target resource is ensured; if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request; in the process of processing the resource request of the first request target resource after the expiration of the target resource in the cache (namely, in the process of sending the data request to the second service and waiting for the return result of the second service), the target resource in the cache is utilized to respond to the requests of other request target resources, and all the resource requests of the target resource are not required to wait for the return result of the second service, and only the resource request of the first request target resource is required to wait for the return result of the second service after the expiration of the target resource, so that the response efficiency to the plurality of resource requests of the target resource can be improved under the condition that the target resource in the cache is expired, the response time of the plurality of resource requests of the target resource is shortened as a whole, the user experience is improved, and if the first service receives the plurality of resource requests of the target resource in a period, the first service only needs to send the data request to the second service once, and the utilization rate of communication resources between the first service and the second service is not required to send the plurality of data requests.
In other embodiments, after step S110, the request response method may further include: if the target resource is queried in the cache and the target resource in the cache is determined to be in the valid period, the target resource queried in the cache is sent to the initiator of the target resource request.
In some embodiments, as shown in fig. 6, fig. 6 shows a further flowchart of the request response method provided in the embodiments of the present application, and step S110 includes:
s160, if the first service receives a target resource request for requesting the target resource, determining a second service for providing the target resource.
Wherein the second service may provide a plurality of resources, i.e. different resource requests may correspond to the same second service.
The second service determination may determine, through a correspondence between the resource identifier and the service, that the service corresponding to the resource identifier in the target resource request is determined as the second service that provides the target resource.
S170, if the resource updating frequency of the second service is smaller than the updating frequency threshold value, searching the target resource in the cache of the first service.
The resource update frequency of the second service may be preset according to the type of the resource provided by the second service, for example, the resource update frequency is a for the second service providing the class a resource, and the resource update frequency is B for the second service providing the class B resource. The resource update frequency of different services may be preset, or may be determined according to a resource update record corresponding to a service.
It should be noted that, the resource update frequency of the second service is smaller than the update frequency threshold, which indicates that the probability of the resource provided by the second service changing is lower in a short time, so that the target resource in the cache of the first service can be utilized to return to the initiator of the resource request, and the probability of the target resource received by the initiator of the resource request being accurate is higher, thereby ensuring the feasibility of the response of the resource request.
And S180, if the resource updating frequency of the second service is not less than the updating frequency threshold, sending a data request to the second service so that the second service returns to the target resource obtained by the query in response to the data request.
It should be noted that, the resource update frequency of the second service is not less than the update frequency threshold, which indicates that in a short time, the probability of changing the resource provided by the second service is higher, and even if the target resource in the cache of the first service is returned to the source of the resource request, the target resource received by the source of the resource request is also a wrong resource that cannot be used; therefore, when the resource updating frequency of the second service is not smaller than the updating frequency threshold, the data request is sent to the second service, and the target resource returned by the second service response data request is sent to the initiator of the resource request, so that the accuracy of the target resource received by the initiator of the resource request is ensured.
It will be appreciated that if the resource update frequency of the second service is not less than the update frequency threshold, the resource provided by the second service with the higher resource update frequency need not be stored in the cache. That is, in this case, the latest target resource is requested from the second service each time.
In other embodiments, as shown in fig. 7, fig. 7 shows another flow chart of a request response method provided in the embodiment of the present application, where the request response method includes:
s210, if the first service receives a target resource request for requesting a target resource in a first period, querying the target resource in a cache of the first service.
The specific description of step S210 is the same as or similar to the procedure of step S110 in the foregoing embodiment, and thus, the specific description of step S210 may refer to the specific description of step S110 in the foregoing embodiment, and will not be repeated here.
S220, if the target resource is not queried in the cache, sending a data request to the second service.
In some embodiments, the target resource request may also be locked prior to sending the data request to the second service; if resource requests of other request target resources are received in the process of waiting for the second service to respond to the data request, the resource requests of other request target resources can be locked.
S230, receiving a target resource returned by the second service in response to the data request.
The specific description of step S230 is the same as or similar to the process of step S140 in the foregoing embodiment, and thus, the specific description of step S230 may refer to the specific description of step S140 in the foregoing embodiment, and will not be repeated here.
S240, returning the target resource returned by the second service to the initiator of the target resource request, setting the validity period for the target resource, and storing the target resource returned by the second service into a cache.
When a plurality of target resource requests exist in the first time period, the target resource requests are sequentially processed in a locking mode, and the target resource requests all need to wait for the second service to return to the target resource, namely blockage is generated; however, after the first target resource request is responded, the target resource corresponding to the target resource request is already stored in the cache, and when the first service processes the subsequent target resource request, the subsequent target resource request can directly inquire the target resource in the cache, so that the target resource in the cache is directly returned, the second service is not required to be accessed again, and the blocking time is reduced.
It should be noted that, in some embodiments, the resources in the cache are stored in the form of key-value pairs, and considering that the capacity of the cache is limited, as shown in fig. 8, fig. 8 shows a further flow schematic diagram of the request response method provided in the embodiment of the present application, and before step S240, the request response method further includes:
s241, if the key in the cache reaches the threshold of the key capacity of the cache, releasing the key occupied by the reference resource in the cache, and deleting the reference resource in the cache.
It will be appreciated that the deletion of the reference resource is to free up space in the cache in order to write new resources in the cache.
Wherein, the determination of the reference resource can have various modes; in some embodiments, the resource with the largest occupied space in the cache can be determined as the reference resource in consideration of the maximum capacity release, so that more cache space is obtained through one deleting operation; meanwhile, more cache space means that deletion is not needed again in a short time, so that the execution times of deletion operations are reduced.
In other embodiments, the determining of the resource with the lowest frequency of use as the reference resource may be based on the determining of the frequency of use of the target resource, as shown in fig. 9, fig. 9 shows a schematic flow chart of step S241 in fig. 7 provided in the embodiment of the present application, where step S241 includes:
S2411, determining a frequency of use parameter of each resource in the buffer in the first time period.
The determining of the first time period may be based on the current time, for example, a time period within a preset duration before the current time is taken as the first time period; the determination may be based on the request time of the current target resource request, and the time period within a preset time period before the request time is used as the first time period, which is not particularly limited herein.
The usage frequency parameter may refer to the number or frequency of queries over a first period of time.
S2412, taking the resource with the smallest frequency of use parameter in the cache as the reference resource.
Obviously, as the frequency of the use of the reference resource is the lowest, the probability of resource request for requesting the reference resource is the smallest in a short time, thereby reducing the modification frequency of the needed cache to the greatest extent; for example, for resource a and resource B in the cache, the frequency of use of resource a is 1 time per 10ms and the frequency of use of resource B is 5 times per 10 ms; if the resource B is deleted as the reference resource, the resource B is possibly used for 5 times within 10ms after the deletion, so that other services need to be called again to inquire the resource B; if the resource A is deleted as the reference resource, the resource A may need to be used only once within 10ms after deletion, thereby reducing the modification frequency of the cache.
Among them, steps S2411 and S2412 may be concretely implemented by a least recently used algorithm (Least Recently Used Algorithm, LRU).
S242, creating a new key in the cache based on the resource identification of the target resource.
Wherein the new key is a unique identifier that is the target resource; for example, if the target resource requested by the target resource request is the address of a certain active page, the resource identifier is "address", and the key value is created by using the "address", where the corresponding target resource is specific address information. In some embodiments, the resource identifier of the target resource may be hashed, and the result of the hash is used as a new key.
Further, when the resource in the cache is stored in the form of key-value pairs, step 240 may specifically include:
and taking the validity period set for the target resource and the target resource as the value of a new key, and storing the values into a cache.
According to the request response method provided by the embodiment of the application, when the target resource is not queried in the cache, the resource in the cache is updated through the target resource returned by the second service, so that the subsequent resource request aiming at the target resource can directly obtain the target resource through reading the cache, and the response efficiency of the subsequent resource request aiming at the target resource is ensured; meanwhile, the capacity setting of the cache is fully considered, and after the threshold value of the key capacity in the cache is reached, the key capacity in the cache is released by deleting the least used reference resource in the first time period, so that the writing of the target resource is facilitated.
For ease of understanding, referring to fig. 10, fig. 10 is a schematic diagram of a scenario involved in a request response method provided by an embodiment of the present application, where the scenario includes a home page service (i.e. a first service in the present application), a cache component of the home page service (i.e. a cache of the first service in the present application), and a configuration service (i.e. a second service in the present application), and the request response method provided by the present application is executed by an electronic device where the home page service and the cache component of the home page service are located.
After receiving the target resource request sent by the client, the home page service queries the cache component according to the target resource request, and if the target resource in the validity period is queried in the cache component, the queried target resource in the cache component is returned to the client. In such a scenario, the target resource requested by the target resource request may be a page, or configuration information for the page. Thus, after the home page service returns the target resource to the initiator of the target resource request, the client can correspondingly display the page.
If the target resource outside the effective period is inquired in the cache component, accessing configuration service; for a target resource request for requesting the target resource for the first time after expiration, sending a data request for requesting the target resource to a configuration service, waiting for the configuration service to return the target resource, and returning the target resource returned by the configuration service to a client by a home page service, and updating the validity period of the target resource in a cache component by using the target resource returned by the configuration service; for a target resource request which does not firstly request the target resource after expiration, because the configuration service is in an accessed state at the moment, namely, the configuration service is in the process of returning to the target resource, if the configuration service is accessed again, the configuration service can cause blockage, so that in order to avoid blockage, the home page service directly transmits the target resource out of the effective period inquired in the cache component to the client; therefore, the waiting time of the target resource request which does not first request the target resource after the target resource in the cache component is out of date is reduced, and the response efficiency is improved.
If the target resource is not queried in the cache component, the home page service sends a data request to the configuration service and sends the target resource returned by the configuration service to the client; meanwhile, the target resource returned by the configuration service and the validity period set for the target resource are associated and stored in the cache component.
Specifically, referring to fig. 11, fig. 11 shows a flowchart related to a request response method provided in the embodiment of the present application, where service a is a first service in the present application, service B is a second service in the present application, a cache component is a cache of the first service in the present application, and resources in the cache component are stored in a key value pair.
Service a receives multiple resource requests (request 1, request 2, and request 3 are exemplarily shown in fig. 10) requesting the same resource (e.g., target resource) in a second period of time, determines a Key identifying the target resource through a resource identifier corresponding to the target resource, and queries in the cache component based on the Key identifying the target resource (i.e., key); if the corresponding Key is inquired and the Key is not expired, cache data associated with the Key, namely target resources in the application, are read in the cache component, and the cache data corresponding to the Key are returned to the initiator of each resource request.
If a corresponding Key is queried, when the Key is expired (note that the expiration of the Key refers to the expiration of the resource associated with the Key), the first resource request accessing the Key after expiration is locked, namely, the service A processes the first resource request accessing the Key after expiration, the service A accesses the service B according to the resource request and waits for the service B to return to a target resource, and at the moment, for other first resource requests accessing the Key which are not after expiration, cache data corresponding to the Key are read, namely, the target resource in the application, the cache data corresponding to the Key is returned to an initiator of the resource request, so that the waiting of other initiators of the resource requests is avoided; after the service B returns the target resource, the validity period corresponding to the Key in the cache component is updated through the target resource returned by the service B (naturally, if the target resource returned by the service B is updated compared with the target resource in the original cache, the target resource in the cache should be updated), and meanwhile, the first request for accessing the Key after expiration is unlocked, and the target resource returned by the service B is returned to the initiator of the resource request.
If the Key is not inquired in the cache component, checking whether the Key capacity of the cache component reaches an upper limit, if the Key capacity of the cache component does not reach the upper limit, locking all resource requests, accessing the service B by the service A according to the resource requests, waiting for the service B to return to the target resource, storing the target resource returned by the service B corresponding to the Key allocated for the target resource in the cache component after the service B returns to the target resource, and updating the expiration time of the Key; and simultaneously, unlocking all the resource requests, and returning the target resource returned by the service B to the initiator of each resource request.
If the Key capacity of the cache component reaches the upper limit, releasing a Key according to the least recently used algorithm, creating a new Key, simultaneously locking all resource requests, enabling the service A to access the service B according to the resource requests, waiting for the service B to return to the target resource, storing the target resource returned by the service B corresponding to the Key of the new Key after the service B returns to the target resource, and updating the expiration time of the Key; and simultaneously, unlocking all the requests, and returning the target resource returned by the service B to the initiator of the request.
Obviously, in the above access flow, only when the corresponding Key does not exist in the cache of the service a, a short blocking may occur; as long as the corresponding Key exists in the cache of the service A, no matter whether the Key is in the effective period or not, the request cannot be blocked, so that the possibility of blocking in the running process is greatly reduced, the response speed of the request is improved, and the user experience is optimized.
For example, referring to fig. 12, fig. 12 is a schematic diagram of a request access process provided in the embodiment of the present application, where a target resource is queried in a cache of a service a, but the queried target resource is not within a validity period.
After the cache of the service a is queried, the service a finds that a corresponding target resource exists in the cache of the service a, but the target resource is expired, at this time, the service a determines that the request sent by the user 1 is a request for first requesting the target resource after the target resource is expired, the service a accesses the service B according to the request, the service B receives the access of the service a at the 15ms time point, the service B takes 100ms to process the access of the service a, and returns the target resource to the service a at the 115ms time point and then returns to the user 1.
And during the period that the service A accesses the service B and waits for the service B to return the result, the service A receives the request of the request target resource sent by the user 2 at 20ms and receives the request of the request target resource sent by the user 3 at 30ms respectively, the service A does not need to wait for the target resource returned by the service B at the moment, and the expired target resource inquired in the cache of the service A is returned to the user 2 and the user 3, so that the request blockage is avoided, and the response efficiency to the request of the user 2 and the request of the user 3 is improved.
In some embodiments, based on the request response method provided by the foregoing embodiments, the embodiment of the present application further provides a request response device, as shown in fig. 13, fig. 13 provides a schematic diagram of the request response device provided by the embodiment of the present application, where the request response device 300 includes:
the query module 310 is configured to query a cache of the first service for a target resource if the first service receives a target resource request for requesting the target resource within a first period of time.
And the execution module 320 is configured to send the target resource in the cache to the initiator of the target resource request if the target resource is queried in the cache and it is determined that the target resource request is not the resource request for the first request for the target resource after the target resource in the cache expires.
And sending a data request to a second service providing the target resource if the target resource is queried in the cache and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires.
And the receiving module 330 is configured to receive a target resource returned by the second service in response to the data request.
And the output module 340 is configured to return the target resource returned by the second service to the initiator of the target resource request, and update the validity period of the target resource in the cache.
In some embodiments, the execution module 320 includes a locking unit and a sending unit, where the locking unit is configured to lock the target resource request if the target resource is queried in the cache and it is determined that the target resource request is a resource request that first requests the target resource after the target resource in the cache expires; the sending unit is used for responding to the successful locking of the target resource request and sending a data request to a second service providing the target resource; the output module 340 further includes an unlocking unit, where the unlocking unit is configured to unlock the locked target resource request.
In some embodiments, the execution module 320 is further configured to send a data request to the second service if the target resource is not queried in the cache; the output module 340 is further configured to set a validity period for the target resource and store the target resource returned by the second service in the cache.
In some embodiments, the resources in the cache are stored in the form of key value pairs, and the request response device 300 further includes a cache management module, where the cache management module is configured to release a key occupied by a reference resource in the cache and delete the reference resource in the cache if the key in the cache reaches a key capacity threshold of the cache; creating a new key in the cache based on the resource identification of the target resource; the output module 340 is further configured to take the validity period set for the target resource and the target resource as the value of the new key, and store the new key in the cache.
In some embodiments, the cache management module is further configured to determine a frequency of use parameter of each resource in the cache during the first period of time; and taking the resource with the minimum frequency of use parameter in the cache as a reference resource.
In some embodiments, the execution module 320 is further configured to send the target resource queried from the cache to the initiator of the target resource request if the target resource is queried in the cache and the target resource in the cache is determined to be within the validity period.
In some embodiments, the request response device 300 further includes a policy validation module, where the policy validation module is configured to determine, if the first service receives the target resource request for requesting the target resource, to provide the second service of the target resource; if the resource updating frequency of the second service is smaller than the updating frequency threshold value, searching a target resource in the cache of the first service; and if the resource updating frequency of the second service is not less than the updating frequency threshold, sending a data request to the second service so that the second service returns the target resource obtained by query in response to the data request.
Referring to fig. 14, based on the request response method provided by the foregoing embodiment, another electronic device including a processor capable of executing the foregoing method is provided in this embodiment, where the electronic device may be a terminal device, and the terminal device may be a device such as a smart phone, a tablet computer, a computer, or a portable computer. The application also provides an electronic device, the electronic device comprising: one or more processors; a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs configured for use in the request response methods provided herein.
Fig. 14 shows a schematic diagram of a computer system suitable for use in implementing embodiments of the present application. The electronic device may be a terminal as above, for implementing the request response method provided in the present application. It should be noted that, the computer system 1400 of the electronic device shown in fig. 14 is only an example, and should not impose any limitation on the functions and the application scope of the embodiments of the present application.
As shown in fig. 14, the computer system 1400 includes a central processing unit (Central Processing Unit, CPU) 1401, which can perform various appropriate actions and processes, such as performing the methods in the above-described embodiments, according to a program stored in a Read-Only Memory (ROM) 1402 or a program loaded from a storage section 1408 into a random access Memory (Random Access Memory, RAM) 1403. In the RAM 1403, various programs and data required for system operation are also stored. The CPU1401, ROM1402, and RAM 1403 are connected to each other through a bus 1404. An Input/Output (I/O) interface 1405 is also connected to bus 1404.
The following components are connected to the I/O interface 1405: an input section 1406 including a keyboard, a mouse, a microphone, and the like; an output portion 1407 including a Cathode Ray Tube (CRT), a liquid crystal display (Liquid Crystal Display, LCD), and a speaker; a storage section 1408 including a hard disk or the like; and a communication section 1409 including a network interface card such as a LAN (Local Area Network ) card, a modem, or the like. The communication section 1409 performs communication processing via a network such as the internet. The drive 1410 is also connected to the I/O interface 1405 as needed. Removable media 1411, such as magnetic disks, optical disks, magneto-optical disks, semiconductor memory, and the like, is installed as needed on drive 1410 so that a computer program read therefrom is installed as needed into storage portion 1408.
In particular, according to embodiments of the present application, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1409 and/or installed from the removable medium 1411. When executed by a Central Processing Unit (CPU) 1401, performs the various functions defined in the system of the present application.
It should be noted that, the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-Only Memory (ROM), an erasable programmable read-Only Memory (Erasable Programmable Read Only Memory, EPROM), flash Memory, an optical fiber, a portable compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present application, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The foregoing description is not intended to limit the preferred embodiments of the present application, but is not intended to limit the scope of the present application, and any such modifications, equivalents and adaptations of the embodiments described above in accordance with the principles of the present application should and are intended to be within the scope of the present application, as long as they do not depart from the scope of the present application.

Claims (11)

1. A request response method for an electronic device deploying a first service, the method comprising:
if the first service receives a target resource request for requesting a target resource, inquiring the target resource in a cache of the first service;
if the target resource is queried in the cache, and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date, sending the target resource in the cache to an initiator of the target resource request;
If the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource;
receiving a target resource returned by the second service in response to the data request;
and returning the target resource returned by the second service to the initiator of the target resource request, and updating the validity period of the target resource in the cache.
2. The method of claim 1, wherein the sending the data request to the second service providing the target resource if the target resource is queried in the cache and the target resource request is the first resource request to request the target resource after expiration of the target resource in the cache comprises:
if the target resource is queried in the cache and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, locking the target resource request;
responding to the successful locking of the target resource request, and sending a data request to a second service providing the target resource;
After the receiving the target resource returned by the second service in response to the data request, the method further includes:
and unlocking the locked target resource request.
3. The method of claim 1 or 2, wherein after querying the cache of the first service for the target resource, the method further comprises:
if the target resource is not queried in the cache, sending a data request to the second service;
receiving a target resource returned by the second service in response to the data request;
returning the target resource returned by the second service to the initiator of the target resource request;
and setting an effective period for the target resource and storing the target resource returned by the second service into the cache.
4. A method according to claim 3, wherein the resources in the cache are stored in the form of key-value pairs;
before the validity period is set for the target resource and the target resource returned by the second service is stored in the cache, the method further includes:
if the key in the cache reaches the key capacity threshold of the cache, releasing the key occupied by the reference resource in the cache, and deleting the reference resource in the cache;
Creating a new key in the cache based on the resource identification of the target resource;
the step of setting the validity period for the target resource and storing the target resource returned by the second service into the cache includes:
and taking the validity period set for the target resource and the target resource as the value of the new key, and storing the value into the cache.
5. The method of claim 4, wherein before releasing the key occupied by the reference resource in the cache and deleting the reference resource in the cache, the method further comprises:
determining a frequency of use parameter of each resource in the cache in a first time period;
and taking the resource with the smallest frequency parameter used in the cache as the reference resource.
6. The method of claim 1, wherein after querying the cache of the first service for the target resource, the method further comprises:
and if the target resource is inquired in the cache and the target resource in the cache is determined to be in the valid period, sending the target resource inquired in the cache to an initiator of the target resource request.
7. The method of claim 1, wherein querying the cache of the first service for the target resource if the first service receives a target resource request for the target resource comprises:
If the first service receives a target resource request for requesting a target resource, determining a second service for providing the target resource;
if the resource updating frequency of the second service is smaller than the updating frequency threshold value, inquiring the target resource in the cache of the first service;
if the first service receives a target resource request for requesting a target resource, after determining to provide the second service of the target resource, the method further includes:
and if the resource updating frequency of the second service is not less than the updating frequency threshold value, sending a data request to the second service so that the second service returns the target resource obtained by query in response to the data request.
8. A request response device, comprising:
the query module is used for querying the target resource in the cache of the first service if the first service receives a target resource request for requesting the target resource;
the execution module is used for sending the target resource in the cache to an initiator of the target resource request if the target resource is inquired in the cache and the target resource request is not the resource request for requesting the target resource for the first time after the target resource in the cache is out of date;
And if the target resource is queried in the cache, and the target resource request is determined to be a resource request for requesting the target resource for the first time after the target resource in the cache expires, sending a data request to a second service for providing the target resource;
the receiving module is used for receiving a target resource returned by the second service in response to the data request;
and the output module is used for returning the target resource returned by the second service to the initiator of the target resource request and updating the validity period of the target resource in the cache.
9. An electronic device, comprising:
a processor;
a memory having stored thereon computer readable instructions which, when executed by the processor, implement the method of any of claims 1-7.
10. A computer-readable storage medium, comprising: a computer readable storage medium stores program code which is callable by a processor to perform the method according to any one of claims 1-7.
11. A computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the method of any of claims 1-7.
CN202311464605.1A 2023-11-06 2023-11-06 Request response method and device and electronic equipment Pending CN117493397A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311464605.1A CN117493397A (en) 2023-11-06 2023-11-06 Request response method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311464605.1A CN117493397A (en) 2023-11-06 2023-11-06 Request response method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN117493397A true CN117493397A (en) 2024-02-02

Family

ID=89679625

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311464605.1A Pending CN117493397A (en) 2023-11-06 2023-11-06 Request response method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN117493397A (en)

Similar Documents

Publication Publication Date Title
CN107943594B (en) Data acquisition method and device
KR101634403B1 (en) Approaches to reducing lock communications in a shared disk database system
CN107026879B (en) Data caching method and background application system
CN112052264B (en) Business data query method and device, electronic equipment and readable storage medium
US20190138633A1 (en) System and method for committing and rolling back database requests
CN113282626A (en) Redis-based data caching method and device, computer equipment and storage medium
CN117130792B (en) Processing method, device, equipment and storage medium for cache object
CN114003395A (en) Auditing data acquisition method, device, equipment and storage medium
CN113342507A (en) Distributed lock service implementation method and device and computer equipment
CN113010535A (en) Cache data updating method, device, equipment and storage medium
CN110554914B (en) Resource lock management method, device, server and storage medium
CN117407159A (en) Memory space management method and device, equipment and storage medium
CN117493397A (en) Request response method and device and electronic equipment
CN112925472A (en) Request processing method and device, electronic equipment and computer storage medium
CN114244887B (en) Channel management method and device and electronic equipment
CN113448976B (en) Data processing method, device, computer equipment and storage medium
CN111259375A (en) Processing method and device for access request applied to operating system of Internet of things
CN111897847A (en) Data reading and writing method, system, device and medium based on multi-level cache
CN110865845A (en) Method for improving interface access efficiency and storage medium
CN115189932B (en) Rights management method, device, electronic equipment and readable storage medium
CN114116732B (en) Transaction processing method and device, storage device and server
CN115951844B (en) File lock management method, equipment and medium of distributed file system
US20230336416A1 (en) Configuration of a server in view of a number of clients connected to the server
CN116319027A (en) Authentication request generation method and device, electronic equipment and readable storage medium
CN116633616A (en) Data access method, system, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication