Data updating method and device, storage medium and electronic device

By maintaining the effectiveness of cached data when data is updated, the problem of no data is accessible during data updates is solved, resulting in database crashes due to reduced database pressure and improved system stability.

CN119848056APending Publication Date: 2025-04-18QINGDAO HAIER TECH +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411929284.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-25
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

There is no data to access when data is updated, which causes the database to crash easily.

Method used

In the process of updating the second data in the cache in the server using the first data in the target database, the validity of the second data in the cache is maintained, and after the first data is successfully written to the cache, the validity of the first data and the second data is determined.

Benefits of technology

Reduces the frequency of accessing the database, reduces the pressure on the database, and solves the problem of no data to be accessible when data is updated, causing database crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119848056A_ABST
    Figure CN119848056A_ABST
Patent Text Reader

Abstract

The invention discloses a data updating method and device, a storage medium and an electronic device, and relates to the technical field of smart homes.The data updating method comprises the steps that in the process that first data in a target database is used for updating second data in a cache in a server, the validity of the second data in the cache is maintained, the first data and the second data are different versions of data with the same data identifier; and after the first data is successfully written into the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid. By adopting the scheme, the problem that the database is easy to crash due to the fact that no data can be accessed during data updating is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of smart home technology, and more specifically, to a data updating method and device, a storage medium, and an electronic device. Background Art

[0002] With the development of Internet technology, users have higher and higher requirements for the speed and efficiency of data access. Cache is a temporary storage area for storing data, and its access speed is usually faster than that of primary storage (such as disk or database). By using cache to obtain data, the system can reduce the number of accesses to primary storage, thereby improving data access efficiency.

[0003] However, when a large amount of cached data expires at the same time or the cache service fails, and no new data is updated successfully, and there is no accessible data version, all requests will directly access the database, causing a sudden increase in database pressure and possibly causing a system crash. This usually happens when data expires at the same time, or when the memory data structure storage (such as Redis) fails and crashes. Or when the cache of a hot data expires, but there are a large number of requests to access the data at this time, these requests will directly access the database due to the invalidation of the cache, resulting in an increase in database load.

[0004] In the related technology, there is a problem that no data can be accessed when data is updated, which causes the database to crash easily. No effective solution has been proposed yet.

[0005] Therefore, it is necessary to improve the related technology to overcome the above-mentioned defects in the related technology. Summary of the invention

[0006] The embodiments of the present application provide a data updating method and device, a storage medium, and an electronic device to at least solve the problem that no data can be accessed during data updating, which may cause the database to crash easily.

[0007] According to one aspect of an embodiment of the present application, a data updating method is provided, comprising: in the process of updating second data in a cache in a server using first data in a target database, maintaining the validity of the second data in the cache, wherein the first data and the second data are different versions of data with the same data identifier; after successfully writing the first data to the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid.

[0008] In an exemplary embodiment, the method further includes: when a data access request is obtained and there are N caches in the server, loopingly performing the following operations until data with a target data identifier is obtained, and returning the data with the target data identifier, wherein the data access request is used to obtain the data with the target data identifier, and when the following operations are performed for the first time, i is equal to 1, and N is an integer greater than or equal to 2: determining whether data with the target data identifier is found in the i-th cache among the N caches; when data with the target data identifier is found in the i-th cache, obtaining data with the target data identifier from the i-th cache; when data with the target data identifier is not found in the i-th cache and i is not equal to N, updating i to i+1; when data with the target data identifier is not found in the i-th cache and i is equal to N, obtaining data with the target data identifier from the target database.

[0009] In an exemplary embodiment, the method further includes: when data with the target data identifier is found in the i-th cache and i is not equal to 1, writing the data with the target data identifier into one or more caches before the i-th cache among the N caches, and determining that the data with the target data identifier in the one or more caches has the validity; or when data with the target data identifier is found in the i-th cache, the number of times the data with the target data identifier is searched in the i-th cache is greater than a first preset number, and i is not equal to 1, writing the data with the target data identifier into one or more caches before the i-th cache among the N caches, and determining that the data with the target data identifier in the multiple caches has the validity.

