CN114265850A - Local cache updating method, device, equipment and storage medium - Google Patents
Local cache updating method, device, equipment and storage medium Download PDFInfo
- Publication number
- CN114265850A CN114265850A CN202111551233.7A CN202111551233A CN114265850A CN 114265850 A CN114265850 A CN 114265850A CN 202111551233 A CN202111551233 A CN 202111551233A CN 114265850 A CN114265850 A CN 114265850A
- Authority
- CN
- China
- Prior art keywords
- current
- operation information
- value
- local cache
- database
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 43
- 238000004590 computer program Methods 0.000 claims description 10
- 238000012545 processing Methods 0.000 abstract description 15
- 238000010586 diagram Methods 0.000 description 11
- 230000004048 modification Effects 0.000 description 11
- 238000012986 modification Methods 0.000 description 11
- 230000008569 process Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 8
- 238000012217 deletion Methods 0.000 description 4
- 230000037430 deletion Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 2
- 230000008859 change Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000007792 addition Methods 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000001680 brushing effect Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000003780 insertion Methods 0.000 description 1
- 230000037431 insertion Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 208000019116 sleep disease Diseases 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The disclosure provides a method, a device, equipment and a storage medium for updating a local cache, and relates to the technical field of data processing, in particular to the technical field of cache updating. The specific implementation scheme is as follows: and after the current updating operation information of the service system database is acquired, storing the current updating operation information in the auxiliary database, acquiring the current updating operation information from the auxiliary database, and updating the local cache according to the current updating operation information. By applying the embodiment of the disclosure, the auxiliary database is used for recording the update operation information of the service system database, the local cache can read the update operation information from the auxiliary database to update the local cache, the service system database does not need to be returned, the pressure of the service system database is reduced, the local cache can be updated in time based on the update operation information stored in the auxiliary database, and the timeliness of updating the local cache is improved.
Description
Technical Field
The present disclosure relates to the field of data processing technologies, and in particular, to the field of cache update technologies.
Background
At present, in some network services with a large amount of data reading requests, a device for processing data requests usually stores some service data in a local cache to increase the data reading speed, thereby improving the network service performance.
Disclosure of Invention
The present disclosure provides a local cache updating method, apparatus, device, and storage medium for updating a local cache in time.
According to an aspect of the present disclosure, there is provided a method for updating a local cache, including:
obtaining current updating operation information of a service system database; the current update operation information includes: updating the operation type and the target service data information;
storing the current updating operation information into an auxiliary database;
obtaining the current updating operation information from the auxiliary database;
and updating the cached service data in the local cache according to the updating operation type of the current updating operation information and the target service data information.
According to another aspect of the present disclosure, there is provided an apparatus for updating a local cache, including:
the first current updating operation information obtaining module is used for obtaining current updating operation information of the service system database; the current update operation information includes: updating the operation type and the target service data information;
the current updating operation information recording module is used for storing the current updating operation information into the auxiliary database;
a second current update operation information obtaining module, configured to obtain the current update operation information from the auxiliary database;
and the local cache updating module is used for updating the cached service data in the local cache according to the updating operation type of the current updating operation information and the target service data information.
According to another aspect of the present disclosure, there is provided an electronic device including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform any of the above described methods of local cache update.
According to another aspect of the present disclosure, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform any of the above-described local cache updating methods.
According to another aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements any of the above-described local cache updating methods.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
fig. 1 is a schematic diagram of a first embodiment of a local cache updating method provided according to the present disclosure;
FIG. 2 is a schematic diagram of a second embodiment of a method for updating a local cache according to the present disclosure;
FIG. 3 is a schematic flow diagram of writing update operation information to a Redis database in the present disclosure;
FIG. 4 is a schematic diagram of a process for updating a local cache based on Redis saved update operation information in the present disclosure;
FIG. 5 is a schematic illustration of other embodiments of updating a local cache in the present disclosure;
FIG. 6 is a schematic diagram of a first embodiment of a local cache update apparatus provided in accordance with the present disclosure;
FIG. 7 is a schematic diagram of a second embodiment of a local cache update apparatus provided in accordance with the present disclosure;
fig. 8 is a block diagram of an electronic device for implementing a local cache update method according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
At present, when updating the local cache, the following two ways are generally adopted:
one is to set a short cache time for the local memory cache, and after expiration, return to the corresponding database and re-cache the result. In this way, the source database needs to be returned, and when the caching time is short, the data processing pressure of the database is too large and the caching effect is not obvious. In addition, the data in the database is re-cached at regular time in this way, so when data update occurs in the database, the local cache cannot be updated in time.
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 there is data change, the local cache is updated. This approach is complex to implement and introduces additional reliance on message broadcasting.
In order to solve the above problems, the present disclosure provides a method and an apparatus for updating a local cache, an electronic device, and a storage medium.
Referring to fig. 1, fig. 1 is a schematic diagram of a first embodiment of a local cache updating method provided by the present disclosure, which may include the following steps:
step S110, obtaining the current updating operation information of the service system database; the current update operation information includes: and updating the operation type and the target service data information.
In the embodiment of the present disclosure, the service system database may be Oracle, MySQL, or the like, which is not specifically limited in the present disclosure.
In the embodiment of the present disclosure, the update operation types may include modification, addition (insertion), deletion, and the like of the service data. Correspondingly, if the update operation type is data modification, the corresponding target service data information may include an identifier of the service data to be modified (e.g., an ID of the service data, etc.), and a modification content, which may be the modified service data. Of course, the target service data information may further include a storage location of the service data to be modified in the service system database, and the like. If the update operation type is data addition, the corresponding target service data information may include an identifier of the service data to be added, a storage location of the service data to be added in the service system database, and a specific content of the service data to be added. If the update operation type is data deletion, the corresponding target service data information may include an identifier of the service data to be deleted and a storage location of the service data to be deleted in the service system database. The above examples are merely illustrative of the embodiments of the present disclosure and do not specifically limit the present disclosure.
And step S120, storing the current updating operation information into an auxiliary database.
In the embodiment of the present disclosure, the relevant code may be written in the service system database code in advance, so that when data in the service system database is updated, the corresponding update operation information is automatically cached in the auxiliary database.
In an embodiment of the present disclosure, the auxiliary database may be a key-value storage system (e.g., a Redis database). Therefore, when the update operation information is cached in the secondary database, the update operation information can be stored as a value in correspondence with the key.
Step S130, obtaining the current update operation information from the auxiliary database.
In this embodiment of the present disclosure, the auxiliary database may be a cache database, that is, data in the service system database may be cached. Generally, a business system database (e.g., MySQL) can be used to persistently store data to a hard disk, which has a strong data processing function but a slow data reading speed, and therefore, when the data reading amount of a business is large, the business system database is under a large pressure. The use of the auxiliary database can well avoid the situation. As described above, in the embodiment of the present disclosure, the auxiliary database may be a cache database, and the data reading speed of the cache database is fast, so that the update operation information is stored in the auxiliary database, and 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 service system database.
As described above, in an embodiment of the present disclosure, when the secondary database caches the update operation information, the update operation information may be stored in a key-value form. 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.
Step S140, updating the cached service data in the local cache according to the update operation type of the current update operation information and the target service data information.
As described above, in the embodiment of the present disclosure, the service data update operation type may 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 service data identifier to be modified in the corresponding target service data information, and the service data to be modified is modified based on the modified service data contained in the modification content. If the service data updating operation type is data addition, the data to be added can be inserted into the local cache at a corresponding position based on the identification of the service data to be added in the corresponding target service data information, the storage position of the service data to be added in the service system database and the specific content of the service data to be added. If the update operation type is data deletion, the corresponding storage location may be found in the local cache based on the identifier of the to-be-deleted service data included in the corresponding target service data information and the storage location 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 may be deleted.
It can be seen that, in the method for updating a local cache provided by the embodiment of the present disclosure, after current update operation information of a service system database is obtained, the current update operation information is stored in an auxiliary database, then the current update operation information is obtained from the auxiliary database, and service data cached in the local cache is updated according to the current update operation information. By applying the embodiment of the disclosure, the auxiliary database is used for recording 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, the service system database does not need to be returned, the pressure of the service system database is reduced, and when data update is generated in the service system database, the local cache can be updated in time based on the update operation information stored in the auxiliary database, so that the timeliness of updating the local cache is improved.
In an embodiment of the present disclosure, as shown in fig. 2, before the step S110 shown in fig. 1, the following steps may be further included:
step S210, based on the service data stored in the service system database, performing a full refresh on the local cache.
In the embodiment of the present disclosure, before the local cache is updated, the local cache may be fully refreshed, and then the local cache is updated based on the update operation information stored in the auxiliary database.
In the embodiment of the present disclosure, when the local cache is fully refreshed, the service data in the service system database may be acquired and stored according to specific service requirements. For example, it may be set that only the service data with a higher data reading amount (e.g., higher than a preset number threshold) is cached in the local cache, so that when the local cache is fully refreshed, the local cache may be fully refreshed based on the service data with a higher data reading amount.
The local cache is refreshed in full before being updated, so that the consistency of the service data of the local cache and the service data of the service system database can be ensured, and the service data of the local cache is prevented from being continuously wrong due to one-time updating abnormity. And the local cache is refreshed based on the service data stored in the service system database only before the local cache is updated, so that the data reading times of the service system database are reduced, the data processing pressure of the service system database is reduced, and the high-efficiency operation of related services is ensured.
As described above, in one embodiment of the present disclosure, the auxiliary database may be a Redis database. A Remote Dictionary Server (Remote Dictionary Server) is an open-source log-type Key-Value database written in ANSI C language, supporting network, and can be based on memory and can be persisted, and a Redis database can contain multiple types of keys (keys).
There is a commonly used command in the Redis database, namely Redis Incr (Redis self-increment), which can be used to store a digital value +1 in a Key (Key), and if the Key does not exist, the value of the Key is initialized to 0, and then the Incr operation is executed. Therefore, in the embodiment of the present disclosure, a Redis auto-increment key Incr _ buf _ no may be preset to record the update times of the service system database, and when new update operation information is cached in the Redis database (that is, when data is updated in the service system database), a digital value (self-increment value) +1 stored in the auto-increment key Incr _ buf _ no is used.
In this embodiment of the present disclosure, the storage space in the Redis database may be used to store all the data in the business system database, and may also be used to store a part of the storage space, which is not specifically limited in this disclosure.
In the embodiment of the present disclosure, the local recorded value local _ no may be maintained locally. Correspondingly, when the full amount of the local cache is refreshed, the auto-increment value in the current auto-increment key incr _ buf _ no can be obtained from the Redis, the auto-increment value is set as the initial value of the local _ no, and then the full amount of the local cache is refreshed. In this way, the local _ no value is recorded once before the full data is refreshed, which is to prevent the problem that the local cache cannot be updated in time when new data update is generated in the service system database in the process of refreshing the local cache in full.
Accordingly, as shown in fig. 2, step S120 in fig. 1 can be further detailed as:
and step S121, obtaining the current auto-increment value of the Redis database, and generating a current key based on the current auto-increment value.
In the embodiment of the present disclosure, a modulo (%) may be performed on the current self-added value based on the maximum number of storable keys in a storage space for storing the data of the service system database in the Redis database to obtain the current key incr _ buf.
For example, in the Redis database, the size of the storage space for storing the business system database data is 65535, that is, the storage space can store 65535 keys (or key-value pairs) at most. If the self-increment value stored in the self-increment key incr _ buf _ no is a, the current key incr _ buf used for storing the current updating operation information may be a result of modulo a with 65535 (a% 65535). In this way, the number of keys storing the update operation information can be controlled, preventing it from growing indefinitely.
And step S122, taking the current updating operation information as the current value corresponding to the current key to form a current key-value pair, and storing the current key-value pair in a Redis database.
As described above, in the embodiment of the present disclosure, a Hash structure may be specifically adopted, and the update operation information is stored in a key-value pair manner in correspondence with the key.
As can be seen from steps S110 to S122 shown in fig. 2, in the embodiment of the present disclosure, by simply modifying the service system data update logic, the data processing pressure of the service system database can be reduced, the modification cost is low, and better performance can be achieved subsequently.
In the embodiment of the present disclosure, as shown in fig. 2, step S130 in fig. 1 may be further refined into the following steps:
step S131, based on the current self-increment value and the current local record value, judging whether the local cache needs to be updated.
As described above, in the embodiment of the present disclosure, the local record value local _ no may be maintained locally to record the number of times of updating data in the business system database recorded in the Redis database. The current local record value may be a local record value recorded when the local cache is updated last time, and the initial value may be a self-increment value of the Redis database when the local cache is fully refreshed based on the service data in the service system database.
That is to say, in the embodiment of the present disclosure, when the local cache is fully refreshed, the local record value may be used to record the Redis self-increment, that is, the value of the current incr _ buf _ no is assigned to the local _ no, and then the local cache is fully refreshed based on the service data stored in the service system database.
In the embodiment of the present disclosure, when determining whether the local cache needs to be updated, it may be determined whether the current self-increment value 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 updated last time, and the initial value is the Redis database self-increment value recorded when the local cache is fully refreshed, where the Redis self-increment value records the update times of the data in the service system database in real time. Therefore, by comparing the current local record value with the current Redis self-increment value, the recorded Redis self-increment value when the local cache performs the full refresh or update is actually compared with the Redis self-increment value after the local cache performs the full refresh or update.
Correspondingly, if the current Redis self-increment value is greater than the current local record value, that is, the Redis self-increment value after the local cache performs the full refresh or the update is greater than the Redis self-increment value recorded when the local cache performs the full refresh or the update, it is described that new data update is generated in the service system database during the process of performing the full refresh or the update on the local cache, and therefore, the local cache needs to be updated correspondingly. Otherwise, it indicates that no new data in the service system database is updated in the process of performing full refresh or update on the local cache, so that 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 (for example, 1s (sleep 1s)) may be set apart, and then, based on the current Redis auto-increment value and the current local record value, it is determined whether the local cache needs to be updated.
In the embodiment of the disclosure, whether new data is updated in the service system database during the local cache updating period is judged by recording the current Redis self-increment by using the local record value before updating the local cache and comparing the current local record value with the current Redis self-increment after updating the local cache, so that the timeliness of updating the local cache can be well ensured, and the data consistency between the local cache and the service system database is further ensured.
Step S132, if the local cache is judged to need updating, the current local record value is updated, and current updating operation information corresponding to the current key is obtained from the Redis database.
In the embodiment of the present disclosure, when the current local record value is updated, the updated local record value local _ no may be obtained from the current local record value + 1.
The current key may then be calculated based on the updated local record value. In the embodiment of the present disclosure, the maximum number of storable keys in the storage space for storing the data of the business system database in the Redis database may be modulo (for example, may be local _ no% 65535), so as to obtain the current key incr _ buf, which is substantially the same as the current key calculated based on the Redis auto-increment key. Then, the update operation information stored in the current key may be obtained in the Redis database, and the local cache may be updated based on the update operation information. After the update, the step S131 may be performed again.
Because the current local record value of the local record is the same as the Redis self-increment value in the last local cache, when the local cache needs to be updated continuously, the current local record value +1 is used, and then the current key and the corresponding updating operation information are obtained based on the updated local record value, which is equivalent to that the local cache is continuously updated by obtaining the first piece of updating operation information which is generated in the service system database and stored in the Redis database after the last local cache is updated, so that the time sequence of the updating operation information can be well kept, and the consistency of the local cache and the service data in the service system database is further improved.
The following takes the service system database as MySQL and the auxiliary database as Redis database as an example, and details of the update method of the local cache provided by the present disclosure are described with reference to fig. 3 and 4.
Referring to fig. 3, fig. 3 is a schematic flow chart of writing the update operation information into the Redis database.
As shown in fig. 3, the following steps are performed after the program starts:
step S310, update/insert/delete data in MySQL.
Namely, the current updating operation information of the service system database is obtained.
Step S320, recording the current update times by using the Redis self-added value inc _ buf _ no, and recording the return value as a.
In step S330, the update operation information is stored in Redis in correspondence with the current key inc _ buf _ (a% 65535).
On the basis of the update process of the service system database shown in fig. 3, referring to fig. 4, fig. 4 is a schematic diagram illustrating a process of updating a local cache based on update operation information saved by Redis in the embodiment of the present disclosure.
As shown in fig. 4, after the program starts, the following steps are performed:
in step S410, the local _ no is used to record the current auto-increment value inc _ buf _ no of the Redis.
And step S420, brushing the total data in MySQL into a local cache.
I.e. the local cache is flushed in full. After the local cache is refreshed in a full amount, the local cache can be updated on the basis.
Step S430, comparing whether inc _ buf _ no is larger than local _ no; if yes, go to step S440, and if no, go to step S470.
In step S440, the local _ no +1 value is locally recorded.
Step S450, obtain the current key inc _ buf _.
In this embodiment, the current key inc _ buf _ may be local _ no% 65535.
Step S460, based on the update operation information corresponding to the inc _ buf _ in the Redis, updates the data corresponding to the key in the local memory cache, and returns to step S430.
After sleeping for 1S in step S470, the process returns to step S430.
Therefore, the local cache updating method provided by the embodiment of the disclosure has the advantages of low modification cost for the existing service system database codes, realization by only MySQL and Redis, good performance, capability of ensuring the time sequence of data updating, and recording the detailed change process of data.
In other embodiments of the present disclosure, if there is no auxiliary database (e.g., Redis) in the service system, the local cache may be updated in time by using the data update time mtime recorded in the service system database.
The embodiment will be described below by taking the service system database as MySQL as an example.
As shown in fig. 5, after the program starts, the current time is recorded by using the local recording time localmtime, then the local cache is fully refreshed based on the service data stored in MySQL, and after the refreshing is completed, the current time is recorded by using the current recording time now.
And then comparing whether the current recording time now is greater than the local recording time localmtime, if the current recording time now is greater than the local recording time localmtime, judging whether data with the update time mtime which is greater than or equal to the localmtime exist in MySQL, if so, refreshing the local cache based on the data with the update time which is greater than the localmtime, updating the value of the local recording time localmtime to the value recorded by the current recording time now, recording the current time by using the current recording time now, and returning to execute the step of comparing whether the current recording time now is greater than the local recording time localmtime.
If the current recording time now is not greater than the local recording time localmtime or the data of which the update time mtime is greater than or equal to localmtime does not exist in MySQL, the value of the local recording time localmtime is updated to the value recorded by the current recording time now at a preset time interval (for example, sleep 2s), then the current time is recorded by using the current recording time now, and the step of comparing whether the current recording time now is greater than the local recording time is executed.
According to the embodiment of the disclosure, the disclosure further provides a device for updating the local cache. Referring to fig. 6, the apparatus may include:
a first current update operation information obtaining module 610, configured to obtain current update operation information of a service system database; the current update operation information includes: updating the operation type and the target service data information;
a current update operation information recording module 620, which may be configured to store the current update operation information in the auxiliary database;
a second current update operation information obtaining module 630, configured to obtain the current update operation information from the auxiliary database;
the local cache updating module 640 may be configured to update the cached service data in the local cache according to the update operation type of the current update operation information and the target service data information.
The updating device for local cache provided by the embodiment of the present disclosure, after obtaining the current updating operation information of the service system database, stores the current updating operation information in the auxiliary database, then obtains the current updating operation information from the auxiliary database, and updates the cached service data in the local cache according to the current updating operation information. By applying the embodiment of the disclosure, the auxiliary database is used for recording 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, the service system database does not need to be returned, the pressure of the service system database is reduced, and when data update is generated in the service system database, the local cache can be updated in time based on the update operation information stored in the auxiliary database, so that the timeliness of updating the local cache is improved.
In an embodiment of the present disclosure, based on fig. 6, as shown in fig. 7, the apparatus for updating a local cache may further include:
the local cache full refresh module 710 may be configured to perform full refresh on the local cache based on the service data stored in the service system database.
In one embodiment of the present disclosure, the secondary database may be a Redis database; the Redis database may store the current update operation information in the form of key-value pairs;
the current update operation information recording module 620 may be specifically configured to obtain a current auto-increment value of the Redis database, and generate a current key based on the current auto-increment value;
taking the current updating operation information as a current value corresponding to the current key to form a current key-value pair, and storing the current key-value pair in a Redis database;
the second current update operation information obtaining module 630 may be specifically 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 a local record value recorded when the local cache is updated last time, and the initial value is the self-increment value of the Redis database when the local cache is refreshed in full quantity based on the data in the service system database;
and if the local cache needs to be updated, updating the local record value, and acquiring the current updating operation information corresponding to the current key from the Redis database.
In an embodiment of the present disclosure, the second current update operation information obtaining module 630 may be specifically configured to, based on a maximum number of storable keys in a storage space in the Redis database, where the storable keys are used to store data of the service system database, perform modulo operation on the current self-added value to obtain a current key.
In an embodiment of the present disclosure, the second current update operation information obtaining module 630, based on the current self-increment value and the current local record value, determining whether the local cache needs to be updated includes:
judging whether the current self-increment value is larger than the current local record value or not;
if the current self-increment value is larger 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 630, updating the local record value, includes:
and adding 1 to the current local record value to serve as an updated local record value.
In the technical scheme of the disclosure, the collection, storage, use, processing, transmission, provision, disclosure and other processing of the personal information of the related user are all in accordance with the regulations of related laws and regulations and do not violate the good customs of the public order.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
FIG. 8 illustrates a schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 8, the apparatus 800 includes a computing unit 801 that can perform various appropriate actions and processes according to 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. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The calculation unit 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
A number 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, or the like; an output unit 807 such as various types of displays, speakers, and the like; a storage unit 808, such as a magnetic disk, optical disk, or the like; and a communication unit 809 such as a network card, modem, wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may 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 a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
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 a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; 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 may be received in any form, including acoustic, speech, or tactile input.
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: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may 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 may be a cloud server, a server of a distributed system, or a server with a combined blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel or sequentially or in different orders, and are not limited herein as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.
Claims (13)
1. A method for updating a local cache comprises the following steps:
obtaining current updating operation information of a service system database; the current update operation information includes: updating the operation type and the target service data information;
storing the current updating operation information into an auxiliary database;
obtaining the current updating operation information from the auxiliary database;
and updating the cached service data in the local cache according to the updating operation type of the current updating operation information and the target service data information.
2. The method of claim 1, further comprising, prior to the step of obtaining current update operational information for a business system database:
and based on the service data stored in the service system database, performing full refresh on the local cache.
3. The method of claim 2, wherein,
the auxiliary database is a Redis database; the Redis database stores the current update operation information in a key-value pair form;
the step of storing the current update operation information in the secondary database includes:
obtaining a current auto-increment value of the Redis database, and generating a current key based on the current auto-increment value;
taking the current updating operation information as a current value corresponding to the current key to form a current key-value pair, and storing the current key-value pair in a Redis database;
the step of obtaining the current update operation information from the secondary database includes:
judging whether the local cache needs to be updated or not based on the current self-increment value and the current local record value; the current local record value is a local record value recorded when the local cache is updated last time, and the initial value is the self-increment value of the Redis database when the local cache is refreshed in full quantity based on the data in the service system database;
and if the local cache needs to be updated, updating the local record value, and acquiring the current updating operation information corresponding to the current key from the Redis database.
4. The method of claim 1, wherein,
the step of generating a current key based on the current auto-increment value comprises:
and performing modulo operation on the current self-added value based on the maximum number of the storable keys in the storage space for storing the data of the service system database in the Redis database to obtain the current key.
5. The method of claim 4, wherein,
the step of judging whether the local cache needs to be updated based on the current self-increment value and the current local record value comprises the following steps:
judging whether the current self-increment value is larger than the current local record value or not;
if the current self-increment value is larger 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:
and adding 1 to the current local record value to serve as an updated local record value.
6. An apparatus for updating a local cache, comprising:
the first current updating operation information obtaining module is used for obtaining current updating operation information of the service system database; the current update operation information includes: updating the operation type and the target service data information;
the current updating operation information recording module is used for storing the current updating operation information into the auxiliary database;
a second current update operation information obtaining module, configured to obtain the current update operation information from the auxiliary database;
and the local cache updating module is used for updating the cached service data in the local cache according to the updating operation type of the current updating operation information and the target service data information.
7. The apparatus of claim 6, further comprising:
and the local cache full-amount refreshing module is used for refreshing the local cache in full amount based on the service data stored in the service system database.
8. The apparatus of claim 7, wherein,
the auxiliary database is a Redis database; the Redis database stores the current update operation information in a key-value pair form;
the current updating operation information recording module is specifically used for obtaining a current self-increment value of the Redis database and generating a current key based on the current self-increment value;
taking the current updating operation information as a current value corresponding to the current key to form a current key-value pair, and storing the current key-value pair in a Redis database;
the second current updating operation information obtaining module is specifically 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 a local record value recorded when the local cache is updated last time, and the initial value is the self-increment value of the Redis database when the local cache is refreshed in full quantity based on the data in the service system database;
and if the local cache needs to be updated, updating the local record value, and acquiring the current updating operation information corresponding to the current key from the Redis database.
9. The apparatus of claim 6, wherein,
the second current update operation information obtaining module is specifically configured to, based on the maximum number of storable keys in a storage space in the Redis database, which is used for storing the data in the service system database, perform modulo operation on the current self-added value to obtain a current key.
10. The apparatus of claim 9, wherein the second current update operation information obtaining module, based on the current self-increment value and the current local record value, determines whether the local cache needs to be updated, and includes:
judging whether the current self-increment value is larger than the current local record value or not;
if the current self-increment value is larger 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, including:
and adding 1 to the current local record value to serve as an updated local record value.
11. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-5.
12. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-5.
13. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111551233.7A CN114265850A (en) | 2021-12-17 | 2021-12-17 | Local cache updating method, device, equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111551233.7A CN114265850A (en) | 2021-12-17 | 2021-12-17 | Local cache updating method, device, equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114265850A true CN114265850A (en) | 2022-04-01 |
Family
ID=80827815
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111551233.7A Pending CN114265850A (en) | 2021-12-17 | 2021-12-17 | Local cache updating method, device, equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114265850A (en) |
-
2021
- 2021-12-17 CN CN202111551233.7A patent/CN114265850A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108984553B (en) | Caching method and device | |
CN114116613A (en) | Metadata query method, equipment and storage medium based on distributed file system | |
CN113364877B (en) | Data processing method, device, electronic equipment and medium | |
CN113961510A (en) | File processing method, device, equipment and storage medium | |
CN112540731A (en) | Data additional writing method, device, equipment, medium and program product | |
CN113868273A (en) | Metadata snapshot method and device | |
CN113010535A (en) | Cache data updating method, device, equipment and storage medium | |
CN112631517B (en) | Data storage method and device, electronic equipment and storage medium | |
CN115639966A (en) | Data writing method and device, terminal equipment and storage medium | |
CN114265850A (en) | Local cache updating method, device, equipment and storage medium | |
CN116578502A (en) | Access request processing device, processing method, equipment and storage medium | |
CN114168119B (en) | Code file editing method, device, electronic equipment and storage medium | |
CN115904240A (en) | Data processing method and device, electronic equipment and storage medium | |
CN112887426B (en) | Information stream pushing method and device, electronic equipment and storage medium | |
CN115905322A (en) | Service processing method and device, electronic equipment and storage medium | |
US11507511B2 (en) | Method, electronic device and computer program product for storing data | |
CN113535740B (en) | Inventory management method and device | |
CN113986134A (en) | Method for storing data, method and device for reading data | |
CN113986135A (en) | Method, device, equipment and storage medium for processing request | |
CN114861097A (en) | Browser caching method and device, electronic equipment and storage medium | |
CN115168440A (en) | Data read-write method, distributed storage system, device, equipment and storage medium | |
CN113722389A (en) | Data management method and device, electronic equipment and computer readable storage medium | |
CN114564149A (en) | Data storage method, device, equipment and storage medium | |
CN114461950A (en) | Global caching method and device, electronic equipment and storage medium | |
CN115840663A (en) | Method, electronic device and computer program product for flashing metadata |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |