Database cache management method and device and storage medium
Registering database operations and cache management programs in database cache management through observer mode, solving the problems of cache management complexity and data inconsistency in the existing technology, realizing a simplified development process and reducing database query pressure.
Patent Information
- Application Number
- CN202510228095.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-05-30
AI Technical Summary
The existing technology has complex configuration requirements in cache management, especially in the aggregation data scenario, which can easily lead to data inconsistency, increasing the workload of developers and database query pressure.
Through the observer mode, the database operation is registered as the observer, the program of the cache management method is registered as the observer, and the change part of the cache data is updated or deleted according to the cache configuration, reducing the pressure on querying the database.
This enables cache management without explicit configuration, simplifies the development process, reduces database query pressure, and ensures data consistency.
Smart Images

Figure CN120067161A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more particularly, to a database cache management method, apparatus, and storage medium. Background Art
[0002] A cache is a buffer for data exchange (referred to as cache), which is a temporary area for storing data (especially frequently used data). When a user queries data, the server first looks in the cache. If it finds the data, it directly executes; if not, it goes to the database to search. The essence of a cache is to trade space for time, sacrificing data real-time performance, temporarily replacing the latest data read from the database with the data in the server memory, reducing database I / O operations, alleviating server pressure, thereby reducing network latency and accelerating the page opening speed.
[0003] Cache management is a complex process. During the cache management process, it is necessary to ensure the timely cleaning of dirty data and the timely caching of new data. Summary of the Invention
[0004] Embodiments of this application provide a database cache management method, apparatus, and storage medium, which do not require explicit cache-related configurations, reduce the workload of developers, and can effectively alleviate database query pressure.
[0005] Embodiments of this application provide a database cache management method, including: When the observed object is triggered, receiving a notification sent by the observed object to the observer; Determining the part of the cached data corresponding to the cache key that needs to be changed when the observed object is triggered according to the notification and the correspondence between the observed object and the cache key; Deleting or updating the part of the cached data that needs to be changed according to the cache configuration; where the observed object is a database operation on target data; the observer is a program corresponding to the database cache management method; and the cache key is the key of the cached data of the target data.
[0006] In an exemplary embodiment, before the observed object is triggered, the method further includes: Registering the database operation on the target data as the observed object; registering the program corresponding to the database cache management method as the observer; Establishing an association between the observer and the observed object.
[0007] In an exemplary embodiment, establishing the association between the observer and the observed object includes: Establishing the cache key associated with the observer; Establish a correspondence between the observed object and the cache keyword.
[0008] In an exemplary embodiment, before updating the part of the cache data that needs to be changed, the method further includes: obtaining a cache lock to prevent multiple threads or processes from accessing the cache and / or modifying the cache simultaneously.
[0009] In an exemplary embodiment, the updating of the part of the cache data that needs to be changed includes: When the cache lock is successfully obtained, update the part of the cache data that needs to be changed.
[0010] In an exemplary embodiment, the cache configuration includes deleting cache data and / or updating cache data; When the cache configuration includes deleting cache data, delete the part of the cache data that needs to be changed; When the cache configuration includes updating cache data, first delete the part of the cache data that needs to be changed, and then reload the part of the target data that has been changed when the observed object is triggered.
[0011] In an exemplary embodiment, the target data includes aggregated data.
[0012] In an exemplary embodiment, the aggregated data includes user data, role data, and permission data; Wherein, the role data belongs to the user data, and the permission data belongs to the role data.
[0013] In an exemplary embodiment, the database operations include one or more of the following: delete data operation, add data operation, and change data operation.
[0014] The embodiment of the present application also provides a database cache management device, including a memory and a processor, The memory is used to store a program for the database cache management method; The processor is used to read and execute the program for the database cache management method, and execute the method described in any one of the above embodiments.
[0015] The embodiment of the present application also provides a computer-readable storage medium, storing computer-executable instructions, wherein the computer-executable instructions are used to cause the computer to execute the method described in any one of the above embodiments.
[0016] The database cache management method according to the embodiments of the present application registers the program corresponding to the database cache management method as an observer, registers the database operation of the target data as an observed object, and receives the notification sent to the observer when the observed object is triggered; determines the part of the cache data corresponding to the cache key that needs to be changed when the observed object is triggered according to the notification and the corresponding relationship between the observed object and the cache key; deletes or updates the part of the cache data that needs to be changed according to the cache configuration; the notification includes the changed part of the target data when the observed object is triggered; because only the changed part of the data is updated, the query pressure on the database is reduced.
[0017] Other features and advantages of the present application will be described in the following description, and some of them will be obvious from the description, or can be understood by implementing the present application. The objectives and other advantages of the present application can be achieved and obtained through the structures specifically pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings are used to provide a further understanding of the technical solutions of the present application, and constitute a part of the description. Together with the embodiments of the present application, they are used to explain the technical solutions of the present application, and do not constitute a limitation to the technical solutions of the present application.
[0019] Figure 1 It is a schematic diagram of a database cache management method according to an embodiment of the present application; Figure 2 It is a schematic diagram of the observer mode structure; Figure 3 It is a schematic diagram of a cache configuration object according to an embodiment of the present application; Figure 4 It is one of the cache management examples of the prior art; Figure 5 It is another cache management example of the prior art; Figure 6 It is a schematic diagram of another database cache management method (database side) according to an embodiment of the present application; Figure 7 It is a schematic diagram of another database cache management method (cache side) according to an embodiment of the present application; Figure 8 It is a schematic diagram of two cache data according to an embodiment of the present application; Figure 9 It is a schematic diagram of a database cache management device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0020] To make the objectives, technical solutions and advantages of this application more clearly understood, the embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be noted that, without conflict, the embodiments in this application and the features in the embodiments can be combined arbitrarily with each other.
[0021] Cache management may encounter problems in scenarios such as cache data types and cache aggregated data. The Cache provided in the original Spring can provide cache operations, but the cache configuration in this way is relatively complex. For example, @Cacheable is required for caching, and if synchronous update is needed for the update, @CachePut is required, and if synchronous update is not needed, @CacheEvict is required. More cache configurations require the use of @Caching. Especially in the process of caching aggregated data, if there is any omission in any place, it is very easy to cause a certain deviation between the obtained data and the actual data stored in the database.
[0022] To solve the above problems, this application proposes a database cache management method.
[0023] Figure 1 For the schematic diagram of a database cache management method according to an embodiment of this application, this database cache management method is as Figure 1 shown, and includes the following steps 11 to step 13: Step 11, when the observed object is triggered, receive the notification sent by the observed object to the observer; Step 12, determine the part that needs to be changed in the cache data corresponding to the cache key when the observed object is triggered according to the notification and the corresponding relationship between the observed object and the cache key; Step 13, delete or update the part that needs to be changed in the cache data according to the cache configuration.
[0024] Among them, the observed object is the database operation on the target data; the observer is the program corresponding to this database cache management method; the cache key is the key of the cache data of the target data; and the notification includes the part of the target data that has been changed when the observed object is triggered.
[0025] The database cache management method according to the embodiment of the present application registers the program corresponding to the database cache management method as an observer, registers the database operation of the target data as an observed object, and receives the notification sent to the observer when the observed object is triggered; determines the part of the cached data corresponding to the cache key that needs to be changed when the observed object is triggered according to the notification and the corresponding relationship between the observed object and the cache key; deletes or updates the part of the cached data that needs to be changed according to the cache configuration; the notification includes the changed part of the target data when the observed object is triggered; because only the changed part of the data is updated, the query pressure on the database is reduced.
[0026] The observer pattern defines a one-to-many dependency relationship, allowing multiple observer objects (observers) to listen to a single subject object (observed object) simultaneously. When the state of this subject object changes, it will notify all observer objects so that they can update themselves.
[0027] The structural diagram of the observer pattern (Observer) is as Figure 2 shown. Among them, the subject (Subject class) saves all references to observer objects in a collection. Each subject can have any number of observers. The abstract subject provides an interface to add and delete observer objects. The observer (Observer class) is an abstract observer that defines an interface for all concrete observers to update themselves when notified by the subject. The concrete subject (ConcreteSubject class) stores the relevant state in the concrete observer object and sends notifications to all registered observers when the internal state of the concrete subject changes. The concrete observer (ConcreteObserver class) implements the update interface required by the abstract observer role to coordinate its own state with the state of the subject.
[0028] Register the database operation on the target data as the observed object; that is, establish the concrete subject of the target data; register the program corresponding to the database cache management method as the observer, that is, establish the concrete observer.
[0029] In an exemplary embodiment, before the observed object is triggered, the method further includes: Register the database operation on the target data as the observed object; register the program corresponding to the database cache management method as the observer; Establish an association between the observer and the observed object.
[0030] Assume that for the target data User, the cache configuration object may include: cached data UserVO, whose trigger operation for this cached data is deletion or update; cached data UserListVO, whose trigger operation for this cached data is deletion or update; cached data UserPageVO, whose trigger operation for this cached data is deletion or update; cached data RoleVO, whose trigger operation for this cached data is deletion or update; cached data RoleListVO, whose trigger operation for this cached data is deletion or update; cached data RolePageVO, whose trigger operation for this cached data is deletion or update; cached data PermissionVO, whose trigger operation for this cached data is deletion or update; cached data PermissionListVO, whose trigger operation for this cached data is deletion or update; cached data PermissionPageVO, whose trigger operation for this cached data is deletion or update. As Figure 3 shown.
[0031] Assume that database operations may include adding user operations, updating user operations, updating role operations, and updating permission operations.
[0032] Assume that the method addUser() is the operation of adding a user. Then addUser is the observed object, and the observer may be associated with corresponding cache keys such as UserListVO (the user data used) and UserPageVO (the user data for paging query). In this way, when the business triggers the operation of adding a user, all observers need to operate according to the cache configuration, whether to directly clear the cache or reload the cache.
[0033] Assume that the method updateUser(int id) is the operation of updating a user. Then the updateUser method is the observed object, and the observer may be associated with corresponding cache keys such as UserListVO (the user data used), UserPageVO (the user data for paging query), and UserVO (the user information obtained according to the ID). In this way, when the business triggers the operation of updating a user, all observers need to operate according to the cache configuration, whether to directly clear the cache or reload the cache.
[0034] Assume that the method updateRole(int id) is the operation to update the role. Then the updateRole method is the observed object. The observer may be associated with cache keys corresponding to UserVO (user information obtained according to the ID), RoleListVO (role data used), RolePageVO (role data obtained by paging query), RoleVO (role information obtained according to the ID), etc. In this way, when the business triggers the operation to update the user, all observers need to operate according to the cache configuration, whether to directly clear the cache or reload the cache.
[0035] Assume that the method updatePermission(int id) is the operation to update the permission. Then the updatePermission method is the observed object. The observer may be associated with cache keys corresponding to UserVO (user information obtained according to the ID), RoleVO (role information obtained according to the ID), PermissionListVO (permission data used), PermissionPageVO (permission data obtained by paging query), PermissionVO (permission information obtained according to the ID), etc. In this way, when the business triggers the operation to update the user, for all observers, they need to operate according to the cache configuration, whether to directly clear the cache or reload the cache.
[0036] In an exemplary embodiment, establishing the association between the observer and the observed object includes: Establishing the cache keys associated with the observer; Establishing the corresponding relationship between the observed object and the cache keys.
[0037] In an exemplary embodiment, before updating the part of the cache data that needs to be changed, the method further includes: obtaining a cache lock to prevent multiple threads or processes from accessing the cache and / or modifying the cache simultaneously.
[0038] In services involving caches, due to poor cache management, it is very easy to cause the data obtained by users or third-party services to be inconsistent with the data in the database (as Figure 4 and Figure 5 shown).
[0039] Figure 3 The situation shown is to first delete the cache and then update the database. If there are 2 threads (thread A and thread B) to concurrently read and write data, the following scenarios may occur: 1) Thread B wants to update X = 2 (original value X = 1); 2) Thread B first deletes the cache; 3) Thread A reads the cache and finds that it doesn't exist, so it reads the old value (X = 1) from the database; 4) Thread A writes the old value to the cache (X = 1); 5) Thread B writes the new value to the database (X = 2); Ultimately, the value of X in the cache is 1 (the old value). Subsequently, when retrieving data, the old value in the cache will always be obtained, but in the database, it is 2 (the new value), resulting in inconsistent data between the cache and the database.
[0040] Figure 4 The situation shown is to update the database first and then delete the cache. If there are two threads (Thread A and Thread B) that need to concurrently read and write data, the following scenarios may occur: 1) X doesn't exist in the cache (database X = 1); 2) Thread A reads the database and gets the old value (X = 1); 3) Thread B updates the database (X = 2); 4) Thread B deletes the cache; 5) Thread A writes the old value to the cache (X = 1).
[0041] These two situations can cause an illusion to the user or lead to incorrect operation of the program, both of which will bring unnecessary losses to production.
[0042] The role of the cache lock here is to prevent multiple threads or processes from simultaneously accessing and modifying the cache, ensuring the integrity and consistency of the data before the modification is completed.
[0043] In an exemplary embodiment, updating the portion of the cache data that needs to be changed includes: When the cache lock is successfully acquired, update the portion of the cache data that needs to be changed.
[0044] In an exemplary embodiment, the cache configuration includes deleting cache data and / or updating cache data; The cache configuration includes deleting cache data and / or updating cache data; When the cache configuration includes deleting cache data, delete the portion of the cache data that needs to be changed; When the cache configuration includes updating cache data, first delete the portion of the cache data that needs to be changed, and then reload the portion of the target data that has been changed when the observer is triggered.
[0045] In an exemplary embodiment, the target data includes aggregated data.
[0046] Aggregate data refers to a data set, and the data in the data set is collected from one or more sources.
[0047] In the case where the target data is aggregate data, when the aggregate data in the database is modified, the prior art will delete or reload all of the aggregate data in the cache, while the present application only deletes or reloads the data that has changed in the aggregate data in the cache, thereby reducing the query pressure on the database and reducing the workload of developers.
[0048] In an exemplary embodiment, the aggregate data includes user data, role data, and permission data; Among them, the role data is associated with the user data, and the permission data is associated with the role data.
[0049] The role data being associated with the user data may mean that the role data belongs to the user data. The permission data being associated with the role data may mean that the permission data belongs to the role data. Due to the existence of the subordination relationship, changes in the permission data will involve changes in the permission itself, the role, and the user cache data. Changes in the role data will involve changes in the role itself and the user cache data, while changes in the user data will only involve changes in the user's own cache data.
[0050] In traditional cache management, for single data information, caching can be achieved during query, and the cache needs to be deleted or reloaded during change. For complex data structures, only caching can be achieved during query, and the cache needs to be deleted during change. For example, taking users, roles, and permissions as an example, caching is generally based on users. When user information changes, it can be reloaded or deleted. However, when the associated role or permission information changes, only the cache can be deleted. In the case of changes in user data, only the user data in the cache is deleted or reloaded. However, in the embodiments of the present application, through simple configuration, after the observer detects data changes, only the changed part of the data is loaded. For example, when it is configured to change the cache and the role information changes, only the cache information of the users who have this role change is loaded, rather than reloading all of them. The permission operation is similar, thereby reducing the query pressure on the database and decentralizing the centralized query.
[0051] For aggregated data, in the prior art, when configuring cache management through a user management mechanism, it is necessary to configure users, roles, the relationship between users and roles, permissions, the relationship between permissions and roles, and the relationship between permissions and users. However, for the embodiments of the present application, it is only necessary to associate users, roles, and permissions in the observer. Therefore, compared with the prior art, the embodiments of the present application simplify the cache management configuration. In an exemplary embodiment, the database operations include one or more of the following: data deletion operation, data addition operation, and data modification operation.
[0052] The entire operation of the embodiments of the present application will not cause the cache management to fail due to changes in the background database. The embodiments of the present application can be adapted according to the storage components used in the project. For example, if the project uses an SQL database, it will automatically match to SQL; if the project uses a NoSQL database, it will automatically match to NoSQL. For example, in the integrated management platform of a smart park, there are multiple systems (such as a monitoring system, an access control system, a traffic system, etc.). The data of these systems are respectively stored in different databases (for example, the monitoring system uses an SQL database, the access control system uses a NoSQL database, and the traffic system uses an Oracle database). When the integrated management platform registers the database operations for each system as the observed object and registers the cache management program in the platform as the observer, after the cache management program establishes a connection with the above-mentioned multiple systems, when the data of the observed object changes, the observer will delete or update the changed data according to the cache configuration.
[0053] The embodiments of the present application can be applied to various scenarios. For example, in an e-commerce scenario, the aggregated data may include users, order information associated with the users, payment information associated with the users, the user's recent product browsing records, etc. In the prior art, once the information associated with a certain user changes, all the information associated with that user will be deleted, and it will only be loaded when the user is queried again. For such a scenario, the embodiments of the present application will only update the data of the changed part of that user. In the e-commerce scenario, there may be a business model targeting individual consumers (hereinafter referred to as the ToC model), and this business model mainly serves end-users (i.e., ordinary consumers). In the ToC model, products can be used as the target data, and the products include, but are not limited to, data such as product names, product prices, product introductions, and product inventory quantities. The database operations on the products can be registered as the observed object, the cache management program can be registered as the observer, the product information can be stored in the cache, and an association can be established between the cache management program and the keywords corresponding to the products. When the price of a certain product is changed and saved to the database, it triggers the cache management program to update the price of the product associated with the cache management program. And only the price of a certain product is changed, and other information such as the product inventory quantity is not updated.
[0054] The embodiments of this application can also be applied to the intelligent finance scenario. Financial data can be used as the target data, which includes but is not limited to financial data of financial products such as stocks, futures, foreign exchange, bonds, etc. The financial data includes but is not limited to data such as name, category, price, increase or decrease rate, etc. Database operations on financial data can be registered as the observed, the cache manager (including the cache management program) can be registered as the observer, the financial data can be stored in the cache, and the financial data associated with the cache management program can be established. When database operations such as saving are performed on financial data (for example, changing the price of a certain stock), the cache management program is triggered to update the financial data associated with the cache management program. And only the data involved in the database operation is updated (changing the price of the above-mentioned certain stock and changing the increase or decrease rate associated with the stock price), while the stock category is not updated.
[0055] In a trading system, trading orders can be used as the target data, which includes but is not limited to data such as trading amount, trader, trading commodity name, trading commodity quantity, trading commodity unit price, order ID, etc. Database operations on trading orders can be registered as the observed, the cache manager can be registered as the observer, the trading order information can be stored in the cache, and the trading orders associated with the cache management program can be established. When a certain trading order changes (for example, the trading commodity unit price in the trading order changes), the database operation of saving the new trading commodity unit price will cause the change of the trading commodity unit price in the trading order in the cache and the change of the trading amount related to the trading commodity unit price, while the trading commodity quantity, trader, and order ID are not changed. The trading system here can be the trading system in intelligent finance.
[0056] The following uses an example of a database cache management method to illustrate this application.
[0057] Suppose the target data is User, and the target data includes three parts, namely User itself, Role (role) associated with User, and Permission (permission) associated with Role.
[0058] The cache data UserVO of the target data User can be obtained in the following way: 1) Query User; 2) Query the Role associated with User according to User; 3) Query the Permission associated with Role according to Role; 4) Assemble User; 5) Cache User.
[0059] When caching User, cache data UserVO and cache keywords are obtained. The cache keyword (key) can be user.
[0060] The cache management of the cache data UserVO of the target data User may include the following steps: S51, set the database operation for the target data; S52, register the database operation on the target data User as the observed object; S53, register the program corresponding to the database cache management method as the observer; S54, establish the association between the observed object and the observer; S55, delete or update the part of the target data in the cache that is changed by the triggered database operation according to the triggered database operation, the association between the observed object and the observer, and the cache configuration.
[0061] In S51, for example, saveUser is one of the database operations. saveUser is a save operation, and this operation may induce a series of cache data operations according to the cache configuration. If the cache configuration is deletion, it will induce the deletion of cache data; if the cache configuration is update, the newly changed data will be reloaded in the cache.
[0062] In S54, establishing the connection between the observed object and the observer can establish the cache keywords associated with the observer and establish the corresponding relationship between the observed object and the cache keywords. For example, for saveUser, the connection with the cache keyword "user*" is established. After the save operation is completed, all cache keywords starting with "user" will be operated on. Here, "*" is a wildcard. The operation type can be set when establishing the connection. The default is the update operation, and it can also be deletion or addition. In addition to the matching operation of cache keywords, specific cache keywords can also be specified.
[0063] In S55, when the cache configuration includes the type of cache data and the behavior action trigger, whether to directly delete the cache or need to reload the cache. If only the data of the observed object is changed and the configuration of the observer is deletion, the cache data will be directly deleted without reloading the cache data. When the next data access operation is executed, it will be found that there is no data in the cache, and then the data will be loaded from the database, and this data will be stored in the cache and the new data will be returned to the client. Subsequently, when the visitor accesses this part of the data, the data will be directly obtained from the cache.
[0064] In S55, the process at the database end when the data changes is as Figure 6 shown, and the process at the cache end when the data changes is as Figure 7 shown.
[0065] Using the observer pattern, only the User object needs to be responsible. As long as any data in this object changes, the cache can be cleared or updated in real time according to requirements. If only one thread needs to access the User object currently, the cache can be updated in real time without adding a cache lock. If multiple threads need to access the User object simultaneously, then the cache lock needs to be involved. Because after the data change thread deletes the cache, before it has time to reload the new changed data into the cache, if a large number of threads suddenly come in to access this data and find that there is no data in the cache, then these threads will all query the data from the database, which will cause an avalanche effect. Adding a cache lock can avoid this situation and ensure that at the same time, for the access to the same data, at most only one thread queries the database.
[0066] According to the existing cache management scheme, once the role data or Permission data changes, either the cache of the user data will be directly deleted, or the cache of the user data will be directly reloaded. However, according to the technical solution of the embodiment of the present application, only the cache of the changed data in the user data needs to be deleted, or the cache of the changed data in the user data needs to be updated synchronously, so that only the changed part of the data is updated during the deletion or update process of the cache data, and the unchanged data remains unchanged in the cache, thus effectively reducing the database query pressure. Even if there is a cached data UserListVO (all user data) in the cache now, if the user information changes at this time, if this cache is directly deleted, then all user data will be re-queryed when downloading and obtaining data. However, the technical solution of the embodiment of the present application is to only load the currently updated data and update the updated data into UserListVO, which is the difference between querying one piece of data and N pieces of data.
[0067] Deleting the cache and updating the cache are two different cache management strategies. Deleting the cache is to directly remove the data item from the cache, and reload the data from the data source when reading next time. Updating the cache is to modify the existing data in the cache. The operation of deleting the cache is usually faster than the update operation. The operation of deleting the cache is simple to implement, while the operation of updating the cache is complex to implement and needs to handle the synchronization problem of cache update, such as concurrent update. However, updating the cache can avoid the cache penetration problem (that is, avoid all requests directly accessing the database) and ensure that the data in the cache is always the latest.
[0068] For multiple cached data, such as Figure 8The two pieces of cached data shown are user and task respectively. The data of user (user) includes role (role) and Permission (permission), and the data of task includes taskType.
[0069] According to the technical solution of this application, if each be_observe_object changes, the observe_object that needs to be changed will be found based on the cached data. If the observe_object is not involved, the cached data remains unchanged. If it is involved, the caching operation needs to be determined according to the update attribute value. true requires reloading the data into the cache, and false only clears the cache without reloading the data into the cache. This can achieve flexible configuration of cached data without being restricted to a general processing method. For example, if UserVO internally contains Role and Permission data, when the user data update operation is triggered, the user's own data and role and permission data will be automatically loaded, and developers do not need to perform additional operations.
[0070] In the scenario of a smart park, the smart park management platform includes a presentation layer, a user layer, an application function layer, a service layer, a support layer, etc.; the user layer includes management personnel, investment promotion personnel, operation personnel, financial personnel, security personnel, and tenants, etc. Different permissions can also be set for each type of role personnel. For example, when the cache configuration requires cache change, if the role information changes, only the cache information of the users with this role will be loaded, rather than reloading all of them. The process for permission change is similar to the above role change process.
[0071] This application also provides a database cache management device, as Figure 9 shown, including a memory 100 and a processor 200, The memory 100 is used to save the program for the database cache management method; The processor 200 is used to read and execute the program for the database cache management method, and execute the method described in any of the above embodiments.
[0072] This application also provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to cause the computer to execute the method described in any of the above embodiments.
[0073] This application describes multiple embodiments, but the description is exemplary rather than restrictive, and it will be apparent to those of ordinary skill in the art that there can be more embodiments and implementation solutions within the scope of the embodiments described in this application. Although many possible combinations of features are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are also possible. Unless specifically restricted, any feature or element of any embodiment can be used in combination with any other feature or element in any other embodiment, or can replace any other feature or element in any other embodiment.
[0074] This application includes and contemplates combinations with features and elements known to those of ordinary skill in the art. The embodiments, features, and elements disclosed in this application can also be combined with any conventional features or elements to form unique inventive solutions. Any feature or element of any embodiment can also be combined with features or elements from other inventive solutions to form another unique inventive solution. Therefore, it should be understood that any feature shown and / or discussed in this application can be implemented alone or in any suitable combination. Therefore, the embodiments are not subject to other limitations except those made in accordance with the appended claims and their equivalents. In addition, various modifications and changes can be made within the scope of the appended claims.
[0075] In addition, when describing representative embodiments, the specification may have presented the method and / or process as a particular sequence of steps. However, to the extent that the method or process does not depend on the particular sequence of steps described herein, the method or process should not be limited to the particular sequence of steps described. As will be understood by those of ordinary skill in the art, other sequences of steps are possible. Therefore, the particular sequence of steps set forth in the specification should not be construed as a limitation on the claims. In addition, the claims directed to the method and / or process should not be limited to performing their steps in the order written, as those skilled in the art can readily understand that these orders can vary and still remain within the spirit and scope of the embodiments of this application.
[0076] Those of ordinary skill in the art can understand that all or some of the steps in the methods disclosed above, and the functional modules / units in systems and devices, can be implemented as software, firmware, hardware, and their appropriate combinations. In the hardware implementation, the division of functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, one physical component can have multiple functions, or one function or step can be executed by several physical components in cooperation. Some or all components can be implemented as software executed by a processor, such as a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include a computer storage medium (or non-transitory medium) and a communication medium (or transitory medium). As is well known to those of ordinary skill in the art, the term "computer storage medium" includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cassette, tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, as is well known to those of ordinary skill in the art, a communication medium typically contains computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium.
[0077] In addition, the terms "first", "second", etc. are used for descriptive purposes only and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first", "second", etc. can explicitly or implicitly include at least one of such features.
[0078] In the description of this application, the meaning of "a plurality of" is at least two, such as two, three, etc., unless otherwise specifically defined.
[0079] In this application, unless otherwise clearly specified and limited, the terms "install", "connect", "couple", "fix", etc. should be understood in a broad sense. For example, "connect" can be a fixed connection, a detachable connection, or an integral one; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and can be the internal communication of two elements or the interaction relationship between two elements, unless otherwise clearly limited. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0080] In this application, unless otherwise clearly specified or limited, the first feature being "on" or "under" the second feature may mean that the first and second features are in direct contact, or the first and second features are indirectly in contact through an intermediate medium. Moreover, the first feature being "above", "over" and "on top of" the second feature may mean that the first feature is directly above or obliquely above the second feature, or simply indicates that the horizontal height of the first feature is higher than that of the second feature. The first feature being "under", "below" and "beneath" the second feature may mean that the first feature is directly below or obliquely below the second feature, or simply indicates that the horizontal height of the first feature is less than that of the second feature.
[0081] In the description of this specification, the description with reference to terms such as "an embodiment", "some embodiments", "example", "specific example" or "some examples", etc. means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of this application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0082] Although the embodiments of this application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting this application. Those of ordinary skill in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A database cache management method, comprising: When the observed object is triggered, receiving a notification sent by the observed object to the observer; Determine, according to the notification and the correspondence between the observed person and the cache keyword, a portion of the cache data corresponding to the cache keyword that needs to be changed when the observed person is triggered; According to the cache configuration, the part of the cache data that needs to be changed is deleted or updated; wherein the observed is a database operation on the target data; the observer is a program corresponding to the database cache management method; and the cache keyword is a keyword of the cache data of the target data.
2. The database cache management method according to claim 1, characterized in that: Before the observed person is triggered, the method further includes: Register the database operation on the target data as an observer; register the program corresponding to the database cache management method as an observer; An association is established between the observer and the observed.
3. The database cache management method according to claim 2, characterized in that: The establishing of the association between the observer and the observed comprises: Establish the cache key associated with the observer; Establish a correspondence between the observed object and the cache keyword.
4. The database cache management method according to claim 1, characterized in that: Before updating the portion of the cache data that needs to be changed, the method further includes: acquiring a cache lock to prevent multiple threads or processes from accessing and / or modifying the cache at the same time.
5. The database cache management method according to claim 4, characterized in that: The updating of the portion of the cached data that needs to be changed includes: When the cache lock is successfully acquired, the portion of the cache data that needs to be changed is updated.
6. The database cache management method according to claim 4 or 5, characterized in that: The cache configuration includes deleting cache data and / or updating cache data; When the cache configuration includes deleting cached data, deleting the portion of the cached data that needs to be changed; When the cache configuration includes updating cached data, the portion of the cached data that needs to be changed is first deleted, and then the portion of the target data that is changed when the observer is triggered is reloaded.
7. The database cache management method according to claim 1, characterized in that: The target data includes aggregated data.
8. The database cache management method according to claim 7, characterized in that: The aggregated data includes user data, role data and permission data; The role data belongs to the user data, and the authority data belongs to the role data.
9. The database cache management method according to claim 1, characterized in that: The database operation includes one or more of the following: a data deletion operation, a data addition operation, and a data modification operation.
10. A database cache management device, comprising a memory and a processor, characterized in that: The memory is used to store a program for a database cache management method; The processor is used to read and execute the program for the database cache management method, and execute the method according to any one of claims 1 to 9.
11. A computer-readable storage medium storing computer-executable instructions, wherein: The computer executable instructions are used to cause the computer to execute the method according to any one of claims 1 to 9.