Data caching method and device, computer equipment and storage medium
By finding and updating the cache timestamp of the target data object in the data cache, combined with the comparison mechanism of cache and expiration time, the problem of slow response speed in traditional technology is solved, and faster page access and lower server pressure is achieved.
Patent Information
- Application Number
- CN202310638967.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2024-12-03
AI Technical Summary
In traditional technology, after the terminal sends a page access request to the server, the response speed is slow and cannot be effectively improved.
Provides a data cache method, by looking for the target data object of the target page in the data cache, obtaining its cache timestamp, comparing the data expiration time with the preset data, if the same, update the data from the remote database, and the cache duration and expiration time Return data when the conditions are met between durations, reducing the number of accesses to the remote database.
It speeds up the response speed of page access requests, reduces the access pressure of remote servers, and improves the utilization rate and response efficiency of data cache.
Smart Images

Figure CN119066279A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a data caching method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] With the development of Internet technology, Internet platforms have become diversified, such as video platforms, news platforms, social platforms, shopping platforms, etc. Internet platforms are used to display corresponding Internet data and improve the convenience of work and life.
[0003] In traditional technology, after a terminal sends an access request for a certain page to a server, the server obtains the Internet data corresponding to a specific data object on the page from a remote database and returns the Internet data to the terminal. However, the response speed of the access request is slow in this way. Summary of the invention
[0004] Based on this, it is necessary to provide a data caching method, apparatus, computer device, computer-readable storage medium and computer program product that can improve the response speed of page access requests in response to the above technical problems.
[0005] In one aspect, the present application provides a data caching method. The method comprises:
[0006] After receiving the access request to the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page;
[0007] Obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0008] When the preset condition is met between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp;
[0009] When the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0010] In a second aspect, the present application also provides a data cache device. The device includes:
[0011] A search module, configured to search the data cache for target cache data corresponding to the target data object on the target page after receiving an access request to the target page sent by the terminal;
[0012] A determination module, used to obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0013] A comparison module, used to return the target cache data to the terminal when the cache duration and the preset data expiration duration meet the preset conditions, query the current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp;
[0014] The update module is used to use the update timestamp as the current cache timestamp corresponding to the target data object when the target cache timestamp and the current cache timestamp are consistent, and obtain the update data corresponding to the target data object from the remote database, replace the target cache data in the data cache with the update data; and use the update timestamp as the target cache timestamp corresponding to the update data.
[0015] In some embodiments, the preset data expiration period includes: a first preset period and a second preset period, the first preset period is greater than the second preset period; a comparison module is specifically used to: compare the cache period with the first preset period and the second preset period, respectively, and when the cache period is greater than or equal to the second preset period, and the cache period is less than the first preset period, determine that the cache period and the preset data expiration period meet the preset condition.
[0016] In some embodiments, the comparison module is also used to obtain updated data corresponding to the target data object from the remote database when the cache duration is greater than or equal to the first preset duration, return the updated data to the terminal, and replace the target cache data in the data cache with the updated data.
[0017] In some embodiments, the comparison module is further configured to return the target cache data to the terminal when the cache duration is less than a second preset duration.
[0018] In some embodiments, the above-mentioned data caching device also includes a cleaning module, which is used to detect the cache length of the pending cache data corresponding to each pending data object in the data cache, and when the detection result indicates that the cache length of the corresponding pending cache data reaches a first preset length, the corresponding pending cache data is cleared.
[0019] In some embodiments, the cleaning module is specifically used to obtain a first data object corresponding to corresponding cached data to be processed; select a target expiration queue from an expiration queue pool according to preset rules, and store the first data object in the target expiration queue; when the target expiration queue is full, deliver each data object in the target expiration queue to a data communication component through the target expiration queue; deliver each data object in the target expiration queue to a data clearing coroutine through the data communication component, and clear the cached data to be processed corresponding to each data object in the target expiration queue through the data clearing coroutine.
[0020] In some embodiments, a cleaning module is specifically used to start a timer corresponding to the current data object to be processed, starting from the cache timestamp corresponding to the current data object to be processed, for each data object to be processed in the data cache, and the timing duration of the timer is a first preset duration; when the timer stops, it is determined that the cache duration of the current data object to be processed has reached the first preset duration.
[0021] In some embodiments, the above-mentioned data caching device also includes a linked list update module, which is used to obtain the linked list timestamp corresponding to the target data object, the linked list timestamp is the timestamp of the last update of the usage record linked list for the target data object; obtain the linked list cooling time interval between the linked list timestamp and the current timestamp; when the linked list cooling time is greater than or equal to the preset interval threshold, the linked list timestamp is updated by calling a preset function, and the target data object is moved to the head of the usage record linked list.
[0022] In some embodiments, the above-mentioned data cache device also includes an acquisition module, which is used to perform an encryption operation on the target data object to obtain an encryption operation result when the target cache data corresponding to the target data object does not exist in the data cache; determine the global lock object to which the target data object belongs according to the encryption operation result; the global lock object is used to lock the target memory; the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object; based on the global lock object, determine the data lock object corresponding to the target data object; obtain the target data corresponding to the target data object from the remote database through the data lock object, and store the target data in the data cache.
[0023] In some embodiments, an acquisition module is specifically used to update the global lock object to a locked state, and search the target memory corresponding to the global lock object for a data lock object corresponding to the target data object; if it does not exist, create a data lock object corresponding to the target data object, and store the data lock object corresponding to the target data object in the target memory; if it exists, use the found data lock object as the data lock object corresponding to the target data object; and update the global lock object to a released state.
[0024] In some embodiments, the acquisition module is specifically used to update the data lock object corresponding to the target data object to a locked state; when it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, obtain the target data corresponding to the target data object from a remote database and store the target data in the data cache; and update the data lock object corresponding to the target data object to a released state.
[0025] In some embodiments, the acquisition module is further used to update the global lock object to a locked state, delete the data lock object corresponding to the target data object from the target memory; and update the global lock object to a released state.
[0026] In some embodiments, the search module is specifically used to start multiple work threads corresponding to the multiple terminals after receiving access requests to the target page sent by multiple terminals respectively; for each access request to the target page sent by each terminal, search the target cache data corresponding to the target data object on the target page in the data cache through the corresponding work thread;
[0027] The determination module is specifically used to: for each access request to the target page sent by each terminal, obtain the target cache timestamp corresponding to the target cache data through the corresponding working thread, and determine the cache duration of the target cache data based on the target cache timestamp;
[0028] The comparison module is specifically used for: for each access request to the target page sent by each terminal, when the corresponding working thread determines that the cache duration and the preset data expiration duration meet the preset conditions, returning the target cache data to the terminal through the corresponding working thread, querying the current cache timestamp corresponding to the target data object, and comparing the target cache timestamp with the current cache timestamp;
[0029] The update module is specifically used for: the comparison result obtained by the target working thread that first executes the query operation among multiple working threads is consistent, the target working thread obtains the corresponding update data of the target data object from the remote database, and replaces the target cache data in the data cache with the updated data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0030] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0031] After receiving the access request to the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page;
[0032] Obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0033] When the preset condition is met between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp;
[0034] When the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0036] After receiving the access request to the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page;
[0037] Obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0038] When the preset condition is met between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp;
[0039] When the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0040] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0041] After receiving the access request to the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page;
[0042] Obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0043] When the preset condition is met between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp;
[0044] When the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0045] The above-mentioned data caching method, apparatus, computer equipment, storage medium and computer program product, after receiving an access request for a target page sent by a terminal, searches for target cache data corresponding to a target data object on the target page in the data cache; obtains a target cache timestamp corresponding to the target cache data, and determines the cache duration of the target cache data based on the target cache timestamp; when a preset condition is satisfied between the cache duration and a preset data expiration duration, on the one hand, returns the target cache data to the terminal; on the other hand, queries the current cache timestamp corresponding to the target data object, and compares the target cache timestamp with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, uses the updated timestamp as the current cache timestamp corresponding to the target data object, and obtains the target data from the remote database The target cache data in the data cache is replaced with the updated data according to the updated data corresponding to the object; the above method of returning the target cache data currently cached in the data cache to the terminal and triggering the cache update at the same time realizes the asynchronous update of the cache data, and compared with the method of obtaining the updated data from the remote database immediately after receiving the access request and then returning it to the terminal, it speeds up the response speed of the access request. Moreover, considering the concurrent access requests, there will be a problem of obtaining the updated data from the remote database once for each access request. The above embodiment proposes a timestamp comparison scheme. Only the access request with a consistent timestamp comparison result will obtain the updated data from the remote database, which avoids the execution of unnecessary acquisition process, reduces the number of accesses to the remote database, and reduces the access pressure of the remote server. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 An application environment diagram of a data caching method in an embodiment;
[0047] Figure 2 A schematic diagram of a flow chart of a data caching method in an embodiment;
[0048] Figure 3 A schematic diagram of a process for asynchronously acquiring update data in one embodiment;
[0049] Figure 4 A schematic diagram of a flow chart of clearing cache data to be processed in one embodiment;
[0050] Figure 5 A schematic diagram of centrally deleting cached data of expired data objects in one embodiment;
[0051] Figure 6 A schematic diagram of a process for updating a linked list timestamp in one embodiment;
[0052] Figure 7 A schematic diagram of a process for obtaining target data in one embodiment;
[0053] Figure 8 A schematic diagram of a process for obtaining target data in another embodiment;
[0054] Fig. 9 is a structural block diagram of a data cache device in one embodiment;
[0055] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] The data caching method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Figure 1 The application environment shown includes a terminal 102, a server 104 and a remote database 106, and the terminal 102 communicates with the server 104 through a network. After receiving the access request for the target page sent by the terminal 102, the server 104 searches for the target cache data corresponding to the target data object on the target page in the data cache; obtains the target cache timestamp corresponding to the target cache data, and determines the cache duration of the target cache data based on the target cache timestamp; when the cache duration and the preset data expiration duration meet the preset conditions, returns the target cache data to the terminal 102, queries the current cache timestamp corresponding to the target data object, and compares the target cache timestamp with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, uses the update timestamp as the current cache timestamp corresponding to the target data object, obtains the update data corresponding to the target data object from the remote database 106, and replaces the target cache data in the data cache with the update data; uses the update timestamp as the target cache timestamp corresponding to the update data.
[0058] The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0059] In some embodiments, Figure 2 As shown, a data caching method is provided, which is applied to Figure 1 The server in the example is used to illustrate the following steps:
[0060] Step 202: after receiving the access request for the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page.
[0061] Among them, an application is installed on the terminal, and the application may be a game application, a social application, a news application, etc., which is not limited in the embodiment of the present application.
[0062] The application is provided with at least one application page, and the target page can be a page specified by the application developer in at least one application page. The target page includes at least one module for displaying data, and the target data object can be a module specified by the application developer in at least one module for displaying data. The module for displaying data includes at least one content display control, and the target data object can also be a control specified by the application developer in at least one content display control. The target data object can be one or more than one, and this is not limited in the embodiments of the present application.
[0063] In a specific implementation, the application may be a news application, and the target page may be the home page of the application. For example, the home page includes a home page top module, and the target data object may be the home page top module; or, the home page top module includes at least one news title display control, and the application developer may specify each news title display control as the target data object. Each news title display control is used to display the news titles of different top news.
[0064] In a specific implementation, the application may be a game application, the target page may be a page containing an advertisement slot provided by the application, and the target data object may be an advertisement slot on the page.
[0065] In a specific implementation, the application may be a social application, similar to a game application, the target page may be a page provided by the application and containing an advertisement slot, and the target data object may be an advertisement slot on the page.
[0066] Among them, the object can trigger an access operation to the target page on the terminal. After the terminal detects the access operation, it can generate an access request to the target page and send the access request to the server. In a specific implementation, as described above, the target page can be a page specified by the application developer in at least one application page. In this case, the object can trigger an access operation to the target page through the corresponding application.
[0067] Among them, after receiving the access request for the target page sent by the terminal, the server searches the data cache for the target cache data corresponding to the target data object on the target page. If it can be found, it continues to execute step 204. If it cannot be found, it obtains the target data corresponding to the target data object from the remote database. For the specific acquisition process, please refer to the description in the embodiments below. After the server obtains the target data from the remote database, it returns the target data to the terminal.
[0068] Among them, the data cache caches cache data corresponding to each of the multiple data objects. In the embodiment of the present application, each data object in the data cache is also called a data object to be processed, and the cache data corresponding to each data object is also called cache data to be processed.
[0069] In a specific implementation, the server may match the target data object with each data object to be processed in the data cache. If there is a successfully matched data object to be processed in the data cache, it means that the target cache data corresponding to the target data object can be found in the data cache, and the pending cache data corresponding to the successfully matched data object to be processed in the data cache is used as the target cache data corresponding to the target data object.
[0070] Exemplarily, the data cache caches cache data corresponding to three data objects, which are key1, key2 and key3 respectively. Assuming that the target data object on the target page is key4, after matching, the three data objects in the data cache all fail to match, indicating that the target cache data corresponding to the target data object cannot be found in the data cache. In this case, the target data corresponding to the target data object is obtained from the remote database and the target data is returned to the terminal.
[0071] Step 204: Obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp.
[0072] The target cache timestamp is an update timestamp used when updating the current cache timestamp corresponding to the target data object before acquiring the target cache data from the remote database.
[0073] In a specific implementation, for each pending data object in the data cache, each time the server determines that it needs to obtain corresponding updated data from a remote database, it first uses the updated timestamp to update the current cache timestamp corresponding to the pending data object, then obtains the corresponding updated data from the remote database, and uses the updated data to replace the original data corresponding to the pending data object in the data cache, thereby implementing the data update of the pending data object in the data cache, and the updated timestamp can be used as the target cache timestamp corresponding to the updated data. The updated timestamp can be the timestamp corresponding to the moment when the server determines that it needs to obtain the corresponding updated data from the remote database.
[0074] In a specific implementation, when the server updates the current cache timestamp corresponding to the data object to be processed, it can use the timestamp corresponding to the moment when the corresponding update data needs to be obtained from the remote database to replace the current cache timestamp corresponding to the data object to be processed, so as to update the current cache timestamp.
[0075] Exemplarily, for a certain data object to be processed (key3) in the data cache, the server determines through judgment that the updated data corresponding to key3 needs to be obtained from the remote database. Assuming that the current cache timestamp corresponding to key3 is timestamp A, and the timestamp corresponding to the moment when the updated data corresponding to key3 needs to be obtained from the remote database is timestamp B, the current cache timestamp corresponding to key3 is updated from timestamp A to timestamp B, and then the updated data corresponding to key3 is obtained from the remote database, and the updated data is used to replace the original data corresponding to key3 in the data cache. Then the target cache time corresponding to the updated data is timestamp B.
[0076] Among them, each time the server updates the current cache timestamp corresponding to the data object to be processed, the corresponding update timestamp will be recorded. The server can query the target cache timestamp corresponding to the target cache data from the record, and then convert the target cache timestamp into a moment, and determine the cache duration of the target cache data based on the moment and the moment when the target cache data is queried.
[0077] In a specific implementation, after converting the target cache timestamp into a moment, the server can calculate the duration between the moment and the moment when the target cache data is queried, and use the duration as the cache duration of the target cache data.
[0078] Step 206, when the cache duration and the preset data expiration duration meet the preset condition, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp.
[0079] Among them, the preset data expiration period may include a preset period. The server compares the cache period with the preset period. When the cache period is greater than or equal to the preset period, it is determined that the cache period and the preset data expiration period meet the preset condition.
[0080] Alternatively, the preset data expiration period may include a first preset period and a second preset period, the first preset period being greater than the second preset period, and the server may compare the cache period with the first preset period and the second preset period, respectively, and when the cache period is greater than or equal to the second preset period and the cache period is less than the first preset period, it is determined that the cache period and the preset data expiration period satisfy a preset condition.
[0081] Among them, when the server determines that the cache period and the preset data expiration period meet the preset conditions, it returns the target cache data to the terminal. The target cache data may include the object title and the object content. After the terminal receives the target cache data, it displays the object title in the area corresponding to the target data object on the target page. When the object clicks the object title, the terminal displays the object content.
[0082] Exemplarily, the application is a news application, the target page is the homepage of the application, the target data object is the homepage top module on the homepage, the object title is the news title, and the object content is the news content. After receiving the target cache data returned by the server, the terminal can display the news title in the area corresponding to the homepage top module. When the object clicks the news title, the terminal displays the news content.
[0083] Among them, the target cache data can include news titles and news contents corresponding to multiple news respectively. The news titles corresponding to each news can be displayed in the corresponding area of the top module on the homepage. The object can click on the news title of interest according to his own needs.
[0084] Exemplarily, the application is a game application, the target page is a page provided by the application that includes an ad slot, the target data object is the ad slot on the page, the object title is the ad title, and the object content is the ad content. After receiving the target cache data returned by the server, the terminal can display the ad title in the area corresponding to the ad slot. When the object clicks on the ad title, the terminal displays the ad content.
[0085] Among them, the current cache timestamp corresponding to the target data object is the most recent timestamp update result. For example, the target data object is key4. When it is determined for the first time that the updated data corresponding to key4 needs to be obtained from the remote database, the current cache timestamp corresponding to key4 is updated to timestamp A. When it is determined for the second time that the updated data corresponding to key4 needs to be obtained from the remote database, the current cache timestamp corresponding to key4 is updated to timestamp B. It is not updated thereafter. When the server receives the access request for the target page sent by the terminal, it queries the current cache timestamp corresponding to key4, and it can be obtained that the current cache timestamp corresponding to key4 is timestamp B.
[0086] As described above, for each to-be-processed data object in the data cache, each time after the current cache timestamp corresponding to the to-be-processed data object is updated using the update timestamp, the server will record the corresponding update timestamp.
[0087] Among them, the following steps can be completed by calling a preset function: query the current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, the server determines that it is necessary to obtain the updated data corresponding to the target data object from the remote database, and then uses the updated timestamp as the current cache timestamp corresponding to the target data object; when the target cache timestamp and the current cache timestamp are inconsistent, the process ends.
[0088] The preset function may be a function with atomic operation characteristics, which can only be called by one working thread at a time, and can only be called by other working threads after the function is executed. Exemplarily, the preset function may be a Compare And Swap (CAS) function.
[0089] Among them, as the application becomes more and more widespread, the number of objects using the application is very large, and it may happen that the server receives access requests to the target page sent by multiple terminals at the same time. At this time, the server can start multiple working threads corresponding to the multiple terminals one by one, and each working thread processes the access requests to the target page sent by the corresponding terminal. Each working thread will perform the following operations: for the access request sent by the terminal corresponding to the working thread, the working thread can search the target cache data corresponding to the target data object on the target page in the data cache; obtain the target cache timestamp corresponding to the target cache data, and determine the cache time of the target cache data based on the target cache timestamp; when the preset condition is met between the cache time and the preset data expiration time, return the target cache data to the terminal and call the preset function. In the case where the target cache timestamps obtained by the above-mentioned working threads are the same, there may be a problem that multiple working threads obtain the corresponding updated data of the target data object from the remote database. Since the updated data obtained are the same, only one of the working threads needs to obtain it from the remote database, and the redundant acquisition process will cause excessive pressure on the remote database access. In order to achieve that only one working process obtains updated data from a remote database, the embodiment of the present application proposes the application of the above-mentioned preset function. Since the processing performance of the above-mentioned multiple working threads is different, the speed of executing the above-mentioned steps is also different. Only the working thread that first calls the preset function will obtain a consistent result when comparing the target cache timestamp with the current cache timestamp, and then the working process can further update the current cache timestamp corresponding to the target data object. When other working threads call the preset function, since the current cache timestamp has been updated, when comparing the target cache timestamp with the current cache timestamp, inconsistent results will be obtained. At this time, the process can be directly terminated, so that only one working process executes the step of obtaining updated data, reducing the access pressure of the remote database.
[0090] Here are some examples:
[0091] Assume that the server receives access requests for the target page sent by three terminals, which are terminal 1, terminal 2 and terminal 3 respectively. The server can start three working threads to process the three received access requests respectively. The three working threads are working thread 1, working thread 2 and working thread 3 respectively. Assume that working thread 1 processes the access request sent by terminal 1, working thread 2 processes the access request sent by terminal 2, and working thread 3 processes the access request sent by terminal 3. In response to the access request sent by terminal 1, working thread 1 searches the data cache for the target cache data corresponding to the target data object on the target page; obtains the target cache timestamp corresponding to the target cache data, assuming that the obtained target cache timestamp is timestamp A, and determines the cache duration of the target cache data based on the target cache timestamp; when the preset condition is met between the cache duration and the preset data expiration duration, returns the target cache data to the terminal and calls the preset function. Worker thread 2 and worker thread 3 perform the same processing and obtain the same target cache timestamp. Since the processing performance of the three worker threads is different, it is assumed that the processing performance of worker thread 2 is the best. Worker thread 2 first calls the preset function. During the execution of the preset function, the current cache timestamp corresponding to the target data object is queried first. Since the target cache data is the current cache data corresponding to the target data object in the data cache, the current cache timestamp corresponding to the target data object is the target cache timestamp corresponding to the target cache data. Therefore, when the target cache timestamp and the current cache timestamp are compared, it is found that the two are consistent. At this time, the current cache timestamp corresponding to the target data object can be updated, that is, the updated timestamp is used as the current cache timestamp corresponding to the target data object. At this point, the preset function is executed. When worker thread 1 and worker thread 3 call the preset function later, during the execution of the preset function, since the current cache timestamp corresponding to the target data object has been updated, when the target cache timestamp and the current cache timestamp are compared, it is found that the two are inconsistent, and the process is directly terminated.
[0092] Step 208, when the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0093] Among them, when the server determines that the target cache timestamp and the current cache timestamp are consistent, it determines that it needs to obtain the updated data corresponding to the target data object from the remote database, and can use the corresponding timestamp at this moment as the update timestamp, and use the update timestamp as the current cache timestamp corresponding to the target data object.
[0094] After updating the current cache timestamp corresponding to the target data object, the server can obtain the updated data corresponding to the target data object from the remote database, and replace the target cache data in the data cache with the updated data. The above updated timestamp can be used as the target cache timestamp corresponding to the updated data. The next time the server receives an access request to the target page, the updated data is the target cache data corresponding to the target data object on the target page.
[0095] In the above embodiment, after receiving an access request to a target page sent by a terminal, the target cache data corresponding to the target data object on the target page is searched in the data cache; the target cache timestamp corresponding to the target cache data is obtained, and the cache duration of the target cache data is determined based on the target cache timestamp; when a preset condition is met between the cache duration and the preset data expiration duration, on the one hand, the target cache data is returned to the terminal; on the other hand, the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the updated data corresponding to the target data object is obtained from the remote database, and the data is The target cache data in the cache is replaced with the updated data; the above method of returning the target cache data currently cached in the data cache to the terminal and triggering the cache update at the same time realizes the asynchronous update of the cache data. Compared with the method of obtaining the updated data from the remote database immediately after receiving the access request and then returning it to the terminal, the response speed of the access request is accelerated. Moreover, considering the concurrent access requests, there will be a problem of obtaining the updated data from the remote database once for each access request. The above embodiment proposes a timestamp comparison scheme. Only the access request with a consistent timestamp comparison result will obtain the updated data from the remote database, avoiding the execution of unnecessary acquisition process, reducing the number of accesses to the remote database, and reducing the access pressure of the remote server.
[0096] In some embodiments, the preset data expiration period includes: a first preset period and a second preset period, and the first preset period is greater than the second preset period; the method also includes: comparing the cache period with the first preset period and the second preset period, respectively, and when the cache period is greater than or equal to the second preset period and the cache period is less than the first preset period, determining that the cache period and the preset data expiration period meet a preset condition.
[0097] Among them, after determining the cache duration of the target cache data, the server compares the cache duration with a first preset duration. When the cache duration is less than the first preset duration, the cache duration is compared with a second preset duration. When the cache duration is greater than or equal to the second preset duration, it is determined that the cache duration and the preset data expiration duration meet the preset condition. At this time, on the one hand, the server can return the target cache data to the terminal, and on the other hand, it can query the current cache timestamp corresponding to the target data object by calling a preset function, and compare the target cache timestamp with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the corresponding update data of the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the updated data, thereby realizing asynchronous update of the cache data, and the above-mentioned update timestamp can be used as the target cache timestamp corresponding to the updated data.
[0098] When the target cache timestamp is inconsistent with the current cache timestamp, it indicates that the operation of obtaining updated data from the remote database has been executed for other concurrent access requests. At this time, the process is terminated directly, thereby achieving the purpose of executing the acquisition process only for one access request, avoiding the execution of unnecessary acquisition processes, reducing the number of accesses to the remote database, and reducing the access pressure on the remote server.
[0099] In the above embodiment, when the cache duration of the target cache data is greater than or equal to the second preset duration and less than the first preset duration, while returning the target cache data to the terminal, an asynchronous update of the cache data is triggered, which speeds up the response speed of the access request compared to the method of synchronously waiting for the update data obtained from the remote database and returning the update data to the terminal.
[0100] In some embodiments, the data caching method provided by the embodiments of the present application further includes: when the cache duration is greater than or equal to the first preset duration, obtaining updated data corresponding to the target data object from a remote database, returning the updated data to the terminal, and replacing the target cache data in the data cache with the updated data.
[0101] Among them, after determining the cache length of the target cache data, the server compares the cache length with the first preset length. When the cache length is greater than or equal to the first preset length, it means that the target cache data has been cached in the data cache for a long time. At this time, the server no longer returns the currently cached target cache data to the terminal, but obtains the updated data corresponding to the target data object from the remote database, returns the updated data to the terminal, and replaces the target cache data in the data cache with the updated data.
[0102] Among them, when the server simultaneously receives access requests for the target page sent by multiple terminals, when processing each access request separately, it may be concluded that the cache duration is greater than or equal to the first preset duration. In order to obtain updated data from the remote database only for one of the access requests, instead of obtaining data from the remote database once for all access requests, the server can use global lock objects and data lock objects to achieve mutual exclusion between the access requests, so that in the case of concurrent access requests, only one operation of obtaining updated data from the remote database needs to be executed, thereby reducing the number of accesses to the remote database and reducing the access pressure on the remote database.
[0103] In the above embodiment, when the cache time length is greater than or equal to the first preset time length, updated data corresponding to the target data object is obtained from the remote database, and the updated data is returned to the terminal, so that the terminal receives not the stale data that has been cached for a long time, but the updated data synchronously obtained from the remote database, thereby improving the timeliness of the data seen by the object.
[0104] In some embodiments, the data caching method provided by the embodiments of the present application further includes: when the cache duration is less than a second preset duration, returning the target cache data to the terminal.
[0105] Among them, after determining the cache length of the target cache data, the server compares the cache length with the first preset length. When the cache length is less than the first preset length, the cache length is compared with the second preset length. When the cache length is less than the second preset length, it means that the target cache data has been cached in the data cache for a very short time, that is, the target cache data is relatively fresh data. At this time, the server can directly return the target cache data to the terminal, which speeds up the response speed of the access request compared to the method of synchronously waiting for the updated data obtained from the remote database and returning the updated data to the terminal.
[0106] See also Figure 3As shown, after receiving the access request for the target page sent by the terminal, the server searches the target cache data corresponding to the target data object in the data cache. If the target data object can be found, the cache duration is compared with the first preset duration. If the target data object is less than the first preset duration, the cache duration is further compared with the second preset duration. If the target data object is greater than or equal to the second preset duration, the target cache data is directly returned to the terminal on the one hand, and the current cache timestamp corresponding to the target data object is updated by calling a preset function on the other hand. If the update is successful, that is, the timestamp comparison result is consistent, the target data object corresponding to the updated data is obtained from the remote database, and the target cache data in the data cache is replaced with the updated data. If the target cache data corresponding to the target data object cannot be found, or if the cache duration is greater than or equal to the first preset duration, the target data object corresponding to the updated data is obtained from the remote database in a synchronous mode and put into the cache, and the updated data is returned to the terminal. If the cache duration is less than the second preset duration, the target cache data is directly returned to the terminal.
[0107] In the above embodiment, when the cache duration is less than the first preset duration, the target cache data is considered to be relatively fresh data, and the target cache data is directly returned to the terminal, which greatly improves the response speed of the access request.
[0108] In some embodiments, the data caching method provided by the embodiments of the present application further includes: respectively detecting the cache duration of the cache data to be processed corresponding to each data object to be processed in the data cache, and when the detection result indicates that the cache duration of the corresponding cache data to be processed reaches a first preset duration, clearing the corresponding cache data to be processed.
[0109] Among them, the data cache caches cache data corresponding to each of the multiple data objects. In the embodiment of the present application, each data object in the data cache is also called a data object to be processed, and the cache data corresponding to each data object is also called cache data to be processed.
[0110] For each pending data object in the data cache, each time the server determines that it needs to obtain the corresponding updated data from the remote database, it first uses the updated timestamp to update the current cache timestamp corresponding to the pending data object, then obtains the corresponding updated data from the remote database, and uses the updated data to replace the original data corresponding to the pending data object in the data cache, thereby realizing the data update of the pending data object in the data cache, and the updated timestamp is the target cache timestamp corresponding to the updated data. The updated timestamp can be the timestamp corresponding to the moment when the server determines that it needs to obtain the corresponding updated data from the remote database.
[0111] Among them, when the server uses the update timestamp to update the current cache timestamp corresponding to the data object to be processed, it can start real-time detection of the cache length of the cache data to be processed corresponding to the data object to be processed. When the detection result indicates that the cache length of the cache data to be processed reaches the first preset time length, it means that the cache length of the cache data to be processed in the data cache has reached the time length that should be cleared, that is, the data object to be processed corresponding to the cache data to be processed is an expired data object, and the cache data to be processed is cleared.
[0112] In the above embodiment, the cache duration of the cache data to be processed corresponding to each data object to be processed in the data cache is detected respectively. When the detection result indicates that the cache duration of the corresponding cache data to be processed reaches the first preset duration, the corresponding cache data to be processed is cleared, thereby realizing timely clearing of expired data and improving the utilization rate of the data cache.
[0113] In some embodiments, see Figure 4 As shown, the corresponding cache data to be processed is cleared, including:
[0114] Step 402: Obtain a first data object corresponding to the corresponding cache data to be processed.
[0115] Step 404: select a target expiration queue from the expiration queue pool according to a preset rule, and store the first data object in the target expiration queue.
[0116] Among them, the server can obtain the first data object corresponding to the corresponding cache data to be processed. Specifically, the cache data to be processed corresponding to different data objects to be processed in the data cache are stored in different locations. Based on the location where the above cache data to be processed is stored, the first data object corresponding to the above cache data to be processed can be determined, and the target expiration queue can be selected from the expiration queue pool according to preset rules, and the first data object can be stored in the target expiration queue.
[0117] The expired queue pool includes multiple expired queues, and the expired queues are used to store expired data objects. The multiple expired queues have a fixed polling order, and the expired queue last accessed can be obtained. Based on the polling order and the expired queue last accessed, the next expired queue of the expired queue last accessed is determined, and the expired queue is used as the target expired queue. Alternatively, the server can determine the expired queue with the least number of stored data objects among the multiple expired queues, and use the expired queue as the target expired queue.
[0118] Step 406, when the target expiration queue is full, each data object in the target expiration queue is delivered to the data communication component through the target expiration queue; each data object in the target expiration queue is delivered to the data clearing coroutine through the data communication component, and the to-be-processed cache data corresponding to each data object in the target expiration queue is cleared through the data clearing coroutine.
[0119] As expired data objects are continuously put into each expired queue, the expired queue will be full. In this case, the expired queue can deliver each stored data object to the data communication component (Channel). The target expired queue is an expired queue in the expired queue pool. When the target expired queue is full, the target expired queue will deliver each stored data object to the data communication component. Since the first data object is stored in the target expired queue, the first data object is included in each data object delivered by the target expired queue to the data communication component.
[0120] After receiving each data object delivered by the expired queue, the data communication component will deliver each data object to the data clearing coroutine. After receiving each data object delivered by the data communication component, the data clearing coroutine will centrally delete the cached data corresponding to each data object in the data cache. The data objects delivered by the target expired queue to the data communication component include the first data object, and the above-mentioned centralized deletion operation can realize the deletion of the cached data corresponding to the first data object.
[0121] Among them, when the data communication component is full, when the data communication component receives each data object delivered by the expired queue, the data communication component can discard each data object. This practice will cause some cached data whose cache duration has reached the first preset duration to be unable to be deleted. For these cached data, they can be deleted by relying on the use record linked list or relying on the access operation triggered by the object. Exemplarily, the use record chain can be a least recently used (LRU) linked list.
[0122] See also Figure 5As shown, the expired queue pool contains three expired queues, namely queue 1, queue 2 and queue 3. Assuming that the cache duration of the pending cache data 1 in the data cache is determined to reach the first preset duration through the timer corresponding to the pending cache data 1 in the data cache, and queue 3 is determined to be the target expired queue, the pending data object (key) corresponding to the pending cache data 1 is placed in queue 3. When queue 3 is full, queue 3 delivers the object array composed of each data object in queue 3 to the data communication component (Channel), and the data communication component (Channel) further delivers the object array to the data clearing coroutine, which deletes the cache data corresponding to each data object in the object array. For the data objects received again when the data communication component is full and the data objects randomly eliminated from the expired queue pool, they can be deleted by relying on the LRU linked list or by relying on the access operation triggered by the object.
[0123] In the above embodiment, expired data objects are stored in an expiration queue. When the expiration queue is full, each data object in the expiration queue is delivered to the data clearing coroutine through the data communication component, and the data clearing coroutine centrally deletes the cached data corresponding to each received data object. Since the data cache needs to be locked each time the data in the data cache is deleted, and the data cache needs to be unlocked after the deletion is successful, the above-mentioned deletion operations can avoid multiple unlocking and unlocking processes caused by separate deletions, thereby reducing the impact of multiple unlocking and unlocking on the server processing performance.
[0124] In some embodiments, the cache duration of the cache data to be processed corresponding to each data object to be processed in the data cache is detected respectively, including: for the cache data to be processed corresponding to each data object to be processed in the data cache, starting from the cache timestamp corresponding to the current cache data to be processed, starting the timer corresponding to the current data object to be processed, and the timing duration of the timer is a first preset duration; when the timer stops, it is determined that the cache duration of the current cache data to be processed has reached the first preset duration.
[0125] Among them, for the pending cache data corresponding to each pending data object in the data cache, before obtaining the pending cache data from the remote database, the current cache timestamp corresponding to the corresponding pending data object needs to be updated, and the timer corresponding to the corresponding pending data object can be started while updating, so as to achieve the purpose of starting the timer corresponding to the current pending data object from the cache timestamp corresponding to the corresponding pending cache data. When the timer stops, it means that the cache duration of the pending cache data has reached the timing duration of the timer.
[0126] The timing duration of the timer may be a first preset duration. When the timer stops, it may be determined that the cache duration of the cache data to be processed reaches the first preset duration. At this time, the cache data to be processed may be cleared.
[0127] In the above embodiment, a timer is set for each cached data to be processed in the data cache, and the cache duration of the corresponding cached data to be processed is detected by the timer. When the detection result indicates that the cache duration of the corresponding cached data to be processed reaches the first preset duration, the corresponding cached data to be processed is cleared. This realizes the timely clearing of expired data and improves the utilization rate of the data cache.
[0128] In some embodiments, before returning the target cache data to the terminal, the data caching method provided by the embodiments of the present application also includes: obtaining a linked list timestamp corresponding to the target data object, the linked list timestamp being the timestamp of the last update of the usage record linked list for the target data object; obtaining a linked list cooling time interval between the linked list timestamp and the current timestamp; when the linked list cooling time is greater than or equal to a preset interval threshold, updating the linked list timestamp by calling a preset function, and moving the target data object to the head of the usage record linked list.
[0129] Among them, a record linked list is used to record the access situations of cache data corresponding to each data object in the data cache. The access of cache data may include cache data being read, deleted, replaced, etc., which is not limited in the embodiment of the present application.
[0130] When a cached data in the data cache is accessed, the server moves the data object corresponding to the cached data to the head of the queue of the usage record linked list. That is to say, the head of the queue of the usage record linked list always stores the most recently accessed data object.
[0131] When a cached data in the data cache is accessed, on the one hand, the server can move the data object corresponding to the cached data to the head of the queue of the usage record linked list, and on the other hand, the server uses the timestamp corresponding to the current moment as the timestamp of the usage record linked list for the data object corresponding to the cached data, and the server can record the timestamp. Each time each cached data in the data cache is accessed, the server will perform the above operations, so the linked list timestamp corresponding to each cached data will be continuously updated.
[0132] Among them, when the server determines that the cache duration and the preset data expiration duration meet the preset conditions, the server can read the target cache data corresponding to the target data object from the data cache, and obtain the linked list timestamp corresponding to the target data object. As described above, the linked list timestamp is the timestamp of the last update of the linked list using the record for the target data object, and then based on the obtained linked list timestamp and the current timestamp, the time interval between the two timestamps is calculated, and the time interval is used as the linked list cooling time.
[0133] Among them, after obtaining the linked list cooling time, the server can compare the linked list cooling time with the preset interval threshold. When the linked list cooling time is greater than or equal to the preset interval threshold, considering the concurrency of access requests, there may be a linked list timestamp update operation for multiple access requests. The embodiment of the present application proposes to update the linked list timestamp by calling a preset function and move the target data object to the head of the queue of the usage record linked list.
[0134] The preset function may be a function with atomic operation characteristics. Exemplarily, the preset function may be a compare and swap (CAS) function.
[0135] See also Figure 6 As shown, after receiving the access request for the target page sent by the terminal, the server searches the data cache for the target cache data corresponding to the target data object, and obtains the linked list timestamp corresponding to the target data object if it can be found, obtains the linked list cooling time between the linked list timestamp and the current timestamp, and determines whether the linked list cooling time is greater than or equal to the preset interval threshold. If the judgment result is yes, the CAS function is called to update the linked list timestamp. If the update is successful, the target data object is moved to the head of the queue of the usage record linked list. If the update fails or the linked list cooling time is less than the preset interval threshold, the process ends.
[0136] Among them, the number of data objects that can be stored in the usage record linked list is certain. When a new data object is inserted into the head of the usage record linked list, the data object at the tail of the usage record linked list is automatically deleted, and accordingly, the cache data corresponding to the deleted data object is also deleted.
[0137] In the above embodiment, before returning the target cache data to the terminal, the linked list timestamp corresponding to the target data object can be obtained first, and the linked list cooling time length based on the interval between the linked list timestamp and the current timestamp; when the linked list cooling time length is greater than or equal to the preset interval threshold, the linked list timestamp is updated by calling a preset function, and the target data object is moved to the head of the usage record linked list. The above linked list cooling time judgment mechanism ensures that not every access operation will trigger the update of the usage record linked list, because each time the update of the usage record linked list is triggered, the usage record linked list needs to be locked first, and after the update is completed, the usage record linked list is unlocked. The above judgment mechanism can reduce the number of times the usage record linked list is locked, thereby reducing the impact of multiple locking and unlocking on the server processing performance.
[0138] In some embodiments, see Figure 7 As shown, the data caching method provided in the embodiment of the present application further includes:
[0139] Step 702: When there is no target cache data corresponding to the target data object in the data cache, an encryption operation is performed on the target data object to obtain an encryption operation result.
[0140] Among them, after receiving the access request for the target page sent by the terminal, the server searches the data cache for the target cache data corresponding to the target data object on the target page. If the target data cannot be found, the server can obtain the target data corresponding to the target data object from the remote database through the method provided in the embodiment of the present application, and return the target data to the terminal.
[0141] Step 704, determine the global lock object to which the target data object belongs according to the encryption operation result; the global lock object is used to lock the target memory; the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object.
[0142] The encryption operation may be any form of encryption operation, and illustratively, the encryption operation may be a hash operation. Specifically, the server may perform a hash operation on the target data object to obtain a hash value corresponding to the target data object, and determine the global lock object to which the target data object belongs based on the hash value.
[0143] After obtaining the hash value, the server can divide the hash value by the total number of global lock objects to obtain the corresponding remainder, and use the global lock object indicated by the remainder as the global lock object to which the target data object belongs.
[0144] For example, assuming that the number of global lock objects is 256, and the global lock numbers corresponding to the 256 global lock objects are 0, 1, 2, 3, ..., 255 respectively, the server performs a hash operation on the target data object to obtain the corresponding hash value, and divides the hash value by 256 to obtain the corresponding remainder. Assuming the remainder is 2, the global lock object numbered 2 is used as the global lock object to which the target data object belongs.
[0145] Among them, the global lock object is used to lock the target memory, and the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object. When the global lock object is set to a locked state, other working threads except the current working thread cannot modify or delete the data in the target memory, which can avoid problems such as write errors caused by multiple working threads modifying the data at the same location in the target memory at the same time.
[0146] Step 706: Determine the data lock object corresponding to the target data object based on the global lock object.
[0147] Step 708: Obtain target data corresponding to the target data object from the remote database through the data lock object, and store the target data in the data cache.
[0148] Among them, after determining the global lock object to which the target data object belongs, the server can update the global lock object to a locked state to create a data lock object corresponding to the target data object in the target content corresponding to the global lock object, or if a data lock object corresponding to the target data object already exists in the target content, read the data lock object, and then use the data lock object corresponding to the target data object to obtain the target data corresponding to the target data object from the remote database, and store the target data in the data cache.
[0149] In the above embodiment, when the target cache data corresponding to the target data object cannot be found in the data cache, the data lock object corresponding to the target data object can be determined through the global lock object to which the target data object belongs, and the target data corresponding to the target data object can be obtained from the remote database using the data lock object, and the target data can be stored in the data cache. The above global lock object and data lock object can ensure that the data acquisition process is only executed once when access requests are concurrent, thereby reducing the number of accesses to the remote database and reducing the access pressure on the remote database.
[0150] In some embodiments, based on the global lock object, determining the data lock object corresponding to the target data object includes: updating the global lock object to a locked state, searching the target memory corresponding to the global lock object for whether there is a data lock object corresponding to the target data object; if not, creating a data lock object corresponding to the target data object, and storing the data lock object corresponding to the target data object in the target memory; if it exists, using the found data lock object as the data lock object corresponding to the target data object; and updating the global lock object to a released state.
[0151] Among them, after the server determines the global lock object to which the target data object belongs, it updates the global lock object to a locked state, so that other working threads cannot modify or delete the data in the target memory corresponding to the global lock object. The server can search for the data lock object corresponding to the target data object in the target memory corresponding to the global lock object. If it cannot be found, it creates a data lock object corresponding to the target data object and stores the data lock object in the above-mentioned target memory. If it can be found, the found data lock object is used as the data lock object corresponding to the target data object. After obtaining the data lock object corresponding to the target data object, the server can update the global lock object to a released state.
[0152] In the above embodiment, after determining the global lock object to which the target data object belongs, the global lock object is updated to a locked state, and then the data lock object corresponding to the target data object is searched in the target memory corresponding to the global lock object. If the data lock object cannot be found, a data lock object corresponding to the target data object is created and stored in the above target memory, and finally the global lock object is updated to a released state. This method of locking the target memory using a global lock object can avoid problems such as write errors caused by multiple worker threads modifying data at the same location in the target memory at the same time.
[0153] In some embodiments, target data corresponding to a target data object is obtained from a remote database through a data lock object, and the target data is stored in a data cache, including: updating the data lock object corresponding to the target data object to a locked state; when it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, obtaining the target data corresponding to the target data object from a remote database and storing the target data in the data cache; updating the data lock object corresponding to the target data object to a released state.
[0154] Among them, in the case that the server receives access requests sent by multiple terminals at the same time, the above multiple access requests can be processed respectively by multiple working threads. Assuming that one of the working threads A first updates the data lock corresponding to the target data object to a locked state, then the operations of other working threads attempting to lock the data lock object will be blocked. Only after working thread A updates the data lock object to a released state, other working threads will be awakened by the system scheduler and try to lock the data lock object again, that is, try to update the data lock corresponding to the target data object to a locked state. After working thread A updates the data lock corresponding to the target data object to a locked state, it further queries whether the data cache exists. The target cache data corresponding to the target data object, since worker thread A first uses the data lock object, and the query result is that it does not exist, then the target data corresponding to the target data object is obtained from the remote database, and the target data is stored in the data cache, and then the data lock object corresponding to the target data object is updated to the released state. At this time, other worker threads can use the data lock object to perform the same operation as worker thread A. The difference is that since worker thread A has obtained the target data and stored it in the data cache, that is, the target cache data corresponding to the target data object already exists in the data cache, at this time, other worker threads no longer obtain data from the remote database, but update the data lock object corresponding to the target data object to the released state. In this way, it can be ensured that the target data is obtained only once from the remote database, reducing the number of visits to the remote database.
[0155] In the above embodiment, after determining the data lock object corresponding to the target data object, the data lock object is updated to a locked state, and then a further query is made as to whether the target data corresponding to the target data object is already stored in the data cache. If the target data corresponding to the target data object is already stored in the data cache, indicating that the target data has been obtained from the remote server, the step of obtaining the target data from the remote database is skipped to perform subsequent operations, thereby reducing the high pressure on remote database access caused by multiple unnecessary data acquisition processes in scenarios with concurrent access requests.
[0156] In some embodiments, after updating the data lock object corresponding to the target data object to a released state, the method further includes: updating the global lock object to a locked state, deleting the data lock object corresponding to the target data object from the target memory; and updating the global lock object to a released state.
[0157] After the server obtains the target data corresponding to the target data object from the remote database and stores the target data in the data cache, it updates the data lock object corresponding to the target data object to a released state. Further, it updates the global lock object to a locked state, deletes the data lock object corresponding to the target data object from the target memory, and updates the global lock object to a released state, thereby releasing the space of the target memory.
[0158] See also Figure 8 As shown, the server can perform a hash operation on the target data object to obtain a hash operation result, determine the global lock object to which the target data object belongs based on the hash operation result, query the target memory corresponding to the global lock object to find the data lock object corresponding to the target data object, and if it cannot be found, create a data lock object corresponding to the target data object and store the data lock object in the above-mentioned target memory. If it can be found, use the found data lock object as the data lock object corresponding to the target data object and update the global lock object to a released state. Update the data lock object corresponding to the target data object to a locked state; if it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, obtain the target data corresponding to the target data object from the remote database and store the target data in the data cache; update the data lock object corresponding to the target data object to a released state. Update the global lock object to a locked state, delete the data lock object corresponding to the target data object from the target memory; update the global lock object to a released state.
[0159] It should be noted that: when the target cache timestamp is consistent with the current cache timestamp, the update timestamp can be used as the current cache timestamp corresponding to the target data object. Figure 8 The process shown in the figure obtains the update data corresponding to the target data object from the remote database. Similarly, when the cache time is greater than or equal to the first preset time, Figure 8 The process shown obtains the update data corresponding to the target data object from the remote database. Figure 8 The process shown is a general process for obtaining corresponding data from a remote database. Any operation that requires obtaining data from a remote database can be done through Figure 8 The process shown is implemented.
[0160] In some embodiments, after receiving an access request to a target page sent by a terminal, the target cache data corresponding to the target data object on the target page is searched in the data cache, including: after receiving access requests to the target page sent by multiple terminals respectively, multiple working threads corresponding to the multiple terminals are started; for each access request to the target page sent by the terminal, the target cache data corresponding to the target data object on the target page is searched in the data cache through the corresponding working thread; the target cache timestamp corresponding to the target cache data is obtained, and the cache duration of the target cache data is determined based on the target cache timestamp, including: for each access request to the target page sent by the terminal, the target cache timestamp corresponding to the target cache data is obtained through the corresponding working thread, and the cache duration of the target cache data is determined based on the target cache timestamp; when a preset condition is met between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp and the current cache timestamp are compared. The timestamps are compared, including: for each access request to the target page sent by each terminal, when the corresponding working thread determines that the cache time and the preset data expiration time meet the preset conditions, the target cache data is returned to the terminal through the corresponding working thread, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp and the current cache timestamp are compared; when the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the corresponding update data of the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the updated data; the update timestamp is used as the target cache timestamp corresponding to the updated data, including: the comparison result obtained by the target working thread that first executes the query operation among multiple working threads is consistent, the corresponding update data of the target data object is obtained from the remote database through the target working thread, and the target cache data in the data cache is replaced with the updated data; the update timestamp is used as the target cache timestamp corresponding to the updated data.
[0161] Among them, the server can simultaneously receive access requests to the target page sent by multiple terminals respectively, and the server can start multiple working threads corresponding to the multiple terminals one by one, and each working thread processes the access request to the target page sent by the corresponding terminal. For the access request to the target page sent by each terminal, the target cache data corresponding to the target data object on the target page can be searched in the data cache by the corresponding working thread; the target cache timestamp corresponding to the target cache data is obtained by the corresponding working thread, and the cache time of the target cache data is determined based on the target cache timestamp; when the preset condition is met between the cache time determined by the corresponding working thread and the preset data expiration time , return the target cache data to the terminal through the corresponding working thread, query the current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp; due to the difference in processing performance of the above-mentioned multiple working threads, the speed of executing the above steps also varies. Only the target working thread that first executes the query operation will get a consistent result when comparing the target cache timestamp with the current cache timestamp. Then, the corresponding update data of the target data object is obtained from the remote database through the target working thread, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
[0162] In the above embodiment, only for access requests with consistent timestamp comparison results, updated data is obtained from the remote database, thereby avoiding the execution of unnecessary acquisition processes, reducing the number of accesses to the remote database, and reducing the access pressure on the remote server.
[0163] In some embodiments, a data caching method is provided, which is described by taking the method executed by a server as an example, and the method includes:
[0164] After receiving the access request to the target page sent by the terminal, the target cache data corresponding to the target data object on the target page is searched in the data cache.
[0165] When the target cache data can be found, a target cache timestamp corresponding to the target cache data is obtained, and a cache duration of the target cache data is determined based on the target cache timestamp; and the cache duration is compared with the first preset duration and the second preset duration respectively.
[0166] When the cache duration is greater than or equal to the second preset duration, and the cache duration is less than the first preset duration, determine whether the cache duration and the preset data expiration duration meet the preset condition. Obtain the linked list timestamp corresponding to the target data object, which is the timestamp of the last update of the usage record linked list for the target data object; obtain the linked list cooling time interval between the linked list timestamp and the current timestamp; when the linked list cooling time interval is greater than or equal to the preset interval threshold, update the linked list timestamp by calling a preset function, and move the target data object to the head of the usage record linked list. Return the target cache data to the terminal, query the current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, use the update timestamp as the current cache timestamp corresponding to the target data object, and obtain the corresponding update data of the target data object from the remote database, and replace the target cache data in the data cache with the updated data; use the update timestamp as the target cache timestamp corresponding to the updated data.
[0167] When the cache duration is greater than or equal to the first preset duration, the updated data corresponding to the target data object is obtained from the remote database, the updated data is returned to the terminal, and the target cache data in the data cache is replaced with the updated data. When the cache duration is less than the second preset duration, the target cache data is returned to the terminal.
[0168] For each pending cache data corresponding to a pending data object in the data cache, start the timer corresponding to the current pending data object from the cache timestamp corresponding to the current pending cache data, and the timing duration of the timer is the first preset duration; when the timer stops, determine that the cache duration of the current pending cache data reaches the first preset duration. Obtain the first data object corresponding to the corresponding pending cache data; select the target expired queue from the expired queue pool according to the preset rules, and store the first data object in the target expired queue; when the target expired queue is full, deliver each data object in the target expired queue to the data communication component through the target expired queue; deliver each data object in the target expired queue to the data clearing coroutine through the data communication component, and clear the pending cache data corresponding to each data object in the target expired queue through the data clearing coroutine.
[0169] In the case that the target cache data corresponding to the target data object does not exist in the data cache, the target data object is encrypted to obtain the encryption result; the global lock object to which the target data object belongs is determined according to the encryption result; the global lock object is used to lock the target memory; the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object; the global lock object is updated to a locked state, and the target memory corresponding to the global lock object is searched for whether there is a data lock object corresponding to the target data object; if it does not exist, the data lock object corresponding to the target data object is created, and the data lock object corresponding to the target data object is stored in the target memory; if it exists, the data lock object found is used as the data lock object corresponding to the target data object; the global lock object is updated to a released state. The data lock object corresponding to the target data object is updated to a locked state; in the case that it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, the target data corresponding to the target data object is obtained from the remote database, and the target data is stored in the data cache; the data lock object corresponding to the target data object is updated to a released state. The global lock object is updated to a locked state, and the data lock object corresponding to the target data object is deleted from the target memory; the global lock object is updated to a released state.
[0170] In the above embodiment, after receiving an access request to a target page sent by a terminal, the target cache data corresponding to the target data object on the target page is searched in the data cache; the target cache timestamp corresponding to the target cache data is obtained, and the cache duration of the target cache data is determined based on the target cache timestamp; when a preset condition is met between the cache duration and the preset data expiration duration, on the one hand, the target cache data is returned to the terminal; on the other hand, the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp; when the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the updated data corresponding to the target data object is obtained from the remote database, and the data is The target cache data in the cache is replaced with the updated data; the above method of returning the target cache data currently cached in the data cache to the terminal and triggering the cache update at the same time realizes the asynchronous update of the cache data. Compared with the method of obtaining the updated data from the remote database immediately after receiving the access request and then returning it to the terminal, the response speed of the access request is accelerated. Moreover, considering the concurrent access requests, there will be a problem of obtaining the updated data from the remote database once for each access request. The above embodiment proposes a timestamp comparison scheme. Only the access request with a consistent timestamp comparison result will obtain the updated data from the remote database, avoiding the execution of unnecessary acquisition process, reducing the number of accesses to the remote database, and reducing the access pressure of the remote server.
[0171] In some possible scenarios, the data caching method provided in the embodiments of the present application can be applied to news applications, where the target page is the homepage of the application, and the target data object is the homepage top module; after the server receives the access request for the homepage sent by the application, it searches the data cache for the target cache data corresponding to the homepage top module on the homepage, obtains the target cache timestamp corresponding to the target cache data, and determines the cache duration of the target cache data based on the target cache timestamp. When the cache duration is greater than or equal to the second preset duration and the cache duration is less than the first preset duration, the target cache data is returned to the terminal, and the homepage top module is queried for the corresponding current cache timestamp, and the target cache timestamp is compared with the current cache timestamp; when the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the homepage top module, and the corresponding update data of the homepage top module is obtained from the remote database, and the target cache data in the data cache is replaced with the updated data; the update timestamp is used as the target cache timestamp corresponding to the updated data. When the cache duration is greater than or equal to the first preset duration, the updated data corresponding to the home page pinning module is obtained from the remote database, the updated data is returned to the terminal, and the target cache data in the data cache is replaced with the updated data. When the cache duration is less than the second preset duration, the target cache data is returned to the terminal.
[0172] It should be noted that the application scenarios provided above are only used to illustrate the data caching method of this application, and the application of the data caching method provided by this application is not limited to the application scenarios provided above. For example, it can also be applied to game applications, social applications, etc. This embodiment of the application does not limit this.
[0173] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0174] Based on the same inventive concept, the embodiment of the present application also provides a data caching device for implementing the data caching method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more data caching device embodiments provided below can refer to the limitations on the data caching method above, and will not be repeated here.
[0175] In one embodiment, Fig. 9 As shown, a data cache device is provided, comprising:
[0176] The search module 901 is used to search the target cache data corresponding to the target data object on the target page in the data cache after receiving the access request to the target page sent by the terminal;
[0177] A determination module 902 is used to obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp;
[0178] Comparison module 903, used to return the target cache data to the terminal when the cache duration and the preset data expiration duration meet the preset condition, query the current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp;
[0179] Update module 904 is used to use the update timestamp as the current cache timestamp corresponding to the target data object when the target cache timestamp and the current cache timestamp are consistent, and obtain the update data corresponding to the target data object from the remote database, and replace the target cache data in the data cache with the update data; and use the update timestamp as the target cache timestamp corresponding to the update data.
[0180] In some embodiments, the preset data expiration period includes: a first preset period and a second preset period, and the first preset period is greater than the second preset period; the comparison module 903 is specifically used to: compare the cache period with the first preset period and the second preset period respectively, and when the cache period is greater than or equal to the second preset period, and the cache period is less than the first preset period, determine that the cache period and the preset data expiration period meet the preset condition.
[0181] In some embodiments, the comparison module 903 is also used to obtain updated data corresponding to the target data object from the remote database when the cache duration is greater than or equal to the first preset duration, return the updated data to the terminal, and replace the target cache data in the data cache with the updated data.
[0182] In some embodiments, the comparison module 903 is further configured to return the target cache data to the terminal when the cache duration is less than a second preset duration.
[0183] In some embodiments, the above-mentioned data caching device also includes a cleaning module, which is used to detect the cache length of the pending cache data corresponding to each pending data object in the data cache, and when the detection result indicates that the cache length of the corresponding pending cache data reaches a first preset length, the corresponding pending cache data is cleared.
[0184] In some embodiments, the cleaning module is specifically used to obtain a first data object corresponding to corresponding cached data to be processed; select a target expiration queue from an expiration queue pool according to preset rules, and store the first data object in the target expiration queue; when the target expiration queue is full, deliver each data object in the target expiration queue to a data communication component through the target expiration queue; deliver each data object in the target expiration queue to a data clearing coroutine through the data communication component, and clear the cached data to be processed corresponding to each data object in the target expiration queue through the data clearing coroutine.
[0185] In some embodiments, a cleaning module is specifically used to start a timer corresponding to the current data object to be processed, starting from the cache timestamp corresponding to the current data object to be processed, for each data object to be processed in the data cache, and the timing duration of the timer is a first preset duration; when the timer stops, it is determined that the cache duration of the current data object to be processed has reached the first preset duration.
[0186] In some embodiments, the above-mentioned data caching device also includes a linked list update module, which is used to obtain the linked list timestamp corresponding to the target data object, the linked list timestamp is the timestamp of the last update of the usage record linked list for the target data object; obtain the linked list cooling time interval between the linked list timestamp and the current timestamp; when the linked list cooling time is greater than or equal to the preset interval threshold, the linked list timestamp is updated by calling a preset function, and the target data object is moved to the head of the usage record linked list.
[0187] In some embodiments, the above-mentioned data cache device also includes an acquisition module, which is used to perform an encryption operation on the target data object to obtain an encryption operation result when the target cache data corresponding to the target data object does not exist in the data cache; determine the global lock object to which the target data object belongs according to the encryption operation result; the global lock object is used to lock the target memory; the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object; based on the global lock object, determine the data lock object corresponding to the target data object; obtain the target data corresponding to the target data object from the remote database through the data lock object, and store the target data in the data cache.
[0188] In some embodiments, an acquisition module is specifically used to update the global lock object to a locked state, and search the target memory corresponding to the global lock object for a data lock object corresponding to the target data object; if it does not exist, create a data lock object corresponding to the target data object, and store the data lock object corresponding to the target data object in the target memory; if it exists, use the found data lock object as the data lock object corresponding to the target data object; and update the global lock object to a released state.
[0189] In some embodiments, the acquisition module is specifically used to update the data lock object corresponding to the target data object to a locked state; when it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, obtain the target data corresponding to the target data object from a remote database and store the target data in the data cache; and update the data lock object corresponding to the target data object to a released state.
[0190] In some embodiments, the acquisition module is further used to update the global lock object to a locked state, delete the data lock object corresponding to the target data object from the target memory; and update the global lock object to a released state.
[0191] In some embodiments, the search module 901 is specifically used to start multiple work threads corresponding to the multiple terminals one by one after receiving access requests to the target page sent by multiple terminals respectively; for each access request to the target page sent by each terminal, search the target cache data corresponding to the target data object on the target page in the data cache through the corresponding work thread;
[0192] The determination module 902 is specifically used to: for each access request to the target page sent by each terminal, obtain the target cache timestamp corresponding to the target cache data through the corresponding working thread, and determine the cache duration of the target cache data based on the target cache timestamp;
[0193] The comparison module 903 is specifically used for: for each access request to the target page sent by each terminal, when the corresponding working thread determines that the cache duration and the preset data expiration duration meet the preset condition, returning the target cache data to the terminal through the corresponding working thread, querying the current cache timestamp corresponding to the target data object, and comparing the target cache timestamp with the current cache timestamp;
[0194] The update module 904 is specifically used for: when the comparison result obtained by the target work thread that first executes the query operation among multiple work threads is consistent, the target work thread obtains the update data corresponding to the target data object from the remote database, and replaces the target cache data in the data cache with the update data; and uses the update timestamp as the target cache timestamp corresponding to the update data.
[0195] Each module in the above data cache device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0196] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store cache data corresponding to each data object. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data caching method is implemented.
[0197] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0198] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0199] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0200] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0201] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0202] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0203] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0204] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A data caching method, It is characterized in that The method comprises: After receiving the access request for the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page; Obtaining a target cache timestamp corresponding to the target cache data, and determining a cache duration of the target cache data based on the target cache timestamp; When a preset condition is satisfied between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and a current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp; When the target cache timestamp is consistent with the current cache timestamp, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data.
2. The method according to claim 1, It is characterized in that The preset data expiration time includes: a first preset time and a second preset time, and the first preset time is greater than the second preset time; the method further includes: The cache duration is compared with the first preset duration and the second preset duration respectively. When the cache duration is greater than or equal to the second preset duration and the cache duration is less than the first preset duration, it is determined that the cache duration and the preset data expiration duration satisfy a preset condition.
3. The method according to claim 2, It is characterized in that The method further comprises: When the cache duration is greater than or equal to the first preset duration, updated data corresponding to the target data object is obtained from a remote database, the updated data is returned to the terminal, and the target cache data in the data cache is replaced with the updated data.
4. The method according to claim 2, It is characterized in that The method further comprises: When the cache duration is less than the second preset duration, the target cache data is returned to the terminal.
5. The method according to claim 1, It is characterized in that The method further comprises: The cache duration of the cache data to be processed corresponding to each of the data objects to be processed in the data cache is detected respectively, and when the detection result indicates that the cache duration of the corresponding cache data to be processed reaches a first preset duration, the corresponding cache data to be processed is cleared.
6. The method according to claim 5, It is characterized in that The clearing of the corresponding cache data to be processed includes: Obtaining a first data object corresponding to the corresponding cache data to be processed; Selecting a target expired queue from an expired queue pool according to a preset rule, and storing the first data object in the target expired queue; When the target expiration queue is full, delivering each data object in the target expiration queue to the data communication component through the target expiration queue; Each data object in the target expiration queue is delivered to a data clearing coroutine through the data communication component, and the to-be-processed cache data corresponding to each data object in the target expiration queue is cleared through the data clearing coroutine.
7. The method according to claim 5, It is characterized in that The detecting respectively the cache duration of the cached data to be processed corresponding to each of the data objects to be processed in the data cache includes: For each cached data to be processed corresponding to the data object to be processed in the data cache, starting from the cache timestamp corresponding to the current cached data to be processed, a timer corresponding to the current data object to be processed is started, and the timing duration of the timer is a first preset duration; When the timer stops timing, it is determined that the cache duration of the current cache data to be processed reaches a first preset duration.
8. The method according to claim 1, It is characterized in that Before returning the target cache data to the terminal, the method further includes: Obtaining a linked list timestamp corresponding to the target data object, where the linked list timestamp is a timestamp of a previous update of a usage record linked list for the target data object; Obtain the linked list cooling time interval between the linked list timestamp and the current timestamp; When the cooling time of the linked list is greater than or equal to a preset interval threshold, the linked list timestamp is updated by calling a preset function, and the target data object is moved to the head of the usage record linked list.
9. The method according to claim 1, It is characterized in that The method further comprises: In the case that the target cache data corresponding to the target data object does not exist in the data cache, performing encryption operation on the target data object to obtain an encryption operation result; Determine the global lock object to which the target data object belongs according to the encryption operation result; the global lock object is used to lock the target memory; the target memory is used to store the data lock objects corresponding to each data object managed by the global lock object; Based on the global lock object, determining a data lock object corresponding to the target data object; The target data corresponding to the target data object is acquired from a remote database through the data lock object, and the target data is stored in the data cache.
10. The method according to claim 9, It is characterized in that The determining, based on the global lock object, a data lock object corresponding to the target data object includes: The global lock object is updated to a locked state, and a data lock object corresponding to the target data object is searched in the target memory corresponding to the global lock object to determine whether there is a data lock object corresponding to the target data object; If the target data object does not exist, create a data lock object corresponding to the target data object, and store the data lock object corresponding to the target data object in the target memory; if the target data object does exist, use the found data lock object as the data lock object corresponding to the target data object; Update the global lock object to a released state.
11. The method according to claim 9, It is characterized in that The step of acquiring target data corresponding to the target data object from a remote database through the data lock object and storing the target data in the data cache includes: Updating the data lock object corresponding to the target data object to a locked state; When it is determined that the target cache data corresponding to the target data object still does not exist in the data cache, acquiring the target data corresponding to the target data object from a remote database and storing the target data in the data cache; The data lock object corresponding to the target data object is updated to a released state.
12. The method according to claim 11, It is characterized in that After updating the data lock object corresponding to the target data object to a released state, the method further includes: The global lock object is updated to a locked state, and the data lock object corresponding to the target data object is deleted from the target memory; and the global lock object is updated to a released state.
13. The method according to any one of claims 1 to 12, It is characterized in that After receiving the access request for the target page sent by the terminal, searching the data cache for the target cache data corresponding to the target data object on the target page, includes: After receiving access requests to a target page respectively sent by a plurality of terminals, a plurality of work threads corresponding to the plurality of terminals are started; For each access request to a target page sent by each terminal, searching the data cache for target cache data corresponding to the target data object on the target page through the corresponding working thread; The acquiring a target cache timestamp corresponding to the target cache data, and determining a cache duration of the target cache data based on the target cache timestamp, includes: For each access request to the target page sent by each terminal, a target cache timestamp corresponding to the target cache data is obtained through a corresponding working thread, and a cache duration of the target cache data is determined based on the target cache timestamp; When a preset condition is satisfied between the cache duration and the preset data expiration duration, the target cache data is returned to the terminal, and a current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp, including: For each access request to the target page sent by the terminal, when the corresponding working thread determines that the cache duration and the preset data expiration duration meet the preset condition, the target cache data is returned to the terminal through the corresponding working thread, and the current cache timestamp corresponding to the target data object is queried, and the target cache timestamp is compared with the current cache timestamp; When the target cache timestamp and the current cache timestamp are consistent, the update timestamp is used as the current cache timestamp corresponding to the target data object, and the update data corresponding to the target data object is obtained from the remote database, and the target cache data in the data cache is replaced with the update data; the update timestamp is used as the target cache timestamp corresponding to the update data, including: The comparison result obtained by the target working thread that first executes the query operation among the multiple working threads is consistent, and the target working thread obtains the update data corresponding to the target data object from the remote database, and replaces the target cache data in the data cache with the update data; and uses the update timestamp as the target cache timestamp corresponding to the update data.
14. A data cache device, It is characterized in that The device comprises: A search module, configured to search the data cache for target cache data corresponding to the target data object on the target page after receiving an access request to the target page sent by the terminal; A determination module, configured to obtain a target cache timestamp corresponding to the target cache data, and determine a cache duration of the target cache data based on the target cache timestamp; A comparison module, configured to return the target cache data to the terminal when a preset condition is satisfied between the cache duration and a preset data expiration duration, query a current cache timestamp corresponding to the target data object, and compare the target cache timestamp with the current cache timestamp; An update module is used to use the update timestamp as the current cache timestamp corresponding to the target data object when the target cache timestamp is consistent with the current cache timestamp, obtain the update data corresponding to the target data object from the remote database, replace the target cache data in the data cache with the update data; and use the update timestamp as the target cache timestamp corresponding to the update data.
15. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 13 are implemented.
16. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
17. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
Citation Information
Cited By
Data processing method and device, equipment, storage medium and product
CN119784473A
Data processing method and device, equipment, storage medium and product
CN119784473B
Outgoing event information processing method and device, computer equipment, storage medium and computer program product
CN120705003A
External event information processing method and device, computer device, storage medium and computer program product
CN120705003B
Data processing method and system, computing device and storage medium
CN122285235A
