A local cache updating method, device, apparatus and storage medium
By using an auxiliary database to record update operation information in the business system database, the problems of high database pressure and untimely updates in local cache are solved, achieving efficient and timely local cache updates and ensuring data consistency and service performance.
Patent Information
- Application Number
- CN202111551233.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-12-17
AI Technical Summary
Existing technologies suffer from problems such as high database pressure, untimely caching, and additional dependency complexity when updating local caches. This is especially true in network services with high data read volumes, where it is difficult to guarantee data consistency and efficient updates.
By recording update operation information from the business system database to an auxiliary database (such as Redis) and retrieving update operation information from the auxiliary database, the local cache is updated according to type and data information, reducing direct access to the business system database. Combined with a full refresh mechanism, this ensures data consistency and timeliness.
It reduced the data processing pressure on the business system database, improved the timeliness and convenience of local cache updates, ensured data consistency, and improved the performance of network services without adding any additional dependencies.
Smart Images

Figure CN114265850B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of data processing, and particularly relates to the technical field of cache updating. BACKGROUND
[0002] At present, in some network services with large amount of data reading requests, the equipment processing data requests usually saves some business data in a local cache to improve the speed of data reading, and thus improve the performance of network services. SUMMARY
[0003] The present disclosure provides a local cache updating method, device and equipment for updating a local cache in time, and a storage medium.
[0004] According to an aspect of the present disclosure, a method for updating a local cache is provided, comprising:
[0005] obtaining current update operation information of a business system database; the current update operation information comprises: an update operation type and target business data information;
[0006] storing the current update operation information into an auxiliary database;
[0007] obtaining the current update operation information from the auxiliary database;
[0008] updating the business data cached in the local cache according to the update operation type and the target business data information of the current update operation information.
[0009] According to another aspect of the present disclosure, an updating device for a local cache is provided, comprising:
[0010] a first current update operation information obtaining module, configured to obtain current update operation information of a business system database; the current update operation information comprises: an update operation type and target business data information;
[0011] a current update operation information recording module, configured to store the current update operation information into an auxiliary database;
[0012] a second current update operation information obtaining module, configured to obtain the current update operation information from the auxiliary database;
[0013] a local cache updating module, configured to update the business data cached in the local cache according to the update operation type and the target business data information of the current update operation information.
[0014] According to another aspect of the present disclosure, an electronic device is provided, comprising:
[0015] at least one processor; and
[0016] a memory in communication with the at least one processor; wherein
[0017] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the local cache updating method of any of the above.
[0018] According to another aspect of the present disclosure, a non-transitory computer readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to perform the local cache updating method of any of the above.
[0019] According to another aspect of the present disclosure, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the local cache updating method of any of the above.
[0020] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present disclosure, nor to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0021] The accompanying drawings are used to better understand the present scheme and do not limit the present disclosure. Among them:
[0022] Figure 1 is a schematic diagram of a first embodiment of the local cache updating method provided according to the present disclosure;
[0023] Figure 2 is a schematic diagram of a second embodiment of the local cache updating method provided according to the present disclosure;
[0024] Figure 3 is a flowchart of writing update operation information into a Redis database in the present disclosure;
[0025] Figure 4 is a process diagram of updating the local cache based on the update operation information saved by Redis in the present disclosure;
[0026] Figure 5 is a schematic diagram of another embodiment of updating the local cache in the present disclosure;
[0027] Figure 6 is a schematic diagram of a first embodiment of the local cache updating device provided according to the present disclosure;
[0028] Figure 7 is a schematic diagram of a second embodiment of the local cache updating device provided according to the present disclosure;
[0029] Figure 8 is a block diagram of an electronic device for implementing a local cache updating method according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0030] Exemplary embodiments of the present disclosure are described herein with reference to the accompanying drawings, in which various details of the present disclosure are set forth to facilitate an understanding. However, it will be appreciated that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Also, it is to be understood that the description and specific examples herein are by way of illustration only and thus are not restrictive of the present disclosure.
[0031] At present, when updating a local cache, the following two methods are usually used:
[0032] One is to set a short cache time for the local memory cache, and after expiration, the corresponding database is returned to source and the result is cached again. In this method, the database needs to be returned to source, and when the cache time is short, the data processing pressure of the database will be too large and the cache effect will not be obvious. In addition, this method re-caches the data in the database at regular intervals, so when data updates occur in the database, the local cache cannot be updated in a timely manner.
[0033] Another way is to use the form of message broadcasting, that is, multiple devices subscribe to the same message at the same time, and when the data changes, the local cache is updated. This method is relatively complex to implement, and the introduction of message broadcasting will increase additional dependencies.
[0034] To solve the above problems, the present disclosure provides a local cache updating method, device, electronic device and storage medium. First, the local cache updating method provided by the present disclosure is described.
[0035] Referring to Figure 1 , Figure 1 is a schematic diagram of a first embodiment of a local cache updating method according to the present disclosure, which can include the following steps:
[0036] Step S110, obtaining current update operation information of a business system database; the current update operation information includes: update operation type and target business data information.
[0037] In the present embodiment, the business system database can be Oracle, MySQL, etc., which is not specifically limited in the present disclosure.
[0038] The update operation type can include modification, addition (insertion), deletion, and the like of the business data. Correspondingly, if the update operation type is data modification, the target business data information can include the identifier of the business data to be modified (e.g., the ID of the business data), and the modification content, which can be the modified business data. Of course, the target business data information can also include the storage location of the business data to be modified in the business system database, and the like. If the update operation type is data addition, the target business data information can include the identifier of the business data to be added, the storage location of the business data to be added in the business system database, and the specific content of the business data to be added. If the update operation type is data deletion, the target business data information can include the identifier of the business data to be deleted and the storage location of the business data to be deleted in the business system database. The above examples are only for illustration of the embodiments of the present disclosure and do not limit the present disclosure.
[0039] In step S120, the current update operation information is stored in the auxiliary database.
[0040] In the embodiments of the present disclosure, the related code can be written in advance in the business system database code, so that when there is data update in the business system database, the corresponding update operation information is automatically cached in the auxiliary database.
[0041] In an embodiment of the present disclosure, the auxiliary database can be a key-value storage system (e.g., a Redis database). Therefore, when the update operation information is cached in the auxiliary database, the update operation information can be stored as a value corresponding to a key.
[0042] In step S130, the current update operation information is obtained from the auxiliary database.
[0043] In the embodiments of the present disclosure, the auxiliary database can be a cache database, that is, the data in the business system database can be cached. Generally, the business system database (e.g., MySQL) can be used to persistently store data to a hard disk, and has strong data processing function, but the data reading speed is slow, so when the data reading amount of the business is large, the business system database will bear a large pressure. The use of the auxiliary database can well avoid this situation. As described above, in the embodiments of the present disclosure, the auxiliary database can be a cache database, which has a fast data reading speed, so that when the local cache is updated, the update operation information is read from the auxiliary database, which can well reduce the data reading pressure of the business system database.
[0044] As described above, in an embodiment of the present disclosure, when the auxiliary database caches the update operation information, the update operation information can be stored in the form of key-value. Therefore, when the local cache on the device needs to be updated, the corresponding update operation information can be obtained based on the information of the key.
[0045] In step S140, the cached service data in the local cache is updated according to the update operation type and the target service data information of the current update operation information.
[0046] As described above, in an embodiment of the present disclosure, the service data update operation type can include modification, addition and deletion of service data. If the update operation type is data modification, the service data to be modified in the local cache can be determined based on the to-be-modified service data identifier in the corresponding target service data information, and the to-be-modified service data can be modified based on the modified service data included in the modification content. If the update operation type is data addition, the to-be-added data can be inserted in the corresponding position in the local cache based on the identifier of the to-be-added service data, the storage position of the to-be-added service data in the service system database and the specific content of the to-be-added service data. If the update operation type is data deletion, the corresponding storage position in the local cache can be found based on the identifier of the to-be-deleted service data and the storage position of the to-be-deleted service data in the service system database, and the service data corresponding to the identifier of the to-be-deleted service data is deleted.
[0047] It can be seen that the update method of the local cache provided by the embodiment of the present disclosure stores the current update operation information of the service system database in the auxiliary database, and then obtains the current update operation information from the auxiliary database and updates the cached service data in the local cache according to the current update operation information. By using the auxiliary database to record the update operation information of the service system database, the local cache can read the update operation information from the auxiliary database for local cache update without returning to the service system database, thereby reducing the pressure on the service system database. When data update occurs in the service system database, the local cache can be updated based on the update operation information stored in the auxiliary database in a timely manner, thereby improving the timeliness of the local cache update. In addition, the embodiment of the present disclosure does not increase additional dependence, thereby improving the convenience of updating the local cache.
[0048] In an embodiment of the present disclosure, as shown in Figure 2 the step S110 shown in Figure 1 may further include the following steps before the step S110:
[0049] In step S210, the local cache is refreshed in full based on the service data stored in the service system database.
[0050] In the embodiments of the present disclosure, the local cache can be refreshed in full before being updated, and then the local cache is updated based on the update operation information stored in the auxiliary database.
[0051] In the embodiments of the present disclosure, when the local cache is refreshed in full, the service data in the service system database can be acquired and stored according to specific service needs. For example, the service data with a high data read amount (e.g., higher than a preset number threshold) can be cached in the local cache, and then the local cache can be refreshed in full based on the service data with a high data read amount.
[0052] By refreshing the local cache in full before updating the local cache, the consistency of the service data in the local cache and the service data in the service system database can be ensured, and the service data in the local cache can be prevented from being continuously incorrect due to an abnormal update. Since the local cache is refreshed based on the service data stored in the service system database only before the local cache is updated, the number of data read operations of the service system database is reduced, the data processing pressure of the service system database is reduced, and thus the efficient performance of related services is ensured.
[0053] As described above, in an embodiment of the present disclosure, the auxiliary database can be a Redis database. Redis (Remote Dictionary Server) is an open source Key-Value database written in ANSI C language, supporting network, based on memory and persistent log, and a Redis database can contain multiple types of keys. In the embodiments of the present disclosure, the Redis database can store the update operation information in a hash structure.
[0054] Redis Incr (Redis self-increment) is a commonly used command in the Redis database, which can add 1 to the numerical value stored in the key. If the key does not exist, the value of the key will be initialized to 0, and then the Incr operation is performed. Therefore, in the embodiments of the present disclosure, the Redis self-increment key incr_buf_no can be pre-set to record the number of updates of the service system database, and the numerical value (self-increment value) stored in the self-increment key incr_buf_no can be added 1 by using the Redis Incr command when the new update operation information is cached in the Redis database (i.e., when the data in the service system database is updated).
[0055] In the embodiments of the present disclosure, the storage space in the Redis database can be used to store all the data in the business system database, or a part of the storage space can be used to store the data in the business system database, which is not specifically limited in the present disclosure.
[0056] In the embodiments of the present disclosure, the local record value local_no can be maintained locally. Correspondingly, when performing full refresh of the local cache, the self-increment value in the current self-increment key incr_buf_no can be obtained from the Redis first, and set as the initial value of the local record value local_no, and then the full refresh of the local cache is performed. In this way, the local record value local_no is recorded once before the full refresh of the data, which is to prevent the problem that when new data update occurs in the business system database during the full refresh of the local cache, the local cache cannot be updated in time.
[0057] Correspondingly, as shown in FIG. 1 1, Figure 2 Figure 1 the step S120 in the method 1000 can be refined as:
[0058] In step S121, the current self-increment value of the Redis database is obtained, and the current key is generated based on the current self-increment value.
[0059] In the embodiments of the present disclosure, the current self-increment value can be taken modulo (%) based on the maximum number of keys that can be stored in the storage space in the Redis database for storing the data of the business system database, to obtain the current key incr_buf.
[0060] For example, the size of the storage space in the Redis database for storing the data of the business system database is 65535, that is, at most 65535 keys (or key-value pairs) can be stored in the storage space. If the self-increment value stored in the self-increment key incr_buf_no is A, then the current key incr_buf used to store the current update operation information can be the result of A modulo 65535 (A%65535). In this way, the number of keys storing the update operation information can be controlled to prevent unlimited growth.
[0061] In step S122, the current update operation information is stored in the Redis database as the current value corresponding to the current key, to form the current key-value pair.
[0062] As described above, in the embodiments of the present disclosure, the Hash structure can be specifically used to store the update operation information and the key in the form of key-value pair.
[0063] In the embodiments of the present disclosure, the Hash structure can be specifically used to store the update operation information and the key in the form of key-value pair. Figure 2 As can be seen from steps S110-S122 shown in FIG. 1, in the embodiment of the present disclosure, the service system data update logic is simply modified, so that the service system database data processing pressure is reduced, the modification cost is low, and good performance can be achieved subsequently.
[0064] In the embodiment of the present disclosure, as shown in FIG. 1, Figure 2 Figure 1 Step S130 in FIG. 1 can be refined as the following steps:
[0065] Step S131, judging whether the local cache needs to be updated based on the current incr value and the current local record value.
[0066] As described above, in the embodiment of the present disclosure, the local record value local_no can be maintained locally to record the number of times of updating the data in the service system database recorded in the Redis database. The current local record value can be the local record value recorded when the local cache is last updated, and the initial value thereof can be the incr value of the Redis database when the local cache is full refreshed based on the service data in the service system database.
[0067] That is, in the embodiment of the present disclosure, when the local cache is full refreshed, the Redis incr value can be recorded by using the above local record value first, that is, the value of the current incr_buf_no is assigned to local_no, and then the local cache is full refreshed based on the service data stored in the service system database.
[0068] In the embodiment of the present disclosure, when judging whether the local cache needs to be updated, the current incr value can be judged whether it is greater than the current local record value. As described above, the current local record value is the local record value recorded when the local cache is last updated, and the initial value thereof is the Redis incr value recorded when the local cache is full refreshed, and the Redis incr value records the number of times of updating the data in the service system database in real time. Therefore, by comparing the current local record value with the current Redis incr value, it is actually to compare the Redis incr value recorded when the local cache is full refreshed or updated with the Redis incr value after the local cache is full refreshed or updated.
[0069] Correspondingly, if the current Redis auto-increment value is greater than the current local record value, that is, the Redis auto-increment value after the local cache is refreshed or updated in full is greater than the Redis auto-increment value recorded when the local cache is refreshed or updated in full, it means that new data updates have occurred in the business system database during the process of refreshing or updating the local cache in full, and therefore the local cache needs to be updated accordingly. Otherwise, it means that there is no new data update in the business system database during the process of refreshing or updating the local cache in full, and therefore the local cache does not need to be updated. In an embodiment of the present disclosure, when the current Redis auto-increment value is not greater than the current local record value, a preset time interval (for example, sleep 1s) can be set, and then based on the size of the current Redis auto-increment value and the current local record value, it is determined whether the local cache needs to be updated.
[0070] In an embodiment of the present disclosure, by recording the current Redis auto-increment value using the local record value before updating the local cache, and comparing the current local record value with the current Redis auto-increment value after updating the local cache, it is determined whether there is new data update in the business system database during the updating of the local cache. In this way, the timeliness of updating the local cache can be well guaranteed, and the consistency between the local cache and the data of the business system database can be guaranteed.
[0071] Step S132, if it is determined that the local cache needs to be updated, the current local record value is updated, and the current update operation information corresponding to the current key is obtained from the Redis database.
[0072] In an embodiment of the present disclosure, when updating the current local record value, the current local record value + 1 can be obtained to obtain the updated local record value local_no.
[0073] Then, based on the updated local record value, the current key can be calculated. The calculation of the current key based on the Redis auto-increment key is basically the same as described above. In an embodiment of the present disclosure, local_no can be taken modulo (for example, local_no%65535) with the maximum number of keys that can be stored in the storage space in the Redis database for storing the data of the business system database to obtain the current key incr_buf. Then, the update operation information stored in the current key in the Redis database can be obtained, and the local cache can be updated based on the update operation information. After updating, the above step S131 can be executed again.
[0074] Since the current local record value recorded locally is the same as the Redis auto-increment value at the last local caching, when it is necessary to continue updating at the time of local caching, the current local record value is incremented by 1, and the current key and the corresponding update operation information are obtained based on the updated local record value, which is equivalent to obtaining the first update operation information generated in the business system database after the last local cache update and stored in the Redis database, to continue updating the local cache. In this way, the time sequence of the update operation information can be well maintained, and the consistency between the local cache and the business data in the business system database can be improved.
[0075] The update method of the local cache provided by the present disclosure will be described in detail below with the business system database being MySQL and the auxiliary database being Redis database as an example. Figure 3 、 Figure 4 The update method of the local cache provided by the present disclosure will be described in detail below with the business system database being MySQL and the auxiliary database being Redis database as an example.
[0076] Referring to Figure 3 , Figure 3 is a flowchart of writing the update operation information into the Redis database.
[0077] As shown in Figure 3 , the following steps are executed after the program starts:
[0078] Step S310, updating / inserting / deleting data in the MySQL.
[0079] That is, the current update operation information of the business system database is obtained.
[0080] Step S320, recording the current update times by using the Redis auto-increment value inc_buf_no, and the return value is denoted as A.
[0081] Step S330, storing the update operation information and the current key inc_buf_(A%65535) in the Redis.
[0082] Based on the business system database update process shown in Figure 3 , referring to Figure 4 , Figure 4 a process diagram of updating the local cache based on the Redis saved update operation information in the embodiment of the present disclosure is shown.
[0083] As shown in Figure 4 , the following steps are executed after the program starts:
[0084] Step S410, recording the Redis current auto-increment value inc_buf_no by using the local record value local_no.
[0085] Step S420, full data in the MySQL is flushed into the local cache.
[0086] That is, the local cache is full refreshed. After the local cache is full refreshed, the local cache update can be performed on this basis.
[0087] Step S430, whether inc_buf_no is greater than local_no is compared; if greater, step S440 is executed, and if not greater, step S470 is executed.
[0088] Step S440, the local record value local_no+1.
[0089] Step S450, the current key inc_buf_ is obtained.
[0090] In the embodiment, the current key inc_buf_ can be local_no%65535.
[0091] Step S460, based on the update operation information corresponding to inc_buf_ in Redis, the data corresponding to the key in the local memory cache is updated, and the above step S430 is returned.
[0092] Step S470, after sleeping for 1s, the above step S430 is returned.
[0093] As can be seen from the above, the local cache update method provided by the embodiment of the disclosure has low cost for the existing business system database code transformation, and can be realized only by using MySQL and Redis, has good performance, can guarantee the time sequence of data update, and records the detailed change process of data.
[0094] In other embodiments of the disclosure, if there is no auxiliary database (such as Redis) in the business system, the data update time mtime recorded in the business system database can be used to update the local cache in time.
[0095] The embodiment will be described below taking the business system database as MySQL as an example.
[0096] As shown in Figure 5 After the program starts, the current time is recorded by using the local record time localmtime, then the local cache is full refreshed based on the business data stored in the MySQL, and after the refreshing is completed, the current time is recorded by using the current record time now.
[0097] After comparing whether the current record time now is greater than the local record time localmtime, if the current record time now is greater than the local record time localmtime, it is judged whether there is data with an update time mtime greater than or equal to the localmtime in the MySQL, if there is, the local cache is refreshed based on the data with the update time greater than the localmtime, the value of the local record time localmtime is updated to the value recorded by the current record time now, the current time is recorded by the current record time now, and the step of comparing whether the current record time now is greater than the local record time localmtime is returned to be executed.
[0098] If the current record time now is not greater than the local record time localmtime or there is no data with an update time mtime greater than or equal to the localmtime in the MySQL, a preset time (for example, sleep for 2s) is set, the value of the local record time localmtime is updated to the value recorded by the current record time now, the current time is recorded by the current record time now, and the step of comparing whether the current record time now is greater than the local record time localmtime is returned to be executed.
[0099] According to the embodiments of the present disclosure, the present disclosure also provides a local cache updating device. Referring to Figure 6 The device can include:
[0100] The first current update operation information obtaining module 610 can be used to obtain the current update operation information of the business system database; the current update operation information includes: an update operation type and target business data information;
[0101] The current update operation information recording module 620 can be used to store the current update operation information into the auxiliary database;
[0102] The second current update operation information obtaining module 630 can be used to obtain the current update operation information from the auxiliary database;
[0103] The local cache updating module 640 can be used to update the business data already cached in the local cache according to the update operation type and the target business data information of the current update operation information.
[0104] The local cache updating apparatus provided by the embodiments of the present disclosure stores the current update operation information of the service system database in the auxiliary database, then obtains the current update operation information from the auxiliary database, and updates the service data cached in the local cache according to the current update operation information. By recording the update operation information of the service system database in the auxiliary database, the local cache can read the update operation information from the auxiliary database to update the local cache, without returning to the service system database, thereby reducing the pressure on the service system database. When data update occurs in the service system database, the local cache can be updated based on the update operation information stored in the auxiliary database in time, thereby improving the timeliness of the local cache updating. In addition, the embodiments of the present disclosure do not increase additional dependence, thereby improving the convenience of updating the local cache.
[0105] In an embodiment of the present disclosure, the current update operation information is obtained based on Figure 6 As shown in the local cache updating apparatus, the local cache updating apparatus can further include: Figure 7 As shown in the local cache updating apparatus, the local cache updating apparatus can further include:
[0106] The local cache full refresh module 710 can be configured to perform full refresh on the local cache based on the service data stored in the service system database.
[0107] In an embodiment of the present disclosure, the auxiliary database can be a Redis database; the Redis database can store the current update operation information in the form of key-value pairs.
[0108] The current update operation information recording module 620 can be configured to obtain the current self-increment value of the Redis database, and generate the current key based on the current self-increment value.
[0109] The current update operation information is taken as the current value corresponding to the current key, to form the current key-value pair and store in the Redis database.
[0110] The second current update operation information obtaining module 630 can be configured to determine whether the local cache needs to be updated based on the current self-increment value and the current local record value. The current local record value is the local record value recorded when the local cache is last updated, and the initial value is the self-increment value of the Redis database when the local cache is full refreshed based on the data in the service system database.
[0111] If it is determined that the local cache needs to be updated, the local record value is updated, and the current update operation information corresponding to the current key is obtained from the Redis database.
[0112] In an embodiment of the present disclosure, the second current update operation information obtaining module 630 can be specifically configured to obtain the current key by performing modulo operation on the current auto-increment value based on the maximum number of keys that can be stored in the storage space in the Redis database for storing the database data of the business system.
[0113] In an embodiment of the present disclosure, the second current update operation information obtaining module 630 judges whether the local cache needs to be updated based on the current auto-increment value and the current local record value, including:
[0114] judging whether the current auto-increment value is greater than the current local record value.
[0115] If the current auto-increment value is greater than the current local record value, the local cache needs to be updated; otherwise, the local cache does not need to be updated.
[0116] The second current update operation information obtaining module 630 updates the local record value, including:
[0117] adding 1 to the current local record value as the updated local record value.
[0118] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information comply with relevant laws and regulations and do not violate public order and good customs.
[0119] According to the embodiments of the present disclosure, the present disclosure further provides an electronic device, a readable storage medium and a computer program product.
[0120] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular telephones, smart phones, wearable devices, and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not intended to limit implementations of the present disclosure described and / or claimed in this document.
[0121] As Figure 8As shown, the device 800 includes a computing unit 801 that can perform various appropriate actions and processes in accordance with a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. Various programs and data required for the operation of the device 800 can also be stored in the RAM 803. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0122] A plurality of components in the device 800 are connected to the I / O interface 805, including an input unit 806, such as a keyboard, a mouse, etc., an output unit 807, such as various types of displays, speakers, etc., a storage unit 808, such as a magnetic disk, an optical disk, etc., and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.
[0123] The computing unit 801 can be various general and / or special purpose processing components having processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 801 performs various methods and processes described above, such as the update method of local cache. For example, in some embodiments, the update method of local cache can be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as the storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed on the device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the update method of local cache described above can be performed. Alternatively, in other embodiments, the computing unit 801 can be configured to perform the update method of local cache by any other appropriate means, such as by means of firmware.
[0124] The various embodiments of the systems and techniques described above can be implemented in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0125] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or the block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine as a stand-alone software package, or entirely on a remote machine or server.
[0126] In the context of the present disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of electrical conductors, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0127] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0128] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0129] The computer system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0130] It should be understood that various forms of flow shown above can be used, with steps reordered, added, or removed. For example, the steps recited in the present disclosure can be performed in parallel, in series, or in a different order, without limitation herein, so long as the desired results of the technology disclosed in the present disclosure are achieved.
[0131] The specific embodiments described above are not intended to limit the scope of the present disclosure. Those skilled in the art will understand that various modifications, combinations, sub-combinations, and alternatives can be made to the specific embodiments without departing from the spirit and principles of the present disclosure. Any further modifications, changes, improvements, and the like that come within the spirit and principles of the present disclosure should be considered within the scope of the present disclosure.
Claims
1. A method for updating a local cache, comprising: obtaining current update operation information of a business system database; the current update operation information comprising: an update operation type and target business data information; obtaining a current auto-increment value of an auxiliary database, and generating a current key based on the current auto-increment value; the auxiliary database being a Redis database; the step of generating the current key based on the current auto-increment value comprising: performing modulo operation on the current auto-increment value based on a maximum number of keys that can be stored in a storage space of the Redis database for storing data of the business system database, to obtain the current key; storing the current update operation information as a current value corresponding to the current key in the auxiliary database in a form of a key-value pair; and judging whether the local cache needs to be updated based on the current auto-increment value and a current local record value; the current local record value being a local record value recorded when the local cache was last updated, and an initial value being an auto-increment value of the Redis database when the local cache is full-refreshed based on data in the business system database; if it is judged that the local cache needs to be updated, updating the local record value, and obtaining the current update operation information corresponding to the current key from the Redis database; the updating manner of the local record value comprising increasing the local record value, and the increasing degree of the local record value each time being the same as the increasing degree of the auto-increment value of the auxiliary database each time; the current key used when the current update operation information is obtained from the Redis database being obtained by performing modulo operation on the updated local record value based on the maximum number; updating business data already cached in the local cache according to the update operation type and the target business data information of the current update operation information. 2.The method of claim 1, further comprising, before the step of obtaining the current update operation information of the business system database: full-refreshing the local cache based on business data stored in the business system database. 3.The method of claim 1, wherein the step of judging whether the local cache needs to be updated based on the current auto-increment value and the current local record value comprises: judging whether the current auto-increment value is greater than the current local record value; if the current auto-increment value is greater than the current local record value, the local cache needs to be updated; otherwise, the local cache does not need to be updated; the step of updating the local record value comprises: increasing the current local record value by 1 as an updated local record value. 4.An apparatus for updating a local cache, comprising: a first current update operation information obtaining module configured to obtain current update operation information of a business system database; the current update operation information comprising: an update operation type and target business data information; The current update operation information recording module is configured to obtain a current auto-increment value of an auxiliary database, and generate a current key based on the current auto-increment value; the auxiliary database is a Redis database; the step of generating the current key based on the current auto-increment value comprises: performing modulo operation on the current auto-increment value based on a maximum number of keys that can be stored in a storage space of the Redis database for storing data of the business system database, to obtain the current key; storing the current update operation information as a current value corresponding to the current key in the auxiliary database in the form of a key-value pair; and storing the current update operation information in the auxiliary database in the form of a key-value pair. The second current update operation information obtaining module is configured to determine whether the local cache needs to be updated based on the current auto-increment value and a current local record value; the current local record value is a local record value recorded when the local cache was last updated, and an initial value is an auto-increment value of the Redis database when the local cache is full-quantity refreshed based on data in the business system database; if it is determined that the local cache needs to be updated, the local record value is updated, and the current update operation information corresponding to the current key is obtained from the Redis database; the local record value is updated by increasing the local record value, and the increasing degree of the local record value each time is the same as the increasing degree of the auto-increment value of the auxiliary database each time; and the current key used when the current update operation information is obtained from the Redis database is obtained by performing modulo operation on the updated local record value based on the maximum number. The local cache updating module is configured to update the business data that has been cached in the local cache according to the update operation type and the target business data information of the current update operation information.
5. The apparatus of claim 4, further comprising: The local cache full-quantity refreshing module is configured to full-quantity refresh the local cache based on the business data stored in the business system database.
6. The apparatus of claim 4, wherein, The second current update operation information obtaining module determines whether the local cache needs to be updated based on the current auto-increment value and the current local record value, comprising: determining whether the current auto-increment value is greater than the current local record value; if the current auto-increment value is greater than the current local record value, the local cache needs to be updated; otherwise, the local cache does not need to be updated; The second current update operation information obtaining module updates the local record value, comprising: increasing the current local record value by 1 to obtain the updated local record value.
7. An electronic device, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-3.
8. A non-transitory computer readable storage medium having stored thereon computer instructions, wherein, The computer instructions are used to enable the computer to perform the method of any one of claims 1-3.
9. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-3.
Citation Information
Patent Citations
Cache updating method and system based on Canal
CN109241072A
Cache refreshing method and electronic equipment
CN111581239A