Cache management method and device and electronic equipment
By obtaining cache usage in real time on the cache management platform side and dynamically adjusting cache policies, the problem of developers in the existing technology being unable to perceive cache usage and being unable to dynamically update cache policies is solved, and the effect of reducing development costs is achieved.
Patent Information
- Application Number
- CN202410984536.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2025-03-07
AI Technical Summary
The existing caching scheme makes it impossible for developers to perceive cache usage and cannot dynamically update cache policies, resulting in increased development costs.
By obtaining the usage of other memory caches, memory caches and cache middleware in real time on the cache management platform side, determine the cache adjustment strategy of the corresponding cache, and sending cache adjustment policy instructions to the server to dynamically adjust the current cache strategy.
Enable developers to perceive cache usage in real time and update cache policies dynamically to reduce development costs.
Smart Images

Figure CN119576516A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of distributed cache management, and in particular to a cache management method, device and electronic device. Background Art
[0002] In today's server systems, cache technology is widely used as a common performance optimization method. Existing cache solutions include single service cache, distributed cache, and secondary cache.
[0003] However, existing cache solutions mainly provide cache storage and query functions, as well as some default cache strategies and configurations, which make it impossible for developers to perceive the usage of the cache, such as the used memory size, total memory size, and hit rate, and it is impossible to dynamically update the cache strategy. To implement these functions, additional development work is required, which increases the development costs of developers. Summary of the invention
[0004] In view of this, the present application provides a cache management method, device and electronic device, the main purpose of which is to solve the technical problem that the existing cache solution makes it impossible for developers to perceive the usage of the cache and cannot dynamically update the cache strategy.
[0005] According to a first aspect of the present disclosure, a cache management method is provided, which is applied to a cache management platform for execution, and the method includes:
[0006] Obtain the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time;
[0007] Determine a cache adjustment strategy for a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage;
[0008] A cache adjustment policy instruction corresponding to the cache adjustment policy is sent to the server to dynamically adjust the current cache policies corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0009] According to a second aspect of the present disclosure, a cache management method is provided, which is applied to a server side for execution, and the method includes:
[0010] Receiving a cache adjustment policy instruction sent by a cache management platform;
[0011] Dynamically adjust the current cache policies of other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instructions.
[0012] According to a third aspect of the present disclosure, a cache management device is provided, which is applied to a cache management platform, and includes:
[0013] An acquisition module, used to acquire in real time the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware;
[0014] a determination module, configured to determine a cache adjustment strategy of a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage;
[0015] The first sending module is used to send a cache adjustment policy instruction corresponding to the cache adjustment policy to the server to dynamically adjust the current cache policies corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0016] According to a fourth aspect of the present disclosure, a cache management device is provided, which is applied to a server side, and the device includes:
[0017] A first receiving module, used to receive a cache adjustment policy instruction sent by a cache management platform;
[0018] The adjustment module is used to dynamically adjust the current cache policies of other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instructions.
[0019] According to the fifth aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method of the aforementioned first aspect or execute the method of the aforementioned second aspect.
[0020] According to a sixth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the method of the aforementioned first aspect or execute the method of the aforementioned second aspect.
[0021] According to a seventh aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method of the aforementioned first aspect or executes the method of the aforementioned second aspect.
[0022] The cache management method, device and electronic device provided by the present disclosure, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache and the third cache usage of the cache middleware in real time; determines the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage and the third cache usage; sends a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server to dynamically adjust the current cache strategy corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment strategy corresponding to the cache adjustment strategy instruction. For the scheme of the present disclosure, the first cache usage of other memory caches, the second cache usage of the memory cache and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the usage of the cache, such as the used memory size, the total memory size and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0023] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0026] Figure 1 A schematic diagram of a flow chart of a cache management method provided in an embodiment of the present disclosure;
[0027] Figure 2 The overall structure diagram of the cache management platform provided by the embodiment of the present disclosure;
[0028] Figure 3 A schematic diagram of a flow chart of a cache management method provided in an embodiment of the present disclosure;
[0029] Figure 4A schematic diagram of a flow chart of a cache management method provided in an embodiment of the present disclosure;
[0030] Figure 5 A schematic diagram of a flow chart of a cache management method provided in an embodiment of the present disclosure;
[0031] Figure 6 A schematic diagram of the structure of a cache management device provided by an embodiment of the present disclosure;
[0032] Figure 7 A schematic diagram of the structure of a cache management device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0033] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description. It should be noted that, in the absence of conflict, the embodiments of the present disclosure and the features in the embodiments may be combined with each other.
[0034] The cache management method, device and electronic device according to the embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0035] In order to effectively solve the technical problem that the existing cache solution makes it impossible for developers to perceive the usage of the cache and cannot dynamically update the cache strategy. This embodiment provides a cache management method that can be applied to the cache management platform side, such as Figure 1 As shown, the method includes:
[0036] Step 101: Acquire in real time the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware.
[0037] The cache usage may include information such as the amount of data stored in the cache, the type of data, and the cache size.
[0038] For the embodiment of the present disclosure, the overall structure of the cache management platform is as follows: Figure 2 As shown, it is divided into two parts: the core management platform Cm-boss and Cm-core.
[0039] Among them, the core management platform Cm-boss can be the management and control center of the framework. It can be used to monitor and synchronize the cache, and provide a user interface for users to monitor cache usage. It can also dynamically adjust the size of the memory cache as needed, that is, increase or decrease the memory resources allocated to the cache, adjust the cache strategy, and perform other management operations.
[0040] Cm-core can be the intermediary between the server and the cache management platform. It can be used to handle and manage cache-related operations, including synchronization of cache data, dynamic update of cache strategies, etc. The server can access the cache management platform by introducing the Cm-core jar package.
[0041] A customized RPC (remote procedure call) network layer based on Netty communication and protostuff serialization can be used between the server and the cache management platform to achieve communication and data synchronization between the server and the cache management platform, so that the cache management platform can monitor and manage the cache of each service in real time and perform cache synchronization across nodes.
[0042] Among them, Netty can be a high-performance network application framework for building network-based client and server-side applications; protostuff can be a serialization library for efficiently serializing and deserializing data.
[0043] On the server side, developers need to add annotations to the cache method and set cache-related parameters, such as whether to use Redis, memory cache, or secondary cache as the cache type. Finally, configure the connection parameters of the management platform in the server configuration file.
[0044] As an IO-intensive application, the cache management platform needs to be able to handle multiple requests from the server and send requests to the server based on the operations on the management page. To meet these requirements, the cache management platform uses the following technology selection and communication mechanisms:
[0045] 1) Technology selection: Webflux, Netty and Protostuff
[0046] Among them, Webflux can be a flow-based asynchronous responsive model suitable for processing a large number of concurrent requests. It is used to process a large number of concurrent requests, reduce the blocking and waiting time of concurrent threads, and improve system throughput.
[0047] Netty is an asynchronous non-blocking network application framework responsible for the underlying network communication and result parsing. It avoids thread blocking and context switching overhead by using an event-driven mechanism.
[0048] Protostuff is a serialization framework used to serialize and deserialize data streams between servers and clients. Compared with Java's own serialization tools, JSON, and XML, Protostuff has a faster and more intensive serialization and deserialization process. Protostuff can be used to compile request parameters into binary byte streams for network transmission.
[0049] 2) Communication mechanism:
[0050] Combine Webflux, Netty and Protostuff to build a high-performance communication mechanism.
[0051] Among them, Webflux can be responsible for processing business logic and building responses, Netty can be responsible for underlying network communication and result parsing, and Protostuff can be responsible for serializing and deserializing data. Through this combination, the communication mechanism of the cache management platform can replace the traditional HTTP-based network interaction method and improve the communication efficiency between the management platform and the server.
[0052] In order to further improve the performance of the cache management platform and the server under a large number of concurrent requests, the event-based Disruptor queue model is introduced to handle various request interactions between Cm-core and the cache management platform. Disruptor can use ring buffers and CAS (Compare and Swap) to implement lock-free concurrent algorithms, and also optimizes memory, making it very suitable for handling large-scale concurrent events. Once the server is initialized, even if a large number of requests trigger cache synchronization and update events, Disruptor can handle them in an orderly and efficient manner. Through lock-free concurrent algorithms and memory optimization, Disruptor can achieve high-performance event processing and avoid the competition and overhead brought by traditional lock mechanisms. After introducing the Disruptor model, the cache management platform and the server can better cope with the scenario of large-scale concurrent requests, improve the system's throughput and concurrent processing capabilities, and ensure that the cache management platform can quickly and efficiently handle a large number of cache synchronization and update events brought by various requests.
[0053] The cache management platform also provides real-time cache monitoring and statistics. By integrating the high-performance cache framework Caffeine, you can track cache hit rate, loading time, cleanup times and other indicators, and obtain the server's memory cache status in real time through the cache management platform. In addition, the cache management platform also supports dynamic modification of cache strategies, and you can configure and modify cache strategies through the cache management platform, such as expiration time, cache start and stop, cache level, etc.
[0054] Specifically, the cache management platform can perform add, delete, modify and query operations through the API of the cache middleware (such as Redis); for the capacity management of the cache middleware, the cache management platform provides a special capacity expansion tool, which allows the cache management platform to adjust the storage capacity of the cache middleware as needed, such as increasing the capacity when the Redis storage space is insufficient, or reducing the capacity when it is not needed.
[0055] By integrating the high-performance cache framework Caffeine as the memory cache library, the cache management platform can obtain the server's memory cache status (i.e. cache usage) in real time, including key indicators such as cache hit rate, loading time, and cleanup times.
[0056] Among them, Caffeine may be a high-performance Java cache library for providing cache strategies and functions.
[0057] Correspondingly, the cache management platform can obtain in real time the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware.
[0058] Step 102: Determine a cache adjustment strategy for a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage.
[0059] For the embodiments of the present disclosure, by monitoring cache usage, the usage patterns and performance analysis results of different cache layers can be analyzed and obtained, and the cache adjustment strategy for each cache layer can be determined based on the analysis results. For example, for a cache layer with a low cache hit rate, the cache adjustment strategy may be to increase the cache capacity of the cache layer with a low hit rate.
[0060] Step 103: Send a cache adjustment policy instruction corresponding to the cache adjustment policy to the server to dynamically adjust the current cache policies corresponding to other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0061] For the embodiments of the present disclosure, when it is determined that the cache strategy needs to be modified, the cache management platform can send a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server, and the Cm-core of the server can use the Bean management function of Spring Boot to dynamically update the cache strategy of Caffeine.
[0062] For the embodiments of the present disclosure, the cache management platform can also save the cache strategy of each method modified by the cache annotation in a cache strategy set, so that the cache behavior of each method can be independently configured, such as cache expiration time, cache level, etc.
[0063] The cache policy management of the unified control module can be used to uniformly manage the cache policy set, so that all cache policies can be configured and modified in a centralized location, which is convenient for user operation and maintenance.
[0064] Users can dynamically configure and modify the cache strategy of the method through the cache management platform, for example, modify the expiration time, start and stop caching, modify the cache level, etc., so that users can flexibly adjust the cache strategy according to actual business needs and system load conditions.
[0065] Through the above functions, the cache management platform can provide real-time monitoring, optimization and management of cache middleware and memory cache, thereby improving the performance and maintainability of the system; and users can adjust the cache strategy according to actual conditions to adapt to different business scenarios and system loads, thereby ensuring efficient operation of the system and rational use of resources.
[0066] In summary, the cache management method, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; determines the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; sends a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server to dynamically adjust the current cache strategy corresponding to the other memory caches, the memory cache, and the cache middleware to the cache adjustment strategy corresponding to the cache adjustment strategy instruction. For the scheme disclosed in the present disclosure, the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the usage of the cache, such as the used memory size, the total memory size, and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0067] Further, as a refinement and extension of the above embodiment, in order to fully illustrate the specific implementation process of the method of this embodiment, this embodiment provides the following Figure 3 The specific method shown comprises the following steps:
[0068] Step 201: Receive a synchronous cache update request sent by a server, and asynchronously send the synchronous cache update request to other memory caches to synchronize cache data of other memory caches with the memory cache and cache middleware.
[0069] The synchronous update cache request may be used to indicate cache data of other memory caches that need to be synchronously updated.
[0070] For the embodiments of the present disclosure, Figure 2 As shown, after receiving the synchronous cache update request sent by the server, the cache management platform will forward the synchronous cache update request to other memory caches, so that other memory caches receive the synchronous cache update command.
[0071] On other memory caches, the event queue responsible for processing requests will asynchronously send the synchronous update cache command to the unified control module after receiving the synchronous update cache command.
[0072] The unified control module may be responsible for performing actual cache synchronization operations and checking cache consistency to ensure that cache data on each cache node is consistent.
[0073] Through the above steps, Cm-core can realize the addition of cache and synchronize it in multiple nodes to ensure that users can get the latest cache data no matter which cache node they access, thereby maintaining the data consistency and performance of the system.
[0074] Correspondingly, the synchronous cache update request sent by the server is received, and the synchronous cache update request is asynchronously sent to other memory caches to synchronize the cache data of other memory caches with the memory cache and the cache middleware.
[0075] For the embodiment of the present disclosure, in order to ensure that the cache data on each cache node is consistent, as a possible implementation method, the first cache data of other memory caches, the second cache data of the memory cache, and the third cache data of the cache middleware may be monitored;
[0076] If the first cache data is different from the second cache data and the third cache data, the request data corresponding to the synchronous update cache request is added to the data cache of other memory caches to make the first cache data the same as the second cache data and the third cache data.
[0077] Step 202: Receive the synchronous cache deletion request sent by the server, and asynchronously send the synchronous cache deletion request to other memory caches to delete the data to be deleted in other memory caches, so as to synchronize the cache data of other memory caches with the memory cache and cache middleware.
[0078] The synchronous cache deletion request may be used to indicate the data to be deleted in other memory caches that need to be synchronously deleted.
[0079] For the embodiments of the present disclosure, Figure 2 As shown, after receiving the synchronous cache deletion request sent by the server, the cache management platform will forward the synchronous cache deletion request to other memory caches, so that other memory caches receive the synchronous cache deletion command.
[0080] On other memory caches, the event queue responsible for processing the request will asynchronously send the synchronous cache deletion command to the unified control module after receiving the synchronous cache deletion command.
[0081] The unified control module may be responsible for performing actual cache deletion operations and checking cache consistency to ensure that cache data on each cache node is consistent.
[0082] Through the above steps, Cm-core can delete the cache and synchronize it in multiple nodes to ensure that users can get the latest cache data no matter which cache node they access, thereby maintaining the data consistency and performance of the system.
[0083] Correspondingly, the synchronous cache deletion request sent by the server is received, and the synchronous cache deletion request is asynchronously sent to other memory caches to delete the data to be deleted in other memory caches, so that the cache data of other memory caches, memory caches and cache middleware are synchronized.
[0084] For the embodiment of the present disclosure, in order to ensure that the cache data on each cache node is consistent, as a possible implementation method, the first cache data of other memory caches, the second cache data of the memory cache, and the third cache data of the cache middleware may be monitored;
[0085] If the first cache data is different from the second cache data and the third cache data, the data to be deleted in other memory caches are deleted again to make the first cache data the same as the second cache data and the third cache data.
[0086] In summary, the cache management method, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; determines the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; sends a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server to dynamically adjust the current cache strategy corresponding to the other memory caches, the memory cache, and the cache middleware to the cache adjustment strategy corresponding to the cache adjustment strategy instruction. For the scheme disclosed in the present disclosure, the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the usage of the cache, such as the used memory size, the total memory size, and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0087] The above embodiment is a cache management process described on the cache management platform side. Further, in order to fully illustrate the implementation of this embodiment, this embodiment also provides another cache management method that can be applied to the server side. Figure 4 As shown, the method includes:
[0088] Step 301: Receive a cache adjustment policy instruction sent by a cache management platform.
[0089] The cache adjustment policy instruction may be used to indicate policy parameters for adjusting the cache.
[0090] Step 302: Dynamically adjust the current cache policies of other memory caches, memory caches, and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0091] Among them, the current cache policy can be the cache policy being used by the memory cache, memory cache and cache middleware before receiving the cache adjustment policy instruction. The current cache policy can be set during cache initialization or set through previous adjustment instructions of the cache management platform.
[0092] The cache adjustment policy may be a policy for adjusting the current cache policy according to the cache adjustment policy instruction.
[0093] For the disclosed embodiment, after the server receives the cache adjustment strategy instruction sent by the cache management platform, the Cm-core of the server can dynamically update the cache strategy of Caffeine by using the Bean management function of Spring Boot.
[0094] Specifically, the server can obtain all currently cached key-value pairs, build a new Caffeine instance according to the new cache strategy, and put the original key-value pairs into the new Caffeine instance to replace the original Bean object, that is, use the new Caffeine instance to replace the old cache. In this way, the server can realize dynamic update of the memory cache, that is, adjust the cache strategy in real time without interrupting the service to adapt to different business needs and system loads.
[0095] Correspondingly, the server can receive the cache adjustment policy instruction sent by the cache management platform, and dynamically adjust the current cache policies of other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0096] In summary, the cache management method, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; determines the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; sends a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server to dynamically adjust the current cache strategy corresponding to the other memory caches, the memory cache, and the cache middleware to the cache adjustment strategy corresponding to the cache adjustment strategy instruction. For the scheme disclosed in the present disclosure, the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the usage of the cache, such as the used memory size, the total memory size, and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0097] Further, as a refinement and extension of the above embodiment, in order to fully illustrate the specific implementation process of the method of this embodiment, this embodiment provides the following Figure 5 The specific method shown comprises the following steps:
[0098] Step 401, receive a data request, search for request data corresponding to the data request in the memory cache and cache middleware, if not found, search for the request data in the database, and synchronously update the found request data to the memory cache and cache middleware. After updating the memory cache and cache middleware, send a synchronous update cache request to the cache management platform to synchronize the cache data of other memory caches with the memory cache and cache middleware.
[0099] For the embodiments of the present disclosure, the server can receive data requests sent by clients and users, etc. The server can use Cm-core to try to obtain request data corresponding to the data request from the memory cache and cache middleware through reverse proxy. If there is no request data in the memory cache and the cache middleware (that is, the cache misses), Cm-core can obtain the request data from the actual database.
[0100] Once Cm-core obtains the request data, no matter whether the request data is an actual value or an empty value, Cm-core will asynchronously store the request data in the cache middleware and memory cache through the event monitoring queue to prevent future data requests from penetrating the cache again to reach the data source, thereby protecting the data source from being affected by excessive requests.
[0101] In this way, Cm-core completes cache synchronization on a single node, ensuring that the requested data can be quickly obtained and stored in the cache so that subsequent requests can be responded to more quickly.
[0102] For the embodiments of the present disclosure, when obtaining request data corresponding to a data request from a memory cache and a cache middleware, since the memory cache has the characteristic of fast access, it is necessary to first search for the request data corresponding to the data request from the memory cache. If the request data is found in the memory cache, it can be used directly, thus avoiding slower cache middleware or database queries.
[0103] If the request data is not found in the memory cache, the cache middleware is used to look up the request data corresponding to the data request. The access speed of cache middleware (such as Redis) is usually slower than that of memory cache. If the request data is not found in the cache middleware, the database is queried to obtain the request data and stored in the memory cache and cache middleware for subsequent use.
[0104] After the single-node cache synchronization is completed, Cm-core can send a synchronization update cache request to the cache management platform through a custom RPC network layer.
[0105] Accordingly, as a possible implementation method, a data request may be received, and request data corresponding to the data request may be searched in a memory cache; if the request data does not exist in the memory cache, the request data corresponding to the data request may be searched in a cache middleware;
[0106] If the request data does not exist in the cache middleware, the request data is searched in the database, and the found request data is synchronously updated to the memory cache and the cache middleware;
[0107] After the memory cache and cache middleware are updated, a synchronous cache update request is sent to the cache management platform to synchronize the cache data of other memory caches with the memory cache and cache middleware.
[0108] Accordingly, as a possible implementation method, the found request data is synchronously updated to the memory cache and the cache middleware, which may specifically include:
[0109] Add the data update event corresponding to the request data to the event monitoring queue; use the event monitoring queue to asynchronously store the request data in the memory cache and cache middleware;
[0110] Use the event monitoring queue to asynchronously monitor whether there is request data in the memory cache and / or cache middleware; if the request data does not exist in the memory cache and / or cache middleware, repeatedly use the event monitoring queue to asynchronously store the request data in the memory cache and / or cache middleware until the request data exists in the memory cache and / or cache middleware.
[0111] Step 402: Receive a data deletion request, delete the data to be deleted corresponding to the data deletion request in the database, cache middleware and memory cache based on the data deletion request, and send a synchronous cache deletion request to the cache management platform to delete the data to be deleted corresponding to other memory caches, so that the cache data of other memory caches is synchronized with the memory cache and cache middleware.
[0112] According to the disclosed embodiment, when a method for deleting or updating a database is annotated with a cache deletion annotation, Cm-core may execute a data deletion or update operation within the database.
[0113] As a possible implementation method, the server can receive a data deletion request, and the server can use Cm-core to first execute the data deletion operation in the database through a reverse proxy, then execute the data deletion operation in the cache middleware, and finally execute the data deletion operation in the memory cache.
[0114] Cm-core can send the deletion event to the deletion event queue and return the processing result. The processing result can be used to indicate that the cache deletion operation has been successfully submitted.
[0115] When Cm-core executes a cache deletion operation, it not only deletes the cache on the local node, but also sends a synchronous cache deletion request to the cache management platform to notify other nodes to perform synchronous cache deletion.
[0116] Accordingly, as a possible implementation method, a data deletion request may be received, and a deletion event corresponding to the data deletion request may be added to a deletion event queue; the deletion event queue may be used to asynchronously search for the to-be-deleted data corresponding to the data deletion request in the database, and the to-be-deleted data in the database may be deleted;
[0117] After deleting the data to be deleted in the database, use the deletion event queue to asynchronously search for the data to be deleted corresponding to the data deletion request in the cache middleware, and delete the data to be deleted in the cache middleware;
[0118] After deleting the data to be deleted in the cache middleware, use the deletion event queue to asynchronously search for the data to be deleted corresponding to the data deletion request in the memory cache, and delete the data to be deleted in the memory cache;
[0119] After deleting the corresponding data to be deleted in the database, cache middleware and memory cache, a synchronous cache deletion request is sent to the cache management platform to delete the corresponding data to be deleted in other memory caches, so that the cache data of other memory caches is synchronized with the memory cache and cache middleware.
[0120] Step 403: Use the deletion event queue to asynchronously monitor the deletion event. If a deletion event is detected, query the main database in the database, and update the latest queried data to the memory cache and cache middleware.
[0121] For the embodiments of the present disclosure, after deleting the data to be deleted corresponding to the data deletion request in the database, cache middleware and memory cache, the deletion event queue can asynchronously perform a cache consistency check. The consistency check here can be used to prevent the situation where the master database data has been modified but the slave database data has not been synchronized in time when using a master-slave database. When the query operation reads the slave database, the old data is stored in the cache, resulting in dirty data.
[0122] Among them, in the master-slave database architecture, the master database can be responsible for processing all write operations, while the slave database can be responsible for processing read operations. The data in the master database is the latest, while the data in the slave database may not have synchronized the latest changes.
[0123] When the asynchronous thread in the deletion event queue listens to the deletion event, the asynchronous thread will trigger the query method of the deletion event again and specify that the query operation is executed from the main database to query the latest data in the main database and update the latest data to the memory cache and cache middleware to keep the cached data in the memory cache and cache middleware consistent with the latest data in the main database.
[0124] This mechanism ensures that in a master-slave database environment, the data in the cache is consistent with the latest data in the master database, avoiding dirty data problems caused by data inconsistency. This consistency check and cache update operation is performed by an asynchronous thread in the delete event queue to avoid blocking the main thread and improve the system's response speed.
[0125] In summary, the cache management method, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; determines the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; sends a cache adjustment strategy instruction corresponding to the cache adjustment strategy to the server to dynamically adjust the current cache strategy corresponding to the other memory caches, the memory cache, and the cache middleware to the cache adjustment strategy corresponding to the cache adjustment strategy instruction. For the scheme disclosed in the present disclosure, the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the usage of the cache, such as the used memory size, the total memory size, and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0126] Based on the above Figure 1 and Figure 3 The present disclosure provides a cache management device that can be applied to a cache management platform side, such as Figure 6 As shown, the device includes: an acquisition module 31, a determination module 32, and a first sending module 33;
[0127] An acquisition module 31 is used to acquire in real time the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware;
[0128] A determination module 32, configured to determine a cache adjustment strategy of a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage;
[0129] The first sending module 33 is used to send a cache adjustment policy instruction corresponding to the cache adjustment policy to the server to dynamically adjust the current cache policies corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
[0130] In specific application scenarios, such as Figure 6 As shown, the device further includes: a second receiving module 34, a first monitoring module 35 and an adding module 36;
[0131] A second receiving module 34 is used to receive a synchronous cache update request sent by the server, and asynchronously send the synchronous cache update request to the other memory cache to synchronize the cache data of the other memory cache with the memory cache and the cache middleware;
[0132] A first monitoring module 35, configured to monitor first cache data of the other memory cache, monitor second cache data of the memory cache, and monitor third cache data of the cache middleware;
[0133] The adding module 36 is used to add the request data corresponding to the synchronous update cache request to the data cache of the other memory cache if the first cache data is different from the second cache data and the third cache data, so that the first cache data is the same as the second cache data and the third cache data.
[0134] In specific application scenarios, such as Figure 6 As shown, the device further includes: a third receiving module 37, a second monitoring module 38 and a deleting module 39;
[0135] The third receiving module 37 is used to receive the synchronous cache deletion request sent by the server, and asynchronously send the synchronous cache deletion request to other memory caches to delete the data to be deleted in the other memory caches, so that the cache data of the other memory caches, the memory caches and the cache middleware are synchronized;
[0136] A second monitoring module 38, configured to monitor the first cache data of the other memory cache, monitor the second cache data of the memory cache, and monitor the third cache data of the cache middleware;
[0137] The deleting module 39 is used to re-delete the to-be-deleted data in the other memory cache if the first cache data is different from the second cache data and the third cache data, so that the first cache data is the same as the second cache data and the third cache data.
[0138] It should be noted that for other corresponding descriptions of the functional units involved in the cache management device applicable to the cache management platform provided in this embodiment, please refer to Figure 1 and Figure 3 The corresponding description of the method in will not be repeated here.
[0139] Further, as Figure 4 and Figure 5 The specific implementation of the method shown in the embodiment provides a cache management device that can be applied to the server side, such as Figure 7 As shown, the device includes: a first receiving module 41 and an adjusting module 42.
[0140] A first receiving module 41 is used to receive a cache adjustment policy instruction sent by a cache management platform;
[0141] The adjustment module 42 is used to dynamically adjust the current cache policies of other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instructions.
[0142] In specific application scenarios, such as Figure 7 As shown, the device further includes: a fourth receiving module 43, a first searching module 44, a second searching module 45, and a second sending module 46;
[0143] A fourth receiving module 43, configured to receive a data request and search the memory cache for request data corresponding to the data request;
[0144] A first search module 44, configured to search for request data corresponding to the data request in a cache middleware if the request data does not exist in the memory cache;
[0145] A second search module 45 is used to search for the request data in a database if the request data does not exist in the cache middleware, and synchronously update the searched request data to the memory cache and the cache middleware;
[0146] The second sending module 46 is used to send a synchronous cache update request to the cache management platform after updating the memory cache and the cache middleware, so as to synchronize the cache data of other memory caches with the memory cache and the cache middleware.
[0147] In a specific application scenario, the second search module 45 can be used to add the data update event corresponding to the request data to the event monitoring queue; use the event monitoring queue to asynchronously store the request data in the memory cache and the cache middleware;
[0148] The event monitoring queue is used to asynchronously monitor whether the request data exists in the memory cache and / or the cache middleware; if the request data does not exist in the memory cache and / or the cache middleware, the event monitoring queue is repeatedly used to asynchronously store the request data in the memory cache and / or the cache middleware until the request data exists in the memory cache and / or the cache middleware.
[0149] In specific application scenarios, such as Figure 7 As shown, the device further includes: a fifth receiving module 47, a third searching module 48, a fourth searching module 49, a fifth searching module 50 and a third sending module 51;
[0150] A fifth receiving module 47, configured to receive a data deletion request, and add a deletion event corresponding to the data deletion request to a deletion event queue;
[0151] A third search module 48 is used to asynchronously search the database for the data to be deleted corresponding to the data deletion request using the deletion event queue, and delete the data to be deleted in the database;
[0152] A fourth search module 49, configured to asynchronously search the cache middleware for the data to be deleted corresponding to the data deletion request by using the deletion event queue after deleting the data to be deleted in the database, and delete the data to be deleted in the cache middleware;
[0153] A fifth search module 50, configured to asynchronously search the memory cache for the data to be deleted corresponding to the data deletion request by using the deletion event queue after deleting the data to be deleted in the cache middleware, and delete the data to be deleted in the memory cache;
[0154] The third sending module 51 is used to send a synchronous cache deletion request to the cache management platform after deleting the corresponding data to be deleted in the database, the cache middleware and the memory cache, so as to delete the data to be deleted corresponding to other memory caches, so as to synchronize the cache data of the other memory caches with the memory cache and the cache middleware.
[0155] In specific application scenarios, such as Figure 7 As shown, the device further includes: a third monitoring module 52;
[0156] The third monitoring module 52 is used to asynchronously monitor deletion events using a deletion event queue. If the deletion event is detected, the main database in the database is queried, and the latest queried data is updated to the memory cache and the cache middleware.
[0157] It should be noted that for other corresponding descriptions of the functional units involved in the cache management device provided by the present disclosure, please refer to Figure 4 and Figure 5 The corresponding description in will not be repeated here.
[0158] Based on the above Figure 1 and Figure 3 as well as Figure 4 and Figure 5 The method shown in the present disclosure, accordingly, also provides a computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned Figure 1 and Figure 3 as well as Figure 4 and Figure 5 The method shown.
[0159] Based on this understanding, the technical solution of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of various implementation scenarios of the present disclosure.
[0160] Based on the above Figure 1 and Figure 3 as well as Figure 4 and Figure 5 The method shown, and Figure 6 and Figure 7 In order to achieve the above-mentioned purpose, the embodiment of the present disclosure also provides an electronic device that can be configured on the vehicle (such as an electric vehicle) side, and the device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1 and Figure 3 as well as Figure 4 and Figure 5 The method shown.
[0161] Optionally, the above-mentioned physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0162] Those skilled in the art will appreciate that the above-mentioned physical device structure provided by the present disclosure does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.
[0163] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the above-mentioned physical device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.
[0164] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present disclosure can be implemented by means of software plus a necessary general hardware platform, or by hardware. According to the cache management method, device, and electronic device provided by the present disclosure, compared with the prior art, the present disclosure obtains the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; determines the cache adjustment policy of the corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; sends a cache adjustment policy instruction corresponding to the cache adjustment policy to the server to dynamically adjust the current cache policies corresponding to other memory caches, memory caches, and cache middleware to the cache adjustment policy corresponding to the cache adjustment policy instruction. For the disclosed solution, the first cache usage of other memory caches, the second cache usage of the memory cache and the third cache usage of the cache middleware can be obtained in real time through the cache management platform, so that the developer can perceive the cache usage, such as the used memory size, the total memory size and the hit rate, etc., and can determine the cache adjustment strategy of the corresponding cache according to the first cache usage, the second cache usage and the third cache usage, so as to dynamically adjust the cache adjustment strategy of the current cache strategy, so that the cache strategy can be dynamically updated without the need for additional development work, thereby reducing the development cost of the developer.
[0165] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0166] The above are only specific embodiments of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments herein, but will conform to the widest scope consistent with the principles and novel features applied herein.
Claims
1. A cache management method, characterized in that: Applied to the cache management platform side for execution, the method includes: Obtain the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware in real time; Determine a cache adjustment strategy for a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; A cache adjustment policy instruction corresponding to the cache adjustment policy is sent to the server to dynamically adjust the current cache policies corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
2. The method according to claim 1, characterized in that The method further comprises: Receiving a synchronous cache update request sent by the server, and asynchronously sending the synchronous cache update request to the other memory cache, so that the cache data of the other memory cache is synchronized with the memory cache and the cache middleware; Monitoring first cache data of the other memory cache, monitoring second cache data of the memory cache, and monitoring third cache data of the cache middleware; If the first cache data is different from the second cache data and the third cache data, the request data corresponding to the synchronous update cache request is added to the data cache of the other memory cache to make the first cache data the same as the second cache data and the third cache data.
3. The method according to claim 1, characterized in that The method further comprises: Receive a synchronous cache deletion request sent by the server, and asynchronously send the synchronous cache deletion request to other memory caches to delete the data to be deleted in the other memory caches, so that the cache data of the other memory caches, the memory caches and the cache middleware are synchronized; Monitoring first cache data of the other memory cache, monitoring second cache data of the memory cache, and monitoring third cache data of the cache middleware; If the first cache data is different from the second cache data and the third cache data, the to-be-deleted data in the other memory caches are deleted again to make the first cache data the same as the second cache data and the third cache data.
4. A cache management method, characterized in that: Applied to the server side for execution, the method includes: Receiving a cache adjustment policy instruction sent by a cache management platform; The current cache policies of other memory caches, memory caches and cache middleware are dynamically adjusted to the cache adjustment policies corresponding to the cache adjustment policy instructions.
5. The method according to claim 4, characterized in that The method further comprises: Receive a data request, and search the memory cache for request data corresponding to the data request; If the requested data does not exist in the memory cache, searching for the request data corresponding to the data request in the cache middleware; If the request data does not exist in the cache middleware, the request data is searched in the database, and the found request data is synchronously updated to the memory cache and the cache middleware; After the memory cache and the cache middleware are updated, a synchronous cache update request is sent to a cache management platform to synchronize cache data of other memory caches with the memory cache and the cache middleware.
6. The method according to claim 5, characterized in that The synchronously updating the found request data to the memory cache and the cache middleware includes: Adding a data update event corresponding to the request data to an event monitoring queue; Using the event monitoring queue to asynchronously store the request data in the memory cache and the cache middleware; Using the event monitoring queue to asynchronously monitor whether the request data exists in the memory cache and / or the cache middleware; If the request data does not exist in the memory cache and / or the cache middleware, the event monitoring queue is repeatedly used to asynchronously store the request data in the memory cache and / or the cache middleware until the request data exists in the memory cache and / or the cache middleware.
7. The method according to claim 4, characterized in that The method further comprises: Receive a data deletion request, and add a deletion event corresponding to the data deletion request to a deletion event queue; Using the deletion event queue to asynchronously search the database for data to be deleted corresponding to the data deletion request, and deleting the data to be deleted in the database; After deleting the data to be deleted in the database, asynchronously searching the cache middleware for the data to be deleted corresponding to the data deletion request using the deletion event queue, and deleting the data to be deleted in the cache middleware; After deleting the data to be deleted in the cache middleware, asynchronously searching the memory cache for the data to be deleted corresponding to the data deletion request using the deletion event queue, and deleting the data to be deleted in the memory cache; After deleting the corresponding data to be deleted in the database, the cache middleware and the memory cache, a synchronous cache deletion request is sent to the cache management platform to delete the data to be deleted corresponding to other memory caches, so that the cache data of the other memory caches is synchronized with the memory cache and the cache middleware.
8. The method according to claim 7, characterized in that The method further comprises: The deletion event queue is used to asynchronously monitor the deletion event. If the deletion event is monitored, the main database in the database is queried, and the latest queried data is updated to the memory cache and the cache middleware.
9. A cache management device, characterized in that: Applied to the cache management platform side, the device includes: An acquisition module, used to acquire in real time the first cache usage of other memory caches, the second cache usage of the memory cache, and the third cache usage of the cache middleware; a determination module, configured to determine a cache adjustment strategy of a corresponding cache according to the first cache usage, the second cache usage, and the third cache usage; The first sending module is used to send a cache adjustment policy instruction corresponding to the cache adjustment policy to the server to dynamically adjust the current cache policies corresponding to the other memory caches, the memory cache and the cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instruction.
10. A cache management device, characterized in that: Applied to the server side, the device includes: A first receiving module, used to receive a cache adjustment policy instruction sent by a cache management platform; The adjustment module is used to dynamically adjust the current cache policies of other memory caches, memory caches and cache middleware to the cache adjustment policies corresponding to the cache adjustment policy instructions.
11. A non-transitory computer-readable storage medium having computer instructions stored thereon, characterized in that: The computer instructions are used to make a computer execute the method as claimed in claims 1-3, or the method as claimed in claims 4-8.
12. A computer program product, characterized in that The method comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 3, or the method according to claims 4 to 8.