Data synchronization method and device, equipment and storage medium

By storing data pull status in the client memory cache, the problem of wasted resource waste and excessive server traffic caused by client cache verification is solved, and efficient data synchronization is achieved.

CN120343036APending Publication Date: 2025-07-18BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510353825.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-24
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, when the client pulls data from the server, there are problems such as wasting resources and excessive instantaneous traffic of the server, especially the repeated requests and traffic increases caused by asynchronousness during the client cache verification process.

Method used

Store the pull state of data in the client's memory cache, judge whether the data in the local database cache expires, and decide whether to pull data from the server based on the pull state to avoid repeated requests.

Benefits of technology

It effectively avoids resource waste from clients and servers, reduces instantaneous traffic of servers, and improves the efficiency of data synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120343036A_ABST
    Figure CN120343036A_ABST
Patent Text Reader

Abstract

Embodiments of the invention provide a data synchronization method, apparatus and device, and a storage medium, the method comprising: when a client needs to obtain N data, determining N1 target data to be pulled from the N data, the target data being expired data in a local database cache of the client; for each piece of target data, reading a pulling state of the target data from a memory cache of the client; if the pulling state indicates that the target data is being pulled, waiting for a pulling result of the target data; and if the pulling state indicates that the target data is not being pulled, updating the pulling state of the target data to be being pulled, and starting to pull the target data from the server. According to the method, whether the data is pulled from the server side or not can be determined according to the pulling state of the data stored in the memory cache, and the data which is being pulled does not need to be repeatedly pulled from the server, so that the resource waste of the client and the server can be avoided, and the instantaneous flow of the server can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular, to a data synchronization method, device, equipment, and storage medium. Background Art

[0002] When a client needs to synchronize data from a server (or called a service end), it can be achieved through a pull data interface or a push data interface provided by the server. In some scenarios, when the server cannot push data to the client through the push data interface, the client can only rely on the pull data interface to pull data from the server.

[0003] The client can request data from the server through multiple parallel pull data interfaces. When there are too many instantaneous data points obtained by the client, it will cause a large number of server interface requests, and these requests are concentrated within a short period of time, which is likely to cause an instantaneous explosion of the server interface traffic and excessive pressure on the server. In the prior art, the client cache is used to reduce the traffic of the server interface. Specifically, after the client requests data from the server, the data is synchronized to the client cache, and the update time of the data is recorded. Before each time the client pulls data from the server, it checks whether the data in the client cache has expired. If the data has not expired, the data is read from the client cache. If the data has expired, the data is pulled from the server. This method only pulls the expired data in the client cache from the server, thereby reducing the traffic of the server interface.

[0004] However, the process of the client reading data from the client cache is an asynchronous process. The client needs to wait for a certain period of time to obtain the verification result. During the period of waiting for the verification result, there may be other requests to obtain the same data, so there is a certain probability of causing repeated requests to the server to obtain the same data, which will result in waste of resources of the client and the server, and will also increase the instantaneous traffic of the server. Summary of the Invention

[0005] The embodiments of the present application provide a data synchronization method, device, equipment, and storage medium, which can avoid waste of resources of the client and the server, and reduce the instantaneous traffic of the server.

[0006] In a first aspect, the embodiments of the present application provide a data synchronization method, which is applied to a client, and the method includes:

[0007] When the client needs to obtain N data, determine N1 target data to be pulled from the N data, where the target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1;

[0008] For each target data, read the pull status of the target data from the memory cache of the client, where the pull status is used to indicate whether the target data is being pulled;

[0009] If the pull status of the target data indicates that the target data is being pulled, wait for the pull result of the target data;

[0010] If the pull status of the target data indicates that the target data is not being pulled, update the pull status of the target data to being pulled, and start pulling the target data from the server;

[0011] In response to successful pulling of the target data, update the target data to the local database cache, and update the pull status of the target data to not being pulled.

[0012] In some exemplary embodiments, the method further includes: in response to failure of pulling the target data, update the update time of the target data stored in the local database cache to a target value, and update the pull status of the target data to not being pulled, where the target value is used to indicate that the target data has expired.

[0013] In some exemplary embodiments, the method further includes: if the pull status of the target data is not read from the memory cache, add the pull status of the target data to the memory cache, update the pull status of the target data to being pulled, and start pulling the target data from the server.

[0014] In some exemplary embodiments, the local database cache stores data pulled from the server and the update time of the data, and the data in the local database cache has a validity period.

[0015] In some exemplary embodiments, determining N1 target data to be pulled from the N data includes:

[0016] For each of the N data, determine whether the data is stored in the local database cache;

[0017] If the data is stored in the local database cache, determine whether the data has expired according to the update time and the data validity period of the data stored in the local database cache. If the data has expired, determine the data as target data;