[0010] In an exemplary embodiment, after obtaining the data with the target data identifier from the target database, the method further includes: writing the data with the target data identifier into the N caches, and determining that the data with the target data identifier in the N caches has the validity; or when the number of searches for the data with the target data identifier in the target database is greater than a second preset number of times, writing the data with the target data identifier into the N caches, and determining that the data with the target data identifier in the N caches has the validity.

[0011] In an exemplary embodiment, the method further includes: when the versions of the data with the target data identifier in the p-th cache among the N caches are inconsistent with the data with the target data identifier in the j-th cache among the N caches, using the latest version of the data with the target data identifier in the target database to update the data with the target data identifier in the p-th cache and the j-th cache, wherein p is a positive integer less than or equal to N, and j is a positive integer less than or equal to N.

[0012] In an exemplary embodiment, the method further includes: obtaining historical operation records corresponding to a target account, wherein the target account is an account of a target application, and the server is a server corresponding to the target application; predicting multiple data based on the historical operation records, and predicting an access frequency corresponding to each of the multiple data; and writing the multiple data into N caches of the server based on the access frequency of each of the multiple data.

[0013] In an exemplary embodiment, the method further includes: when the load of the server is greater than a preset threshold, increasing the data stored in the cache of the server; when the load of the server is less than the preset threshold, reducing the data stored in the cache of the server.

[0014] According to another aspect of an embodiment of the present application, a data updating device is provided, comprising: a processing module for maintaining the validity of second data in a cache in a server while using first data in a target database to update the second data in the cache, wherein the first data and the second data are different versions of data with the same data identifier; a writing module for determining that the first data in the cache is valid and that the second data in the cache is not valid after the first data is successfully written into the cache.

[0015] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein the computer program is configured to execute the above-mentioned data updating method when running.

[0016] According to another aspect of the embodiments of the present application, there is further provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, wherein the processor is configured to execute the above-mentioned data updating method through the computer program.

[0017] According to another aspect of the embodiments of the present application, a computer program product is provided, including a computer program, and the above-mentioned data updating method is implemented when the computer program is executed by a processor.

[0018] Through the present application, when the first data is used to update the second data in the cache of the server, the validity of the second data is maintained, ensuring that the second data can still be found when the data is updated, and after the first data is successfully written, it is ensured that the first data can be found, thereby reducing the frequency of accessing the database, reducing the pressure on the database, and solving the problem that there is no data to access when the data is updated, which makes the database prone to crash. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0021] Figure 1 is a hardware environment schematic diagram of a data updating method according to an embodiment of the present application;

[0022] Figure 2 is a flow chart of a data updating method according to an embodiment of the present application;

[0023] Figure 3 is a timing diagram of an optional data update process according to an embodiment of the present application;

[0024] Figure 4 is a structural block diagram of an optional data updating device according to an embodiment of the present application;

[0025] Figure 5 It is a structural block diagram of another optional data updating device according to an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application 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 the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] According to one aspect of an embodiment of the present application, a data update method is provided. The data update method is widely used in smart home (Smart Home), smart home, smart home device ecology, smart residential (IntelligenceHouse) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the above data update method can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.

[0029] The network may include but is not limited to at least one of the following: wired network, wireless network. The wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 may be but is not limited to a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing device, a smart dishwasher, a smart projection device, a smart TV, a smart clothes drying rack, a smart curtain, a smart audio and video, a smart socket, a smart speaker, a smart fresh air device, a smart kitchen and bathroom device, a smart bathroom device, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification device, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, etc.

[0030] In order to solve the above problems, a data updating method is provided in this embodiment, including but not limited to being applied to the whole house intelligent digital control application scenario. Figure 2 is a flow chart of a data updating method according to an embodiment of the present application, the flow includes the following steps S202-S204:

[0031] Step S202: in the process of using the first data in the target database to update the second data in the cache of the server, maintaining the validity of the second data in the cache, wherein the first data and the second data are different versions of data with the same data identifier;

[0032] Optionally, the data identifier is used to identify data, and different types of data have different data identifiers, for example, the data identifier of A data is different from the data identifier of B data.

[0033] Optionally, the second data may include multiple data, the first data may include multiple data, and the version number of the first data is greater than the version number of the second data, that is, the version of the first data is an updated version of the second data.

[0034] Optionally, validity is used to indicate that the data is allowed to be found.

[0035] Step S204: after the first data is successfully written into the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid.

[0036] Optionally, when the server obtains an update instruction to update the data in the cache, the server first obtains the latest data version (first data) from the target database and writes the first data into the cache, but before confirming that the first data is written successfully, the old data version (second data) in the cache remains "valid". This means that if a client requests data before confirming that the first data is written successfully, the server will return the old data version (second data) without causing data access interruption or direct request impact on the database.

[0037] Optionally, after the first data is successfully written, the second data in the cache is deleted within a preset time.

[0038] It should be noted that the above steps ensure the continuous availability of the cache and avoid the problem of cache avalanche or breakdown by introducing a delayed failure (or soft failure) mechanism when updating data.

[0039] The above steps maintain the validity of the second data when the first data is used to update the second data in the cache of the server, ensure that the second data can still be found when the data is updated, and ensure that the first data can be found after the first data is successfully written, thereby reducing the frequency of accessing the database, reducing the pressure on the database, and solving the problem that there is no data to access when the data is updated, which makes the database prone to crash.

[0040] In an exemplary embodiment, the method further includes the following steps: when a data access request is obtained and the server has N caches, the following steps S11 to S14 are executed in a loop until data with a target data identifier is obtained, and the data with the target data identifier is returned, wherein the data access request is used to obtain the data with the target data identifier, and when the following operations are executed for the first time, i is equal to 1, and N is an integer greater than or equal to 2:

[0041] Step S11: determining whether data having the target data identifier is found in the i-th cache among the N caches;

[0042] Step S12: when data with the target data identifier is found in the i-th cache, acquiring the data with the target data identifier from the i-th cache;

[0043] It should be noted that if data with the target data identifier is found in the current cache (the i-th cache), the system will directly read the data with the target data identifier from this cache and return it to the client without accessing a deeper cache or database, thereby greatly improving data access speed and server efficiency.

[0044] Step S13: if no data with the target data identifier is found in the i-th cache and i is not equal to N, update i to i+1;

[0045] That is to say, when the data with the target data identifier is not found in the i-th cache, the next level of cache, that is, the i+1-th cache, is searched for the data with the target data identifier.

[0046] Step S14: when no data with the target data identifier is found in the i-th cache and i is equal to N, the data with the target data identifier is obtained from the target database.

[0047] It should be noted that if data with the target data identifier is not found in all caches (that is, when i is equal to N), the system will read the data directly from the database. This is the last line of defense in the caching strategy to ensure the availability and accuracy of the data.

[0048] Optionally, when the server receives an access request for a specific data identifier (target data identifier), it starts searching for data with the target data identifier from the first cache (i=1, i is a variable used to distinguish cache levels) until the data with the target data identifier is found or all caches are traversed and the data with the target data identifier is obtained from the database.

[0049] It should be noted that the priority of the i-th cache is greater than the priority of the i+1-th cache. For example, the priority of the server's local cache is greater than the priority of the first cache middleware. The speed at which data is returned to the client from the server's local cache is faster than the cache speed from the first cache middleware, where the cache middleware is used to cache data.

[0050] It should be noted that the above steps describe a multi-level cache data access and acquisition strategy, which obtains data by looping through different levels of cache, combining the efficiency of cache with the authority of database, and achieving high performance and high consistency of data access. This strategy is particularly suitable for scenarios that need to process a large number of high-concurrency requests, which can significantly reduce the frequency of direct access to the database, reduce the database load, and provide fast data response.

[0051] It should be noted that step S12, step S13, and step S14 are steps performed under different circumstances, and there is no order of execution when executing the embodiments of the present application.

[0052] In an exemplary embodiment, the method further includes the following steps S21 or S22:

[0053] Step S21: when data with the target data identifier is found in the i-th cache and i is not equal to 1, the data with the target data identifier is written into one or more caches before the i-th cache among the N caches, and it is determined that the data with the target data identifier in the one or more caches has the validity;

[0054] Optionally, when the requested data is found in the i-th cache (where i>1, meaning it is not the cache closest to the client, i.e., it is not the local cache of the server), the system not only returns the data with the target data identifier, but also writes the data to all caches before the i-th cache (there may be only one cache or there may be multiple caches), i.e., caches that are closer to the client.

[0055] It should be noted that through the above steps, hot data or data that is frequently accessed recently can be written into a cache with a higher priority in advance, reducing the number of access levels for the same data in the future, thereby improving data access speed and efficiency. At the same time, the system will ensure the validity of the data in these higher priority caches to ensure that subsequent accesses can correctly obtain the latest data.

[0056] Step S22: When data with the target data identifier is found in the i-th cache, the number of times the data with the target data identifier is searched in the i-th cache is greater than a first preset number of times, and i is not equal to 1, the data with the target data identifier is written into one or more caches before the i-th cache among the N caches, and it is determined that the data with the target data identifier in the multiple caches have the validity.

[0057] Optionally, if the data with a certain target data identifier is accessed more than a first preset number of times in the i-th level cache (where i>1) within a certain period of time (such as the data is accessed more than 5 times within 1 minute), the system will identify the data with the target data identifier as a hot data. At this time, the system not only writes the data to the cache before the i-th cache (there may be only one cache or multiple caches), but also ensures that the written data with the target data identifier can be found in these multiple caches, so that subsequent requests can access it more quickly, which helps to dynamically optimize the cache layout, ensure that hot data can be accessed quickly, reduce the burden on the back-end database, and improve the performance and response speed of the entire system.

[0058] It should be noted that through the above steps, the system can intelligently identify and process hot data, and accelerate data access by preheating the data to a cache with a higher priority, that is, writing the data to a cache with a higher priority in advance before the next access to the data. This mechanism is particularly suitable for high-concurrency Internet services, which can significantly improve user experience and reduce the consumption of storage resources.

[0059] In an exemplary embodiment, after acquiring the data with the target data identifier from the target database, the method further includes the following steps S31 or S32:

[0060] Step S31: writing the data with the target data identifier into the N caches, and determining whether the data with the target data identifier in the N caches has the validity;

[0061] Optionally, when data with the target data identifier cannot be found in the multi-level cache, the system will directly obtain the data from the most authoritative data source, the target database. After obtaining the data from the target database, the system will write the data into all caches.

[0062] It should be noted that, through the above steps, the data with the target data identifier will not only be stored in the cache with the lowest priority (which may be the cache closest to the database), but will also be written to all other caches, and it is guaranteed that the data can be found after being written, thereby significantly improving the data access speed, because future access requests for data with the target data identifier can quickly find the data in a cache with a higher priority without having to access the database again.

[0063] Step S32: When the number of searches for data with the target data identifier in the target database is greater than a second preset number of searches, the data with the target data identifier is written into the N caches, and it is determined that the data with the target data identifier in the N caches has the validity.

[0064] Optionally, the first preset number of times and the second preset number of times may be the same.

[0065] Optionally, the system will record the number of times data with the target data identifier is found from the target database within a certain period of time. When this number exceeds a second preset number (such as more than 6 times within 1 minute), the system will confirm the data with the target data identifier as a hot spot data, and write the data with the target data identifier into all caches, and ensure that the written data can be found.

[0066] It should be noted that this access frequency-based caching strategy helps identify and process hot data, that is, data that is frequently accessed in a short period of time. By writing hot data into all caches, it can significantly reduce the number of future requests for data with the target data identifier that directly access the database, reducing the database load and improving the system's response speed and stability.

[0067] It should be noted that through the above steps, more intelligent management of data access can be achieved, which not only ensures fast access to data in multi-level caches, but also dynamically adjusts cache strategies according to data popularity, reduces unnecessary database access times, and thus improves the performance and efficiency of the entire system. This mechanism is particularly suitable for scenarios that handle a large number of user requests, which can effectively improve user experience while reducing the pressure on the backend database.

[0068] In an exemplary embodiment, the method further includes the following steps: when the versions of the data with the target data identifier in the p-th cache among the N caches are inconsistent with the data with the target data identifier in the j-th cache among the N caches, use the latest version of the data with the target data identifier in the target database to update the data with the target data identifier in the p-th cache and the j-th cache, wherein p is a positive integer less than or equal to N, and j is a positive integer less than or equal to N.

[0069] Optionally, when the system detects that the data versions with the same target data identifier are inconsistent in any two caches among N caches - the pth cache and the jth cache (where p and j are both positive integers less than or equal to N, and p is not equal to j), the system will not immediately update the data, but will first actively check and compare the versions of the data with the target data identifier in all caches to identify whether there are version inconsistencies in all caches except the pth cache and the jth cache. Then, the latest version of the data with the target data identifier is obtained from the target database. After obtaining the latest version of the data with the target data identifier from the database, the system will use the latest version of the data with the target data identifier to update all caches involving version inconsistencies, including but not limited to the pth cache and the jth cache. The purpose of this is to eliminate data version differences, ensure that the data in all caches is up to date, and avoid problems caused by data expiration or inconsistency.

[0070] It should be noted that through the above steps, the problem of inconsistent data versions can be effectively solved in the multi-level cache architecture, avoiding logical errors or reduced user experience caused by inconsistent data, while reducing frequent access to the database, reducing the database load, and improving the overall performance and stability of the system. This cache synchronization strategy based on version control is particularly suitable for application scenarios that require high data consistency and real-time performance, such as financial transactions, real-time data analysis, etc.

[0071] In an exemplary embodiment, the method further comprises the following steps S41-S43:

[0072] Step S41: Acquire historical operation records corresponding to a target account, wherein the target account is an account of a target application, and the server is a server corresponding to the target application;

[0073] Step S42: predicting a plurality of data according to the historical operation records, and predicting the access frequency corresponding to each of the plurality of data;

[0074] Step S43: writing the multiple data into the N caches of the server according to the access frequency of each data in the multiple data.

[0075] Optionally, historical operation records of a specific account (target account) in the target application are collected. These records may include the user's search history, browsing behavior, purchase history, or other interactions with the target application in the target application. By analyzing these historical data, the system can gain insights into the user's behavior patterns and interests, providing a basis for subsequent prediction and caching strategies, wherein the target application is the client that issues the data request.

[0076] Optionally, after collecting historical operation records, the system uses data analysis and machine learning techniques to predict multiple data that the user may be interested in or will access in the future by identifying the periodicity, trend or pattern of the user's access pattern and the preference for specific types of data. At the same time, the system also predicts the access frequency of these data in the future, which helps determine which data should be pre-cached first.

[0077] Optionally, based on the predicted access frequency, the system will pre-write the predicted multiple data into the N caches of the server. Data with higher access frequency will be placed in a higher priority cache first to ensure that data with higher access frequency can be returned to the client faster. Data with lower access frequency may be placed in a lower priority cache or only kept in the database, which helps to optimize the use of cache space and avoid resource waste.

[0078] It should be noted that the above steps implement a pre-caching strategy based on user behavior prediction, which can predict and cache the data that may be needed in advance, reduce user waiting time, and improve user experience. It can dynamically adjust the caching strategy according to the access frequency of data, effectively utilize cache resources, and improve system performance. At the same time, it reduces the burden on the database, reduces direct access to the database in high-concurrency scenarios, and enhances the stability and reliability of the system. It is particularly suitable for Internet applications that require real-time response and personalized services.

[0079] In an exemplary embodiment, the method further comprises the following steps S51-S52:

[0080] Step S51: when the load of the server is greater than a preset threshold, increasing the data stored in the cache of the server;