[0018] If the data is not stored in the local database cache, determine that the data has expired and determine the data as target data.

[0019] In some exemplary embodiments, after determining N1 target data to be pulled from the N data, the method further includes: modifying and updating the update time of the target data stored in the local database cache to the current time.

[0020] In some exemplary embodiments, the client modifies and updates the update time of the target data stored in the local database cache by using an optimistic update method to the current time.

[0021] In some exemplary embodiments, the operation of reading the pull status of the target data from the memory cache of the client is executed asynchronously with the operation of modifying and updating the update time of the target data stored in the local database to the current time.

[0022] In some exemplary embodiments, the least recently used (LRU) page replacement algorithm is used to manage the cache space of the memory cache of the client.

[0023] In some exemplary embodiments, when the target data is successfully pulled, updating the target data to the local database cache includes:

[0024] Writing the pulled target data to the local database cache and updating the update time of the target data.

[0025] In a second aspect, an embodiment of the present application provides a data synchronization device, the device includes:

[0026] A determination module, configured to determine N1 target data to be pulled from the N data when the client needs to obtain N data, where the target data is data that has expired in the local database cache of the client, and N is an integer greater than 1;

[0027] A reading module, configured to, for each target data, read the pull status of the target data from the memory cache of the client, where the pull status is used to indicate whether the target data is being pulled;

[0028] A data pulling module, configured to wait for the pull result of the target data when the pull status of the target data indicates that the target data is being pulled, and update the pull status of the target data to being pulled and start pulling the target data from the server when the pull status of the target data indicates that the target data is not being pulled;

[0029] An update module, configured to update the target data to the local database cache in response to successful pulling of the target data, and update the pull status of the target data to not being pulled.

[0030] In a third aspect, an embodiment of the present application provides a terminal device, which includes: a processor and a memory. The memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the method described in the first aspect above.

[0031] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program, and the computer program enables a computer to execute the method described in the first aspect above.

[0032] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the method described in the first aspect above.

[0033] The data synchronization method provided by the embodiment of the present application stores the pulling status of data in the memory cache of the client. When the data in the local database cache expires, it decides whether to pull data from the server according to the pulling status of the data. If the pulling status of the data indicates that the target data is being pulled, there is no need to repeatedly pull data from the server, but only wait for the pulling result of the data. On the one hand, it can avoid the client from repeatedly requesting the same data from the server, avoiding waste of resources of the client and the server. On the other hand, for duplicate data within a short period of time, the client only needs to request the data from the server once, thereby reducing the instantaneous traffic of the server. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0035] Figure 1 It is a schematic diagram of a network architecture applicable to the embodiment of the present application;

[0036] Figure 2 It is a timing diagram of the client requesting data from the server;

[0037] Figure 3 It is a flowchart of the data synchronization method provided in Embodiment 1 of the present application;

[0038] Figure 4 It is an interaction diagram between the client and other devices in the data synchronization method;

[0039] Figure 5 It is a schematic structural diagram of the data synchronization device provided in Embodiment 2 of the present application;

[0040] Figure 6 This is a schematic structural diagram of the terminal device provided in Embodiment 3 of the present application. Detailed implementation manners

[0041] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0042] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order different from those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0043] The embodiment of the present application provides a data synchronization method. Figure 1 This is a schematic diagram of a network architecture applicable to the embodiment of the present application. As Figure 1 shown, the network architecture includes a client 10 and a server 20. The client and the server can communicate with each other in a wired or wireless manner.

[0044] The client 10 can be an instant messaging application (APP), a news client, or other application software, and can also be a Web page or a small program, etc. The client 10 runs in a terminal device, which includes but is not limited to a mobile phone, a tablet computer, a notebook computer, a desktop computer, a smart TV, a smart wearable device, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc.

[0045] The server 20 is the background server corresponding to the client 10, and is used to provide services for the client 10. The client 10 depends on the services and data provided by the server 20 to complete its functions.

[0046] Data synchronization is performed between the client 10 and the server 20 through a pull data interface or a push data interface. When communicating through the pull data interface, the client 10 sends a data pull request to the server 20 through the pull data interface. The server 20 queries the pulled data from the database according to the data pull request and returns a response to the data pull request to the client 10. The response to the data pull request includes the data requested by the client 10. When communicating through the push data interface, the server 20 actively pushes data to the client 10 through the push data interface.

[0047] In some scenarios, the server 20 cannot push data to the client 10 through the push data interface. For example, the server 20 cannot calculate the result to be pushed, or the amount of data to be pushed is too large and exceeds the maximum level that the server 20 can bear. At this time, the client 10 can only achieve data synchronization through the pull data interface.

[0048] Figure 2 It is a timing diagram for the client to request data from the server, as Figure 2 shown. The client 10 needs to obtain data at multiple points. For the data at each point, the client 10 needs to send a data pull request (also called a pull data interface request) through the pull data interface. Correspondingly, the server 20 returns a corresponding response for each data pull request.

[0049] In the embodiments of the present application, a point refers to a specific location or node on the client where specific data needs to be obtained. In an actual scenario, the client usually needs to obtain data at multiple points simultaneously, and the data acquisition at each point will trigger an independent data pull request. If 100 points request data simultaneously, the server will receive 100 parallel data pull requests.

[0050] Taking an instant messaging application as an example, after the user opens the instant messaging application, the instant messaging application needs to obtain data at multiple points. The point can be one or more types of labels on the page of the instant general application. For example, a classification label is displayed after the user names of some message sessions in the message list of the instant general application, or a classification label is displayed after the user name in a specific conversation box. The classification label can be a label for distinguishing whether the user is an internal employee or an external employee of the enterprise. For example, the "external" label is used to distinguish that a friend is an external employee of the enterprise. The classification label can also be a label for distinguishing the department to which the employee belongs, or the classification label can also be a label for distinguishing whether the employee belongs to the headquarters or a branch of the group company, etc.

[0051] Taking the classification label used to distinguish whether a user is an internal employee or an external employee of an enterprise as an example, when the user opens the instant messaging application, the instant messaging application needs to request the "external" labels of all friends from the server. When the user has 100 friends, it is necessary to request the labels of these 100 friends from the server. For the same label, it may be located in different groups or pages (i.e., different positions in the client). When the label is in different groups or pages, although the label is the same, due to the different positions where the label is located, it will be regarded as multiple different points, and data needs to be requested separately.

[0052] When there are too many data acquisition points on the client side, a large number of interface requests will flood the server in a short period of time, causing a sharp increase in the instantaneous traffic of the server interface and putting pressure on the server. If the data change frequency of these points is not high, frequent requests will also cause unnecessary traffic waste on the client side.

[0053] In the prior art, the client cache is used to reduce the traffic of the server interface. After the client requests data from the server, the data is synchronized to the client cache, and the update time of the data is recorded. Before each time the client pulls data from the server, it checks whether the data in the client cache has expired. If the data has not expired, the data is read from the client cache. If the data has expired, the data is pulled from the server. This method only pulls the expired data in the client cache from the server, thereby reducing the traffic of the server interface.

[0054] The client cache stores the data and the update time of the data. The client cache is usually a local database cache. Each point needs to go through a verification process before pulling data from the server side. However, the reading of the local database cache is an asynchronous process, and the client needs to wait for a certain time to obtain the verification result. During the period of waiting for the verification result, there may be other points obtaining the same data, so there is a certain probability of causing repeated requests to the server to obtain the same data, resulting in waste of resources on the client and the server, and also increasing the instantaneous traffic of the server.

[0055] To solve the problems of the prior art, an embodiment of the present application provides a data synchronization method. This data synchronization method simultaneously uses the local database cache of the client and the in-memory cache of the client, stores the data pulling status in the in-memory cache of the client, and this pulling status is used to indicate whether data is being pulled from the server. The data content and the update time of the data are stored in the local database cache of the client. When data synchronization is required, if the data in the local database cache of the client has expired, it is judged whether the data is being pulled according to the data pulling status. If it is being pulled, wait for the data pulling to end. If it is not being pulled, pull the data from the server. This method avoids repeatedly pulling the same data from the server according to the data pulling status in the in-memory cache of the client, avoids wasting resources of the client and the server, and also reduces the instantaneous traffic of the server.

[0056] Figure 3 It is a flowchart of the data synchronization method provided by Embodiment 1 of the present application. The method of this embodiment is applied to the client, as Figure 3 shown. The method provided by this embodiment includes the following steps.

[0057] S101. When the client needs to obtain N pieces of data, determine N1 target data to be pulled from the N pieces of data. This target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1.

[0058] The N pieces of data are the data of N points. The data of these N points may be different or may have some similarities. For example, in an instant messaging application, it is necessary to obtain the labels of 20 friends. The label data of these 20 friends is different, and the labels of the same friend on different pages will be regarded as different points and the data of the points need to be obtained separately, while the data of these points is actually the same.

[0059] To reduce the load and pressure on the server, a local database cache is set on the client side in the embodiment of the present application. The local database cache stores the data pulled from the server and the update time of the data. Among them, the update time of the data can be the time when the data is written into the local database cache, or the reception time when the client receives the data from the server. The data in the local database cache has a validity period, and the validity period of the data can be set as needed. Exemplarily, the validity period of the data is 30 seconds, 60 seconds, or 90 seconds, etc.