[0081] Optionally, when the server load (e.g., CPU usage, network request volume, response time, etc.) reaches above a pre-set threshold, it indicates that the system is experiencing a high concurrency or high resource demand state. In this case, the system reduces the burden on the server by increasing the amount of data stored in the cache. Specifically, more data is loaded from the database into the cache, especially data that is accessed more frequently or related to the current request. This can reduce direct access to the database because many requests can directly obtain data from the cache, thereby alleviating the processing pressure on the server and improving its response speed and efficiency.

[0082] Step S52: When the load of the server is less than the preset threshold, reduce the data stored in the cache of the server.

[0083] Optionally, when the server load is below a preset threshold, it indicates that the system's resource usage is relatively loose, or the current cache strategy may exceed actual demand. At this time, the system will reduce the amount of data stored in the cache to optimize resource usage. This may include removing less frequently accessed data from the cache, or data that is no longer in a hot state. Doing so helps free up cache space and reduce unnecessary memory usage, thereby improving the overall resource utilization of the system and reducing operating costs.

[0084] It should be noted that through the above steps, an adaptive cache management mechanism is implemented, which can dynamically adjust the cache strategy according to the server load. When the load is high, the response speed and system stability are improved by increasing the cache data; when the load is low, the resource usage is optimized and waste is avoided by reducing the cache data. This mechanism is very suitable for application scenarios with large load fluctuations, such as holiday promotions on e-commerce websites and hot events on social media. It can effectively balance system performance and resource utilization efficiency and provide more stable and efficient services.

[0085] Obviously, the above-described embodiments are only embodiments of a part of the present invention, rather than all embodiments. In order to better understand the above method, the above process is described below in conjunction with embodiments, but it is not intended to limit the technical solutions of the embodiments of the present invention, specifically:

[0086] Figure 3 The following diagram illustrates an optional sequence of data update processes, where there are two caches before the database: the local cache of the server and the cache middleware. The details are as follows:

[0087] First, when a user accesses a browser or application (Application, referred to as app), he or she will request specific data (i.e., the data with the target data identifier mentioned above). When requesting data, a data request identifier will be formed based on the data identifier and the timestamp of the request;

[0088] Next, in the local cache of the server, first search according to the data identifier and timestamp, and if there is data with the target data identifier, it will be returned;

[0089] If the data request is not found in the local cache, the cache middleware (i.e., the next level cache) is queried, and the data with the target data identifier is cached in the local cache of the server;

[0090] If the target data cannot be found in the cache middleware, the data with the target data identifier is searched in the database and cached in the local cache of the server and the cache middleware;

[0091] Among them, in the query requesting local cache and cache middleware, the data identifier is divided into two parts, the first part is the unique identifier of the data, and the other part is the timestamp. During the update process, there will be two versions at the same time. When the new version cache is written, the previous version will be invalidated with a delay. This mechanism can effectively avoid cache avalanche and cache invalidation problems. At the same time, during the data update process, the cache middleware will record hot data, and the database will synchronously push the server and cache middleware to preheat the cache of hot data.

[0092] It should be noted that the present application also has the following advantages: (1) In a multi-level cache, the local cache of the server and the cache middleware both have data with target data identifiers, which has advantages in terms of effectiveness and availability of data response; (2) Due to the timestamp-based version mechanism, there is no vacuum period when acquiring and updating data, which can effectively prevent cache failure and cache avalanche from impacting the storage layer, and can effectively improve the availability and stability of the service; (3) The multi-level cache preheating mechanism based on hotspot detection can avoid the impact of hotspot data on the cache. By effectively identifying hotspot data, pre-caching is performed in advance. This can effectively reduce the length of service response, reduce service glitches, and effectively improve service stability.

[0093] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.

[0094] In the present embodiment, a data updating device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made are omitted. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and contemplated.

[0095] Figure 4 is a structural block diagram of a data updating device according to an embodiment of the present application, the device comprising:

[0096] A processing module 42, configured to maintain validity of second data in a cache in a server in a process of updating the second data in the cache with first data in a target database, wherein the first data and the second data are different versions of data having the same data identifier;

[0097] The writing module 44 is used to determine that the first data in the cache is valid and that the second data in the cache is not valid after the first data is successfully written into the cache.

[0098] The above-mentioned device maintains the validity of the second data when using the first data to update the second data in the cache of the server, ensures that the second data can still be found when the data is updated, and ensures that the first data can be found after the first data is successfully written, thereby reducing the frequency of accessing the database, reducing the pressure on the database, and solving the problem that there is no data to access when the data is updated, which makes the database prone to crash.

[0099] In an exemplary embodiment, Figure 5It is a structural block diagram of another data updating device according to an embodiment of the present application, and the above-mentioned device also includes: an acquisition module 52, which is used to, when a data access request is obtained and there are N caches in the server, cyclically perform the following operations until data with a target data identifier is obtained, and return the data with the target data identifier, wherein the data access request is used to obtain the data with the target data identifier, and when the following operations are performed for the first time, i is equal to 1 and N is an integer greater than or equal to 2: determine whether the data with the target data identifier is found in the i-th cache among the N caches; when the data with the target data identifier is found in the i-th cache, obtain the data with the target data identifier from the i-th cache; when the data with the target data identifier is not found in the i-th cache and i is not equal to N, update i to i+1; when the data with the target data identifier is not found in the i-th cache and i is equal to N, obtain the data with the target data identifier from the target database.

[0100] In an exemplary embodiment, the write module 44 is further used to, when data with the target data identifier is found in the i-th cache and i is not equal to 1, write the data with the target data identifier into one or more caches before the i-th cache among the N caches, and determine that the data with the target data identifier in the one or more caches has the validity; or when data with the target data identifier is found in the i-th cache, the number of times the data with the target data identifier is searched in the i-th cache is greater than a first preset number, and i is not equal to 1, write the data with the target data identifier into one or more caches before the i-th cache among the N caches, and determine that the data with the target data identifier in the multiple caches has the validity.

[0101] In an exemplary embodiment, the writing module 44 is also used to write the data with the target data identifier into the N caches, and determine that the data with the target data identifier in the N caches has the validity; or when the number of searches for the data with the target data identifier in the target database is greater than a second preset number of times, write the data with the target data identifier into the N caches, and determine that the data with the target data identifier in the N caches has the validity.

[0102] In an exemplary embodiment, the processing module 42 is also used to update the data with the target data identifier in the p-th cache among the N caches and the j-th cache using the latest version of the data with the target data identifier in the target database when the versions of the data with the target data identifier in the p-th cache among the N caches are inconsistent with the data with the target data identifier in the j-th cache among the N caches, wherein p is a positive integer less than or equal to N, and j is a positive integer less than or equal to N.

[0103] In an exemplary embodiment, the acquisition module 52 is further used to acquire the historical operation record corresponding to the target account, wherein the target account is the account of the target application, and the server is the server corresponding to the target application; Figure 5 It is a structural block diagram of another data updating device according to an embodiment of the present application, and the above-mentioned device also includes: a prediction module 54, which is used to predict multiple data based on the historical operation records, and predict the access frequency corresponding to each of the multiple data; a writing module 44, which is also used to write the multiple data into N caches of the server according to the access frequency of each of the multiple data.

[0104] In an exemplary embodiment, the processing module 42 is also used to increase the data stored in the cache of the server when the load of the server is greater than a preset threshold; and to reduce the data stored in the cache of the server when the load of the server is less than the preset threshold.

[0105] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein the computer program is configured to execute the above-mentioned data updating method when running.

[0106] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:

[0107] S1, in the process of updating second data in a cache in a server using first data in a target database, maintaining the validity of the second data in the cache, wherein the first data and the second data are different versions of data having the same data identifier;

[0108] S2: After the first data is successfully written into the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid.

[0109] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0110] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0111] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, wherein the processor is configured to execute the above-mentioned data updating method through the computer program.

[0112] Optionally, in this embodiment, the electronic device may be configured to perform the following steps through a computer program:

[0113] S1, in the process of updating second data in a cache in a server using first data in a target database, maintaining the validity of the second data in the cache, wherein the first data and the second data are different versions of data having the same data identifier;

[0114] S2: After the first data is successfully written into the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid.