[0060] In the embodiment of the present application, the data with a large request volume on the client in a short period of time can be stored in the local database cache, or the data with a large request volume and repetition on the client in a short period of time can be stored in the local database cache.

[0061] When the client needs to obtain N pieces of data, the client can determine whether these data are the target data to be pulled according to the update time of the data stored in the local database cache. Exemplarily, for each of the N pieces of data, the client determines whether the data is stored in the local database cache; if the data is stored in the local database cache, then according to the update time and data validity period of the data stored in the local database cache, it is determined whether the data has expired. If the data has expired, then it is determined that the data is the target data. If the data is not stored in the local database cache, then it is determined that the data has expired and the data is determined to be the target data.

[0062] Each piece of data has an identifier. The client can look up the update time of the data in the local database cache according to the identifier of the data. If the update time of the data can be queried from the local database cache, it is determined that the data is stored in the local database cache. If the update time of the data cannot be queried from the local database cache, it is determined that the data is not stored in the local database cache, that is, the data is pulled for the first time.

[0063] Exemplarily, the data validity period of the data stored in the local database cache is 60 seconds. After the client obtains the update time of a certain piece of data, it can calculate the time difference between the current time and the update time of the data, and determine whether the calculated time difference is greater than the data validity period. If the calculated time difference is greater than or equal to the data validity period, it is determined that the data has expired. If the calculated time difference is less than the data validity period, it is determined that the data has not expired.

[0064] Alternatively, after the client obtains the update time of a certain piece of data, it calculates the sum of the update time of the data and the data validity period to obtain the expiration time of the data, and determines whether the expiration time of the data is greater than the current time. If the expiration time of the data is greater than or equal to the current time, it is determined that the data has not expired. If the expiration time of the data is less than the current time, it is determined that the data has expired.

[0065] The value of N1 may be less than or equal to N. When N1 is less than N, it means that some of the data at N points have not expired. For the data that has not expired, the data can be directly read from the local database cache without pulling from the server. For the data that has expired, it needs to be pulled from the server.

[0066] S102. For each target data, read the pull status of the target data from the memory cache of the client, where the pull status is used to indicate whether the target data is being pulled.

[0067] In this embodiment, the pulling status of data is stored in the memory cache of the client. Since the reading speed of the memory is relatively fast, the pulling status of data can be quickly obtained, avoiding other points from obtaining the same data during the process of obtaining the pulling status of data. The pulling status of data is used to indicate whether the data is being pulled. Herein, the data being pulled means that the client is pulling the data from the server.

[0068] Exemplarily, the memory cache of the client stores the identifier of the data and the pulling status of the data. The identifier of the data is used to distinguish which data's pulling status is stored. The pulling status of the data can be represented by one or more bits. For example, when representing the pulling status of the data by one bit, 1 can be used to indicate being pulled, and 0 can be used to indicate not being pulled.

[0069] In the embodiment of the present application, an appropriate cache space (such as an appropriate number of memory entries) can be configured to store the pulling status of data, thereby avoiding memory leaks. A memory leak refers to the situation where, during the running of a program, the memory space allocated is not correctly released after being used, resulting in this part of the memory being unable to be reused. As the program runs, the leaked memory accumulates continuously, and eventually, it may exhaust the system's memory resources, causing the program to crash or the system to run slowly.

[0070] Optionally, the Least Recently Used (LRU) page replacement algorithm can be used to manage the cache space of the memory cache of the client.

[0071] The core idea of the LRU algorithm is that if data has not been accessed within a recent period of time, then the possibility of its being accessed in the future is relatively low. Therefore, when the cache space is full and some data needs to be eliminated, the LRU algorithm will preferentially select the data that has not been accessed for the longest time to be eliminated.

[0072] In this embodiment, when the cache space of the memory cache preconfigured for storing the pulling status of data is full or the usage rate (such as 90%) reaches a preset ratio, the RLU algorithm can be used to eliminate the pulling status of the data that has not been accessed within a recent period of time.

[0073] Figure 4 For the interaction schematic diagram between the client and other devices in the data synchronization method, as Figure 4 shown, optionally, after the client determines N1 target data to be pulled from N data, it can also update the update time of the expired data in the local database cache, that is, modify the update time of the target data (i.e., the expired data) stored in the local database cache to the current time.

[0074] In this embodiment, the client updates the update time of the expired data in the local database cache by using the optimistic update method. Optimistic update and pessimistic update are two common data update strategies when operating on a database concurrently. The optimistic update assumes that in most cases, the data will not be modified by other transactions between being read and updated, that is, the possibility of concurrent conflicts is small. Therefore, when operating on the data, the data is not locked. The pessimistic update believes that the data is very likely to be modified by other transactions between being read and updated. Therefore, when operating on the data, a lock is acquired first to prevent other transactions from modifying the data simultaneously, thus avoiding data conflicts.

[0075] Optionally, the operation of reading the pull status of the target data from the client's memory cache and the operation of modifying and updating the update time of the target data stored in the local database to the current time are executed asynchronously. By asynchronously updating the update time of the expired data in the local database cache, the waiting time before reading the pull status of the target data from the client's memory cache is saved. Once it is determined that the target data has expired, the pull status of the target data can be read from the memory cache.

[0076] S103. If the pull status of the target data indicates that the target data is being pulled, wait for the pull result of the target data.

[0077] S104. If the pull status of the target data indicates that the target data is not being pulled, update the pull status of the target data to being pulled and start pulling the target data from the server.

[0078] Refer to Figure 4 As shown, optionally, after the client reads the pull status of the target data from the memory cache, it determines whether the target data is being pulled. If the data is being pulled, step S103 is executed; if the data is not being pulled, step S104 is executed.

[0079] If the target data is being pulled, it means that before the current time, there is already data at other points that is the same as the target data, and the data at other points has already started to be pulled. For the same data at multiple points, the client does not need to repeatedly pull from the server, but only needs to pull from the server once, and other points share the pulled data. Therefore, when the pull status of the target data indicates that the target data is being pulled, the client only needs to wait for the pull result of the target data. After the target data is successfully pulled at other points, all points that need to obtain the target data will be notified, and the pulled target data will be stored in the local database cache.

[0080] If the target data is not being pulled, it means that before the current time, no other points have pulled the target data. Refer to Figure 4, the client updates the memory cache and updates the pulling status of the target data to being pulled.

[0081] Among them, updating the pulling status of the target data to being pulled and pulling the target data from the server adopt a synchronous manner, that is, the client needs to update the pulling status of the target data to being pulled first before pulling the target data from the server.

[0082] Refer to Figure 4 As shown, the client pulling data from the server includes the following steps: the client sends a data pulling request to the interface of the server, and the data pulling request includes the identifier of the data to be pulled. The server queries the data to be pulled from the database of the server according to the identifier of the data to be pulled, and carries the data to be pulled in the response of the data pulling request.

[0083] It should be noted that if the client does not read the pulling status of the target data from the memory cache, the pulling status of the target data is added to the memory cache, and the pulling status of the target data is updated to being pulled, and the client starts to pull the target data from the server. Optionally, it can also be considered that the fact that the pulling status of the target data is not read from the memory cache indicates that the target data is not being pulled.

[0084] In the method of this embodiment, the client stores the pulling status of the data in the memory cache. When the data in the local database cache expires, it can decide whether to pull the data from the server according to the pulling status of the data. If the pulling status indicates that the target data is being pulled, it means that there is the same data and it is already being pulled, so there is no need to repeatedly pull the data from the server, but just wait for the result of the data pulling, thus avoiding the client from repeatedly requesting the same data from the server and reducing the instantaneous traffic of the server. Taking an instant messaging application as an example, before using the method of this embodiment of the present application, the interface magnitude of the server is 10 qps / user, where qps / user represents the number of query requests (Queries per Second, qps) generated by each user per second. After using the method of this embodiment of the present application, the interface magnitude of the server is reduced to 0 - 1 qps / user.

[0085] S105. In response to successful pulling of the target data, update the target data to the local database cache, and update the pulling status of the target data to not being pulled.

[0086] The target data may be successfully pulled or pulled unsuccessfully. When the target data is successfully pulled, that is, when the client obtains the target data from the server, in addition to using the target data for page display, the client also updates the target data to the local database cache and updates the in-memory cache of the client, that is, updates the pulling status of the target data to not being pulled.

[0087] Among them, updating the target data to the local database cache includes: writing the pulled target data to the local database cache and updating the update time of the target data. Optionally, the update time of the target data is updated to the current time, or the update time of the target data is updated to the time when the target data is written to the local database cache, or the update time of the target data is updated to the reception time when the target data is received from the server.

[0088] Optionally, in response to the failure of pulling the target data, the update time of the target data stored in the local database cache is updated to a target value, and the pulling status of the target data is updated to not being pulled, where the target value is used to indicate that the target data has expired. Exemplarily, the value of the target value is 0, and the value of the target value can also be a null value (Null) or an infinitely large value, etc.

[0089] Refer to Figure 4 As shown, when the target data is successfully pulled or pulled unsuccessfully, the client will update the in-memory cache, that is, update the pulling status of the target data stored in the in-memory cache to not being pulled. Among them, when the target data is pulled unsuccessfully, the client also updates the update time of the abnormal data (that is, the target data that fails to be pulled) in the local database cache, that is, updates the update time of the abnormal data to the target value. Subsequently, when the client reads that the update time of the target data is the target value, it determines that the target data has expired according to the value of the update time of the target data.