[0115] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0116] According to another aspect of the embodiments of the present application, a computer program product is provided, including a computer program, and the above-mentioned data updating method is implemented when the computer program is executed by a processor.

[0117] Optionally, in this embodiment, the computer program product may be configured to perform the following steps through a computer program:

[0118] S1, in the process of updating second data in a cache in a server using first data in a target database, maintaining the validity of the second data in the cache, wherein the first data and the second data are different versions of data having the same data identifier;

[0119] S2: After the first data is successfully written into the cache, determining that the first data in the cache is valid, and determining that the second data in the cache is not valid.

[0120] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0121] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.

[0122] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A data updating method, characterized in that: include: In the process of updating second data in a cache in a server using first data in a target database, maintaining validity of the second data in the cache, wherein the first data and the second data are different versions of data having the same data identifier; After the first data is successfully written into the cache, it is determined that the first data in the cache is valid, and it is determined that the second data in the cache is not valid.

2. The data updating method according to claim 1, characterized in that: The method further comprises: When a data access request is obtained and the server has N caches, the following operations are performed cyclically until data with a target data identifier is obtained, and the data with the target data identifier is returned, wherein the data access request is used to obtain the data with the target data identifier. When the following operations are performed for the first time, i is equal to 1, and N is an integer greater than or equal to 2: Determine whether data having the target data identifier is found in the i-th cache among the N caches; When data with the target data identifier is found in the i-th cache, acquiring the data with the target data identifier from the i-th cache; If no data with the target data identifier is found in the i-th cache and i is not equal to N, update i to i+1; When the data with the target data identifier is not found in the i-th cache and i is equal to N, the data with the target data identifier is obtained from the target database.

3. The data updating method according to claim 2, characterized in that: The method further comprises: When data with the target data identifier is found in the i-th cache and i is not equal to 1, the data with the target data identifier is written into one or more caches before the i-th cache among the N caches, and it is determined that the data with the target data identifier in the one or more caches has the validity; or When data with the target data identifier is found in the i-th cache, the number of times the data with the target data identifier is searched in the i-th cache is greater than a first preset number, and i is not equal to 1, the data with the target data identifier is written into one or more caches before the i-th cache among the N caches, and it is determined that the data with the target data identifier in the multiple caches have the validity.

4. The data updating method according to claim 2, characterized in that: After acquiring the data with the target data identifier from the target database, the method further includes: Writing the data with the target data identifier into the N caches, and determining that the data with the target data identifier in the N caches has the validity; or When the number of searches for data with the target data identifier in the target database is greater than a second preset number of searches, the data with the target data identifier is written into the N caches, and it is determined that the data with the target data identifier in the N caches has the validity.

5. The data updating method according to claim 2, characterized in that: The method further comprises: When the versions of the data with the target data identifier in the p-th cache among the N caches are inconsistent with the data with the target data identifier in the j-th cache among the N caches, the data with the target data identifier in the p-th cache and the j-th cache are updated using the latest version of the data with the target data identifier in the target database, where p is a positive integer less than or equal to N, and j is a positive integer less than or equal to N.

6. The data updating method according to claim 1, characterized in that: The method further comprises: Obtaining historical operation records corresponding to a target account, wherein the target account is an account of a target application, and the server is a server corresponding to the target application; Predicting a plurality of data according to the historical operation records, and predicting an access frequency corresponding to each of the plurality of data; The multiple data are written into the N caches of the server according to the access frequency of each of the multiple data.

7. The data updating method according to claim 1, characterized in that: The method further comprises: When the load of the server is greater than a preset threshold, increasing the data stored in the cache of the server; When the load of the server is less than the preset threshold, the data stored in the cache of the server is reduced.

8. A data updating device, characterized in that: include: A processing module, configured to maintain validity of second data in a cache in a server during the process of updating the second data in the cache using first data in a target database, wherein the first data and the second data are different versions of data having the same data identifier; A writing module is used to determine that the first data in the cache is valid and that the second data in the cache is not valid after the first data is successfully written into the cache.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 7 when executed.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.