[0090] Optionally, when the target data is pulled unsuccessfully, the client updates the update time of the target data stored in the local database cache to 0. Subsequently, when the client reads that the update time of the target data is 0, it determines that the target data has expired. When the target data is pulled unsuccessfully, the update operation on the update time of the target data is called a failure rollback.

[0091] In this embodiment, when the client needs to obtain N pieces of data, N1 pieces of target data to be pulled are determined from the N pieces of data, and the target data is the data that has expired in the local database cache of the client; for each piece of target data, the pulling status of the target data is read from the in-memory cache of the client; if the pulling status of the target data indicates that the target data is being pulled, then wait for the pulling result of the target data; if the pulling status of the target data indicates that the target data is not being pulled, then update the pulling status of the target data to being pulled, and start pulling the target data from the server; when the target data is successfully pulled, update the target data to the local database cache, and update the pulling status of the target data to not being pulled. This method stores the pulling status of the data in the in-memory cache of the client. When the data in the local database cache expires, it decides whether to pull data from the server according to the pulling status of the data. If the pulling status of the data indicates that the target data is being pulled, there is no need to repeatedly pull the data from the server, but only wait for the pulling result of the data. On the one hand, it can avoid the client from repeatedly requesting the same data from the server, thus avoiding the waste of resources of the client and the server. On the other hand, for duplicate data within a short period of time, the client only needs to request the data from the server once, thereby reducing the instantaneous traffic of the server.

[0092] To facilitate better implementation of the data synchronization method in the embodiments of the present application, the embodiments of the present application further provide a data synchronization device. Figure 5 For the structural schematic diagram of the data synchronization device provided in the second embodiment of the present application, as Figure 5 shown, the data synchronization device 100 may include:

[0093] A determination module 11, configured to determine N1 pieces of target data to be pulled from the N pieces of data when the client needs to obtain N pieces of data, where the target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1;

[0094] A reading module 12, configured to read the pulling status of the target data from the in-memory cache of the client for each piece of target data, where the pulling status is used to indicate whether the target data is being pulled;

[0095] A data pulling module 13, configured to wait for the pulling result of the target data when the pulling status of the target data indicates that the target data is being pulled, and update the pulling status of the target data to being pulled and start pulling the target data from the server when the pulling status of the target data indicates that the target data is not being pulled;

[0096] An update module 14, configured to update the target data to the local database cache in response to successful pulling of the target data, and update the pulling status of the target data to not being in the process of pulling.

[0097] In some implementations, the update module 14 is further configured to: in response to failure of pulling the target data, update the update time of the target data stored in the local database cache to a target value, and update the pulling status of the target data to not being in the process of pulling, where the target value is used to indicate that the target data has expired.

[0098] In some implementations, the update module 14 is further configured to: if the pulling status of the target data is not read from the memory cache, add the pulling status of the target data to the memory cache and update the pulling status of the target data to being in the process of pulling. The data pulling module is further configured to: start pulling the target data from the server.

[0099] In some implementations, the local database cache stores data pulled from the server and the update time of the data, and the data in the local database cache has a validity period.

[0100] In some implementations, the determining module 11 is specifically configured to:

[0101] For each of the N pieces of data, determine whether the data is stored in the local database cache;

[0102] If the data is stored in the local database cache, determine whether the data has expired according to the update time and the data validity period of the data stored in the local database cache. If the data has expired, determine the data as target data;

[0103] If the data is not stored in the local database cache, determine that the data has expired and determine the data as target data.

[0104] In some implementations, the update module 14 is further configured to: after the determining module 11 determines N1 pieces of target data to be pulled from the N pieces of data, modify and update the update time of the target data stored in the local database cache to the current time.

[0105] In some implementations, the client uses an optimistic update method to modify and update the update time of the target data stored in the local database cache to the current time.

[0106] In some implementations, the operation of reading the pulling status of the target data from the memory cache of the client is performed asynchronously with the operation of modifying and updating the update time of the target data stored in the local database to the current time.

[0107] In some implementations, the least recently used (LRU) page replacement algorithm is adopted to manage the cache space of the memory cache of the client.

[0108] In some implementations, the update module 14 is specifically configured to:

[0109] Write the pulled target data into the local database cache and update the update time of the target data.

[0110] It should be understood that the device embodiments and the method embodiments can correspond to each other, and similar descriptions can refer to the method embodiments. To avoid repetition, they are not elaborated here.

[0111] In the foregoing, the device 100 of the embodiments of the present application has been described from the perspective of functional modules in combination with the accompanying drawings. It should be understood that the functional modules can be implemented in the form of hardware, can also be implemented by instructions in software form, or can be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiments in the embodiments of the present application can be completed by the integrated logic circuit in the hardware in the processor and / or instructions in software form. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. Optionally, the software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps in the above method embodiments.

[0112] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of the overall module or unit including the functions of the module or unit.

[0113] The embodiments of the present application further provide a terminal device. Figure 6 As a schematic structural diagram of the terminal device provided in Embodiment 3 of the present application, as Figure 6As shown in the figure, the terminal device 200 may include: a processor 201 with one or more processing cores, a memory 202 of one or more computer-readable storage media, and a computer program stored in the memory 202 and executable on the processor. Among them, the processor 201 is electrically connected to the memory 202. Those skilled in the art can understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, and it may include more or fewer components than shown in the figure, or combine some components, or have different component arrangements.

[0114] The processor 201 is the control center of the terminal device 200, connecting various parts of the entire terminal device 200 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 202, and by calling data stored in the memory 202, it executes various functions of the terminal device 200 and processes data, thereby performing overall processing on the terminal device 200.

[0115] In the embodiment of the present application, the processor 201 in the terminal device 200 will load the instructions corresponding to the processes of one or more application programs into the memory 202 according to the following steps, and the processor 201 will run the application programs stored in the memory 202, so as to achieve the following functions: when the client needs to obtain N data, determine N1 target data to be pulled from the N data, where the target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1; for each target data, read the pulling status of the target data from the memory cache of the client, where the pulling status is used to indicate whether the target data is being pulled; if the pulling status of the target data indicates that the target data is being pulled, wait for the pulling result of the target data; if the pulling status of the target data indicates that the target data is not being pulled, update the pulling status of the target data to being pulled, and start pulling the target data from the server; in response to the successful pulling of the target data, update the target data to the local database cache, and update the pulling status of the target data to not being pulled.

[0116] For the specific implementation of each of the above operations, reference can be made to the previous embodiments, and details will not be repeated here.

[0117] In some embodiments, the processor 201 may include, but is not limited to: a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like.

[0118] In some embodiments of the present application, the memory 202 includes, but is not limited to: volatile memory and / or non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus random access memory (DR RAM).

[0119] Optionally, as Figure 6 shown, the terminal device 200 further includes: a display screen 203, a radio frequency circuit 204, an audio circuit 205, an input unit 206, and a power supply 207. Among them, the processor 201 is electrically connected to the display screen 203, the radio frequency circuit 204, the audio circuit 205, the input unit 206, and the power supply 207 respectively. Those skilled in the art can understand that Figure 6 the computer device structure shown in

[0120] The display screen 203 is used to display images, videos, etc. The display screen 203 includes a display panel, and the display panel can adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light-emitting diode (QLED), etc. The display panel can be used to display the information input by the user or the information provided to the user, as well as various graphical user interfaces of the computer device, and these graphical user interfaces can be composed of graphics, texts, icons, videos, and any combination thereof.

[0121] Optionally, the display screen 203 may further include a touch panel. Correspondingly, the display screen 203 can be a touch display screen. The touch panel can be used to collect the touch operations of the user on or near it (such as the operations of the user using any suitable object or accessory such as a finger or a stylus on or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute the corresponding program. Optionally, the touch panel can include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the touch orientation of the user, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the processor 201, and can receive the commands sent by the processor 201 and execute them. The touch panel can cover the display panel. After the touch panel detects a touch operation on or near it, it is transmitted to the processor 201 to determine the type of touch event. Subsequently, the processor 201 provides a corresponding visual output on the display panel according to the type of touch event. In the embodiments of the present application, the touch panel and the display panel can be integrated into a touch display screen to implement the input and output functions. However, in some embodiments, the touch panel and the display panel can be implemented as two independent components to implement the input and output functions. That is, the touch display screen can also be used as a part of the input unit 206 to implement the input function.

[0122] The radio frequency circuit 204 can be used to receive and transmit radio frequency signals to establish wireless communication with a network device or other computer devices through wireless communication, and receive and transmit signals with the network device or other computer devices.

[0123] The audio circuit 205 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 205 can convert the received audio data into an electrical signal and transmit it to the speaker, which converts it into a sound signal for output. On the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 205, converted into audio data, and then the audio data is output to the processor 201 for processing. After that, it is sent to another computer device, for example, through the radio frequency circuit 204, or the audio data is output to the memory 202 for further processing. The audio circuit 205 may also include an earphone jack to provide communication between the peripheral earphone and the computer device.

[0124] The input unit 206 can be used to receive input digital, character information, or object feature information (such as fingerprint, iris, face information, etc.), and generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function controls.

[0125] The power supply 207 is used to supply power to each component of the terminal device 200. Optionally, the power supply 207 can be logically connected to the processor 201 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 207 may also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator. The power management system can also be used to monitor parameters such as battery capacity, battery cycle times, and battery health status (leakage, impedance).

[0126] Although Figure 6 not shown in the figure, the terminal device 200 may also include a camera, a sensor component, a Wi-Fi module, a Bluetooth module, etc., which will not be elaborated here. The sensors can include a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, etc.

[0127] It should be understood that each component in the terminal device is connected through a bus system. Among them, the bus system includes not only a data bus, but also a power bus, a control bus, and a status signal bus.

[0128] This application also provides a computer storage medium, on which a computer program is stored. When the computer program is executed by the computer, the computer can execute the methods in the above method embodiments. Or rather, this application embodiment also provides a computer program product containing instructions. When the instructions are executed by the computer, the computer executes the methods in the above method embodiments.

[0129] The present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the corresponding process in the method for controlling the user position in the virtual scene in the embodiments of the present application. For the sake of brevity, it will not be elaborated here.

[0130] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or module can be in electrical, mechanical, or other forms.

[0131] The modules described as separate components may or may not be physically separated. The components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. For example, in each embodiment of the present application, the functional modules can be integrated in a processing module, or each module can exist physically alone, or two or more modules can be integrated in one module.

[0132] The above are only the specific implementation manners of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A data synchronization method, characterized in that, The method includes: When the client needs to obtain N data, determine N1 target data to be pulled from the N data, where the target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1; For each target data, read the pull status of the target data from the memory cache of the client, where the pull status is used to indicate whether the target data is being pulled; If the pull status of the target data indicates that the target data is being pulled, wait for the pull result of the target data; If the pull status of the target data indicates that the target data is not being pulled, update the pull status of the target data to being pulled, and start pulling the target data from the server; In response to the successful pull of the target data, update the target data to the local database cache, and update the pull status of the target data to not being pulled.

2. The method according to claim 1, wherein The method further includes: In response to the failure of pulling the target data, update the update time of the target data stored in the local database cache to a target value, and update the pull status of the target data to not being pulled, where the target value is used to indicate that the target data has expired.

3. The method according to claim 1, wherein The method further includes: If the pull status of the target data is not read from the memory cache, add the pull status of the target data to the memory cache, update the pull status of the target data to being pulled, and start pulling the target data from the server.

4. The method according to claim 1, wherein The local database cache stores the data pulled from the server and the update time of the data, and the data in the local database cache has a validity period.

5. The method according to claim 4, wherein Determining N1 target data to be pulled from the N data includes: For each of the N data, determine whether the data is stored in the local database cache; If the data is stored in the local database cache, determine whether the data has expired according to the update time and data validity period of the data stored in the local database cache. If the data has expired, determine the data as target data; If the data is not stored in the local database cache, determine that the data has expired and determine the data as target data.

6. The method according to any one of claims 1-5, characterized in that, After determining N1 target data to be pulled from the N data, it further includes: Modify and update the update time of the target data stored in the local database cache to the current time.

7. The method according to claim 6, characterized in that, The client uses an optimistic update method to modify and update the update time of the target data stored in the local database cache to the current time.

8. The method according to claim 6, characterized in that The operation of reading the pull status of the target data from the memory cache of the client and the operation of modifying and updating the update time of the target data stored in the local database to the current time are executed asynchronously.

9. The method according to any one of claims 1-5, characterized in that The cache space of the memory cache of the client is managed using the Least Recently Used (LRU) page replacement algorithm.

10. The method according to any one of claims 1-5, characterized in that, When the target data is successfully pulled, updating the target data to the local database cache includes: Write the pulled target data to the local database cache and update the update time of the target data.

11. A data synchronization device, characterized in that, It includes: A determination module, configured to determine N1 target data to be pulled from the N data when the client needs to obtain N data, where the target data is the data that has expired in the local database cache of the client, and N is an integer greater than 1; A reading module, configured to read the pulling status of the target data from the memory cache of the client for each target data, where the pulling status is used to indicate whether the target data is being pulled; A data pulling module, configured to wait for the pulling result of the target data when the pulling status of the target data indicates that the target data is being pulled, and update the pulling status of the target data to being pulled and start pulling the target data from the server when the pulling status of the target data indicates that the target data is not being pulled; An update module, configured to update the target data to the local database cache and update the pulling status of the target data to not being pulled in response to successful pulling of the target data.

12. A terminal device, characterized in that, It includes: A processor and a memory, where the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that, For storing a computer program, which causes a computer to execute the method according to any one of claims 1 to 10.