Cache processing method and apparatus, storage medium and electronic device

By configuring a central server to coordinate cache change events across multiple application nodes, the cache data consistency issue between distributed nodes in a multi-computer room environment is resolved, enabling efficient cache data refresh and query result consistency, and improving the system's scalability and response speed.

WO2025200526A1PCT designated stage Publication Date: 2025-10-02CHINA TELECOM BESTPAY CO LTD

Patent Information

Application Number
PCT/CN2024/135616
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-03-27
Filing Date
2024-11-29
Publication Date
2025-10-02

AI Technical Summary

Technical Problem

In a multi-computer room parallel computing environment, existing technologies cannot effectively solve the cache data consistency problem between distributed nodes. Especially when Redis is deployed independently in each computer room, the cache refresh mechanism across computer rooms has limitations.

Method used

The configuration center server coordinates multiple application nodes, responds to cache change events, publishes cache change events to other nodes, and updates their data storage status based on the events. The event publisher and receiver mechanism is used to ensure data consistency among nodes, reduce dependence on Redis, and use Nacos or Dubbo as the configuration center to implement notifications and broadcasts.

Benefits of technology

It achieves cache data consistency among distributed nodes in a multi-computer room environment, improves the scalability and response speed of the system, reduces the frequency of database access, and ensures the consistency and availability of query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024135616_02102025_PF_FP_ABST
    Figure CN2024135616_02102025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application are a cache processing method and apparatus, a storage medium and an electronic device. The method comprises: determining a plurality of application nodes matched with an initial data storage state, and a predetermined configuration center server that separately interacts with the plurality of application nodes, the plurality of application nodes being interactively-isolated distributed nodes; when a cache change event occurs in a target node among the plurality of application nodes, in response to the interaction between the target node and the configuration center server, publishing the cache change event to the other nodes among the plurality of application nodes; and, on the basis of the cache change event, updating the initial data storage states of the other nodes, so as to obtain the other nodes that have been refreshed to a target data storage state.
Need to check novelty before this filing date? Find Prior Art

Description

Cache processing method, device, storage medium and electronic device

[0001] Related applications

[0002] This application claims priority to Chinese patent application number 2024103610718, filed on March 27, 2024, entitled “Cache processing method, device, storage medium and electronic device”, the entire text of which is hereby incorporated by reference. Technical Field

[0003] The present application relates to the fields of Internet technology and cache technology, and more specifically, to a cache processing method, device, storage medium, and electronic device. Background Art

[0004] In today's microservices architecture, multi-datacenter parallel computing systems are widely used, such as the new modular architecture. Traditional development methods face challenges with this concept. Local caching, as a high-performance caching model, can cause inconsistencies in the local caches of application server nodes when cached content needs to change. This can lead to data inconsistencies between local caches.

[0005] Related technologies typically publish events through Redis (Remote Dictionary Server, an open-source, in-memory data structure storage system), and other nodes listen for these events to refresh cached data and ensure consistency across nodes. However, in the context of multi-computer room parallel computing, since each computer room does not share a single Redis cluster but is independently deployed, and an application typically does not connect to another computer room's Redis cluster, data consistency in interactively isolated scenarios is limited, and cannot meet the cache refresh consistency requirements across distributed nodes in multi-computer room parallel computing.

[0006] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention

[0007] According to a first aspect of an embodiment of the present application, a cache processing method is provided, comprising: determining a plurality of application nodes that match an initial data storage state, and a predetermined configuration center server that interacts with the plurality of application nodes respectively, wherein the plurality of application nodes are distributed nodes with interaction isolation; in a case where a cache change event occurs at a target node among the plurality of application nodes, in response to the interaction between the target node and the configuration center server, publishing the cache change event to other nodes among the plurality of application nodes; based on the cache change event, updating the initial data storage state of the other nodes to obtain the other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query based on the other nodes of the target data storage state matches a second query result of a predetermined query based on the target node where the cache change event occurs.

[0008] Optionally, the multiple application nodes are respectively provided with an event publisher, and the event publisher is used to interact with the configuration center server. The method also includes: sending the cache identifiers corresponding to the multiple application nodes respectively through the event publishers corresponding to the multiple application nodes, and generating node cache information on the configuration center server.

[0009] Optionally, in response to the interaction between the target node and the configuration center server, publishing the cache change event to other nodes among the multiple application nodes includes: publishing the target parameters indicated by the cache change event to the configuration center server through the event publisher of the target node as the interaction between the target node and the configuration center server; in response to the interaction between the target node and the configuration center server, based on the target parameters, changing the node cache information to obtain updated cache information in the configuration center server; and publishing the cache change event to the other nodes when the event publisher of the other nodes detects the updated cache information.

[0010] Optionally, after the target parameters of the cache change event indication are published to the configuration center server through the event publisher of the target node, the method further includes: determining the publishing result of executing the publishing to the configuration center server through the event publisher of the target node; when the publishing result indicates that the publishing failed, executing a predetermined number of retry publishings to the configuration center server through the event publisher of the target node to obtain a retry result; when the retry result indicates that there is a retry failure, sending an alarm message indicating the publishing failure to the predetermined receiving end.

[0011] Optionally, the multiple application nodes are respectively provided with an event receiver, and the event receiver is used to receive the cache change event published by the event publisher of the corresponding application node; publishing the cache change event to the other nodes includes: pushing the cache change event to the event publisher of the other nodes through the configuration center server.

[0012] Optionally, based on the cache change event, the initial data storage state of the other node is updated to obtain the other node refreshed to the target data storage state, including: based on the target parameter indicated by the cache change event, using the event publisher of the other node to notify the event receiver of the other node; in response to the event receiver of the other node receiving the notification of the cache change event, calling a predetermined cleanup function through the event receiver to clean up the initial data storage state of the other node, so as to obtain the other node refreshed to the target data storage state.

[0013] Optionally, the multiple application nodes interact with a predetermined database respectively, and the cache change event is executing a first data change value of the target parameter in the predetermined database, and executing a second data change value of the target parameter on the local cache of the target node, the first data change value is more matched with the second data change value. After obtaining the other nodes refreshed to the target data storage state, the method further includes: when the target data storage state is the target parameter is cleared state, and in response to a query request to execute the predetermined query on the other nodes, executing the predetermined query on the other nodes, and obtaining a third query result that is no parameter value returned; when the third query result is no parameter value returned, executing the predetermined query on the predetermined database, and obtaining the first data change value as the first query result; in response to a query request to execute the predetermined query on the target node, executing the predetermined query on the target node, and obtaining the second data change value as the second query result.

[0014] According to a second aspect of an embodiment of the present application, a cache processing device is provided, comprising: an application node determination module for determining a plurality of application nodes that match an initial data storage state, and a predetermined configuration center server that interacts with the plurality of application nodes respectively, wherein the plurality of application nodes are distributed nodes with interaction isolation; a cache change publishing module for publishing the cache change event to other nodes among the plurality of application nodes in response to the interaction between the target node and the configuration center server when a cache change event occurs at a target node among the plurality of application nodes; a cache processing module for updating the initial data storage state of the other nodes based on the cache change event to obtain the other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query on the other nodes based on the target data storage state matches a second query result of a predetermined query on the target node where the cache change event occurs.

[0015] According to a third aspect of an embodiment of the present application, a non-volatile storage medium is provided, wherein the non-volatile storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing any one of the cache processing methods described above.

[0016] According to the fourth aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement any one of the cache processing methods described.

[0017] The details of one or more embodiments of the present application are set forth in the accompanying drawings and the description below. Other features, objects, and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] FIG1 is a flowchart of an optional cache processing method provided according to an embodiment of the present application;

[0020] FIG2 is a schematic diagram of an optional cache processing method provided according to an embodiment of the present application;

[0021] FIG3 is a schematic diagram of an optional cache processing device provided according to an embodiment of the present application. DETAILED DESCRIPTION

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

[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0024] For ease of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0025] SpringCache is an abstraction layer provided by the Spring Framework, an open source Java application framework, to simplify the use of caching. It provides abstract support for various caching solutions. The Spring Framework provides a unified approach to using local caches. Using annotations, you can easily declare caching behavior at the method level without having to delve into the specific details of the cache implementation.

[0026] Nacos is a high-performance and highly available configuration center that can be used to publish configurations. Each application node can obtain and listen to Nacos' configuration and publishing events. Especially in the microservice architecture, Nacos acts as the center for service registration and discovery, allowing service providers and consumers to easily discover and communicate with each other.

[0027] Caching is a technology that temporarily stores calculation results so they can be used directly in subsequent requests. In applications, cache can be used to store frequently accessed data to improve access speed and performance. When an application needs a piece of data, it first checks whether the data already exists in the cache. If so, the cached data is directly returned. If not, the application performs calculations, queries, and other operations, and stores the results in the cache for future use.

[0028] Dubbo is a high-performance, lightweight RPC (remote procedure call) framework that is widely used to build microservices and communication between services.

[0029] In distributed systems based on related technologies, Redis publishes events, and other nodes listen to these events to refresh cached data. This mechanism ensures data consistency across nodes. However, in a multi-data center parallel computing environment, this strategy is no longer applicable. Because each data center typically has an independent Redis deployment, Redis in one data center cannot publish events to Redis in other data centers. Furthermore, due to security, network latency, and bandwidth considerations, applications typically do not connect to Redis clusters in other data centers across data centers.

[0030] Another related technology, publishing MQ (Message Queue) messages and broadcasting and monitoring them, can address data consistency issues to a certain extent. However, this approach is not feasible in certain architectures. For example, if each data center has its own MQ server, cross-data center message broadcasting becomes very difficult. Furthermore, some customized MQ solutions may not implement broadcast monitoring functionality, or their implementation may not meet specific business requirements.

[0031] SpringCache is a framework that provides a cache abstraction layer for Java applications and can be integrated with various cache solutions (such as Redis). However, the cache frameworks natively supported by SpringCache generally lack a cache refresh mechanism. This means that when the application updates cached data, a cache refresh must be manually triggered, leading to data consistency issues and poor adaptability, especially in high-concurrency scenarios.

[0032] In response to the above-mentioned problems, an embodiment of the present application provides a method embodiment of cache processing. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0033] FIG1 is a flow chart of a cache processing method according to an embodiment of the present application. As shown in FIG1 , the method includes the following steps:

[0034] Step S102: determining a plurality of application nodes that match the initial data storage state, and a predetermined configuration center server that interacts with the plurality of application nodes, wherein the plurality of application nodes are distributed nodes that are isolated from each other.

[0035] It is understood that in a distributed system, the initial data storage states of multiple distributed application nodes are identical or matching. There is interaction isolation between the multiple application nodes, meaning they cannot directly communicate or share data. Each of the multiple application nodes interacts with a predetermined central configuration server. By identifying multiple application nodes with matching initial data storage states and the predetermined central configuration server with which they interact, support is provided for subsequent data consistency and synchronization within the distributed system.

[0036] Step S104: when a cache change event occurs in a target node among the multiple application nodes, in response to the interaction between the target node and the configuration center server, the cache change event is published to other nodes among the multiple application nodes.

[0037] It can be understood that when a cache change event occurs in one of the multiple application nodes, namely the target node, the target node will interact with the configuration center server to notify the configuration center server that the cache status has changed. After receiving the notification from the target node, the configuration center server will publish this cache change event to the other application nodes. In this way, other nodes can be informed that the cached data has changed. After receiving the notification from the target node, the configuration center server will quickly publish the cache change event to the other application nodes. Because these application nodes maintain interaction with the configuration center server, they can receive notifications of change events in a timely manner and update their cached data accordingly. Compared to related technologies, the use of the configuration center server to implement publishing and notification can eliminate the reliance on Redis as a caching mechanism, thereby improving scalability.

[0038] Alternatively, using a cache can reduce the frequency of access to the database or other time-consuming operations, improving the system's responsiveness and concurrency. In Spring Framework applications, you can use SpringCache to simplify the use and management of caches, improving application performance and scalability.

[0039] In an optional embodiment, multiple application nodes are respectively provided with an event publisher, and the event publisher is used to interact with the configuration center server. The method also includes: sending cache identifiers corresponding to the multiple application nodes through the event publishers corresponding to the multiple application nodes, and generating node cache information on the configuration center server.

[0040] As you can understand, each application node is equipped with an event publisher, which is responsible for interacting with the application node and the central configuration server. The event publisher provides a standardized interface for application nodes to exchange information about cache change events with the central configuration server. By sending the corresponding cache identifier to the central configuration server, the central configuration server can obtain node cache information indicating that multiple application nodes need to be refreshed in parallel.

[0041] Optionally, the event publisher can be in the form of an interface. A Notifier event publisher interface is defined. This event publisher is used to publish cache change events to the configuration center server (such as Nacos). This interface format means that it can be implemented by different implementation classes. The event publisher defines a publish(Key key) method that accepts a cache key as a parameter. The publish method indicates the publishing method, Key indicates the object type, and key indicates the object identifier.

[0042] The above event publisher also defines a register(Notified notified) method. Register is used to register an object or entity, which can receive a Notified (notified) type identifier as a notified object. After publishing a cache change event, the event publisher will call the event receiver interface registered here to notify it of the cache change event content.

[0043] It's important to note that the interface above defines a set of methods, but these methods don't have specific implementations. An interface can be thought of as a declaration of the methods that a class implementing it should provide. An implementation class is a class that implements an interface or abstract class, providing concrete implementations of all the methods defined in that interface or abstract class.

[0044] Optionally, the publish method used by the event publisher Notifier is designed to write the cached key list of changes to the specified dataId (configuration set) of the Nacos configuration center server in CAS (Compare-And-Swap, concurrency control technology). The format of this dataId is set to notifyCache.xxx, where xxx represents the name of a local cache. For example, notifyCache.userInfo can be regarded as the identifier of the user information cache. When writing the configuration, the method will serialize the cached key list into a JSON string. JSON (JavaScript Object Notation) string is a lightweight data exchange format. This JSON string will be used as the configuration content and stored in the form of an array list. Each array element is a JSON string representation of a key, that is, each cache key is serialized into a string.

[0045] Optionally, after receiving these cache identifiers from different application nodes, the configuration center server will integrate these identifier information to generate a node cache information table or similar data structure. This node cache information table contains the cache identifiers of all application nodes and possible other related information, such as the node status and last update time.

[0046] In an optional embodiment, in response to the interaction between the target node and the configuration center server, a cache change event is published to other nodes in a plurality of application nodes, including: publishing, through the event publisher of the target node, target parameters indicated by the cache change event to the configuration center server as the interaction between the target node and the configuration center server; in response to the interaction between the target node and the configuration center server, based on the target parameters, the node cache information is changed to obtain updated cache information in the configuration center server; and when the event publisher of other nodes detects updated cache information, a cache change event is published to other nodes.

[0047] As you can understand, when a cache change event occurs on a target node, the event publisher constructs a message containing a specific indication of the cache change event and the relevant target parameters. This message is then sent to the configuration center server. Upon receiving the message from the target node's event publisher, the configuration center server parses the target parameters. The configuration center server then updates or modifies its internal node cache information based on these target parameters, allowing the configuration center server to identify the parameters that have changed. Once the node cache information is updated, the configuration center server broadcasts the updated cache information to all other application nodes. Each application node has an event publisher, which not only publishes events but also detects updates from the configuration center server in real time. When the event publishers of other nodes detect updated cache information published by the configuration center server, they trigger further notifications to the event receivers corresponding to those other nodes. Through this process, the distributed system can efficiently maintain cache consistency across application nodes while ensuring that all nodes utilizing the configuration center server are promptly notified of cache changes and update their own status.

[0048] Optionally, the cache change event may be, for example, data update, deletion, or addition.

[0049] Optionally, the target parameter may be, for example, the key and value of the cache item being changed.

[0050] In an optional embodiment, after publishing the target parameters of the cache change event indication to the configuration center server through the event publisher of the target node, the method also includes: determining the publishing result of executing the publishing to the configuration center server through the event publisher of the target node; when the publishing result indicates that the publishing failed, executing a predetermined number of retry publishings to the configuration center server through the event publisher of the target node to obtain a retry result; when the retry result indicates that there is a retry failure, sending an alarm message indicating the publishing failure to the predetermined receiving end.

[0051] It can be understood that publishing is performed to the configuration center server through the event publisher of the target node, and determining the above-mentioned publishing result involves checking whether the publishing operation is successful. If the publishing result indicates that the publishing failed, an attempt will be made to retry the publishing operation. The number of retries is pre-set, which can ensure that the publishing operation can be successful in the event of temporary network problems or temporary unavailability of the configuration center server. During the retry process, the result of each retry is determined. If the publishing operation still fails after the number of retries reaches the predetermined value, an alarm message indicating the publishing failure is generated and sent to the predetermined receiving end. Through the above processing, it is ensured that the cache change event can be reliably published to the configuration center server, and a corresponding alarm mechanism is provided when the publishing fails, so that the problem can be discovered and handled in a timely manner. This helps to improve the availability and stability of the system.

[0052] Optionally, after sending the alarm information, you can also perform processing such as trying other recovery strategies, generating a local alarm log, etc.

[0053] Optionally, the alarm information includes information such that the receiving end can identify the severity of the problem and the type of abnormality so that corresponding measures can be taken to solve the problem.

[0054] Optionally, a predetermined delay time is set between each retry to avoid excessive pressure on the configuration center server.

[0055] In an optional embodiment, multiple application nodes are respectively provided with an event receiver, which is used to receive cache change events published by the event publisher of the corresponding application node; publishing cache change events to other nodes includes: pushing cache change events to the event publishers of other nodes through the configuration central server.

[0056] As you can understand, multiple application nodes receive cache change events by setting up event receivers. Each application node is equipped with an event receiver for receiving cache change events published by the node's event publisher. When a cache change occurs, the configuration center server pushes the cache change event to the event publishers of other nodes, rather than directly to the event receiver of the node. The event receivers on these other nodes are used to receive the cache change events published by the event publisher. This process separates the functions of the event publisher and event receiver, and the abstracted application can actually be implemented using any of its subclasses. This mechanism helps achieve system decoupling, scalability, and high availability.

[0057] An interface is an abstract type that defines methods but does not include implementation details. This allows different classes to implement the same methods, thus achieving polymorphism. For example, event publishers and event receivers in the form of interfaces are abstracted, meaning that any class that implements the declared interface functionality can be used to notify other nodes about cache change events.

[0058] NacosNotifier is a specific implementation of the Notifier interface, using Nacos as the central configuration server to push cache change events. It supports different notification mechanisms or integrates with other systems. For example, DubboNotifier may be another implementation of the Notifier interface, using Dubbo's broadcast call method to push cache change events. When a cache change occurs, the event publisher sends the cache change event to the Dubbo service provider. The Dubbo service provider then uses the broadcast mechanism to broadcast the event to all subscribed consumers. All relevant application nodes can receive cache change notifications in a timely manner and update their local status accordingly.

[0059] By using different Notifier implementations (such as NacosNotifier or DubboNotifier), you can maintain flexibility and scalability and choose the appropriate notification mechanism based on specific needs and technology stack without modifying the core business logic or event processing process.

[0060] Optionally, after NacosNitfier is constructed, it needs to detect changes in the content of Nacos's cached dataId in real time, such as notifyCache.userInfo. When there is a content change, each Key is parsed according to the agreed format and deserialized into a Java object. Once the Key is successfully deserialized, NacosNotifier will call the notify method of the previously registered Notified object, such as the notify(Key key) method, to notify the changed key information. Other parts that rely on this dataId will know that the content has been updated and make corresponding processing accordingly.

[0061] Step S106: Based on the cache change event, the initial data storage status of other nodes is updated to obtain other nodes refreshed to the target data storage status, wherein the first query result of the scheduled query based on the other nodes in the target data storage status matches the second query result of the scheduled query based on the target node where the cache change event occurs.

[0062] It is understood that after receiving a cache change event, other nodes will update their own data storage states based on this event. The first query result of a scheduled query on other nodes based on the updated target data storage state will match the second query result of a scheduled query on the target node where the cache change event occurred. This means that no matter which distributed node executes the query, the result should be the same, ensuring consistency between node cache data.

[0063] In an optional embodiment, based on a cache change event, the initial data storage state of other nodes is updated to obtain other nodes refreshed to a target data storage state, including: based on a target parameter indicated by the cache change event, using an event publisher of other nodes to notify an event receiver of other nodes; in response to the event receiver of other nodes receiving notification of a cache change event, calling a predetermined cleanup function through the event receiver to clean up data on the initial data storage state of other nodes, to obtain other nodes refreshed to a target data storage state.

[0064] It can be understood that the cache change event contains relevant information about the target parameters. The target node uses its event publisher to notify the event receivers of other nodes of the cache change event, ensuring that all relevant nodes are aware of the data change. The event receivers of other nodes receive the notification of the cache change event, marking the beginning of the data cleanup and update process. After receiving the notification, the event receivers of other nodes will call a scheduled cleanup function, which is responsible for cleaning up the node's initial data storage state and preparing for data updates. The scheduled cleanup function will perform a series of operations to clean up the initial data storage state of other nodes, which may include deleting old data, marking data as invalid, or performing any other necessary cleanup tasks. Through the above processing, the data storage state of other nodes will be refreshed to the target data storage state. The method based on event notification and scheduled cleanup function ensures that when data changes occur, all relevant nodes can update their data storage state in a timely and accurate manner, which helps maintain data consistency and accuracy.

[0065] In an optional embodiment, multiple application nodes interact with a predetermined database respectively, and the cache change event is executing a first data change value of the target parameter in the predetermined database, and executing a second data change value of the target parameter on the local cache of the target node. The first data change value is more matched with the second data change value. After obtaining other nodes refreshed to the target data storage state, the method also includes: when the target data storage state is the target parameter cleared state, and in response to a query request to execute a predetermined query on other nodes, executing a predetermined query on the other nodes, and obtaining a third query result that the parameter value is not returned; when the third query result is that the parameter value is not returned, executing a predetermined query on the predetermined database, and obtaining the first data change value as the first query result; in response to a query request to execute a predetermined query on the target node, executing a predetermined query on the target node, and obtaining the second data change value as the second query result.

[0066] It can be understood that when multiple application nodes interact with a predetermined database and a cache change event causes a data change of a target parameter, a first data change value of the target parameter is executed in the predetermined database, and a corresponding data change, i.e., a second data change value, is executed in the local cache of the target node. Ensure that the first data change value and the second data change value match to maintain data consistency between the database and the cache. It should be noted that the latest data status in the predetermined database is a cache inconsistency problem caused by the fact that the local caches of other distributed application nodes are not refreshed synchronously. After receiving the cache change event, other nodes will refresh to keep the target data storage status consistent. If the target data storage status is a state in which the target parameter is cleared, the node will correspondingly clear the data about the target parameter in its local cache.

[0067] When executing a scheduled query on another node, if the data for the target parameter in the local cache of that node has been cleared (i.e., the target data storage status is empty), the query will not return any parameter value, i.e., the third query result is "no parameter value returned". In this case, the system will fall back to the scheduled database to execute the scheduled query to obtain the latest data change value (i.e., the first data change value).

[0068] When a predetermined query is executed on the target node, since the local cache of the target node already contains the latest data change value (ie, the second data change value), this value will be directly returned to the client that initiated the query as the second query result.

[0069] This approach ensures that even when cached data is cleared, the latest matching query results are returned, maintaining data consistency. Furthermore, because all nodes are synchronized via a central configuration server or other mechanisms, query results across the entire distributed system remain consistent.

[0070] It should be noted that the embodiment of the present application can avoid the situation where the cache of other nodes is not updated, resulting in the initial data storage state and the stored data is not updated, resulting in the query results obtained for the updated target node being inconsistent with the query results obtained for other nodes that have not been updated. It is not required that the data storage state of other nodes is the same as that of the target node. In this way, even if the cache data of a node is cleared, the system can still use the configuration center server or other shared database to ensure that the latest query value is returned, thereby ensuring that the query results are matched. This method effectively improves the availability and data consistency of the system.

[0071] It's important to note that defining a custom cache interface, denoted as SpringNotifyCache, inherits the Cache interface provided by SpringCache, as well as the Notified interface (event publisher) and the Notifier interface (event receiver). This means that this custom cache is capable of working with the SpringCache system, receiving cache change events, publishing cache change events, and providing cache access capabilities. If it doesn't need to work with the SpringCache system, then the custom cache interface doesn't need to inherit the Cache interface provided by SpringCache. However, inheriting the Notified and Notifier interfaces means that this custom cache doesn't need to work with the SpringCache system and only needs to receive and publish cache change events and provide cache access capabilities.

[0072] Optionally, the method also includes: defining a custom cache decorator class SpringNotifyCacheDecorator. The construction of the custom cache decorator requires a Notifier (event publisher) and a specific implementation of SpringCache, such as Spring's built-in ConcurrentMapCache (a cache system that safely accesses and modifies key-value pairs in a multi-threaded environment without causing race conditions). These specific implementations of SpringCache can all implement Spring's Cache interface, which can be the same as the Spring Cache interface inherited by SpringNotifyCache.

[0073] Optionally, the above custom cache decorator implements the publish method of the Notifier interface by directly publishing events through the Notifier instance provided during construction. The decorator only acts as a call proxy.

[0074] Optionally, the above custom cache decorator implements the notify method of the Notified interface to clear the cache content in the local cache object according to the key in the parameter.

[0075] Optionally, the cache decorator implements the evit (for clearing a specific cache) and clear (for clearing all caches) methods of Spring's Cache interface to clear the contents of the cache according to the key in the method parameter and call the publish method to publish a cache change event.

[0076] In an optional embodiment, the method further includes defining a custom cache decorator class, denoted as NotifyCacheDecorator. If the SpringCache architecture is not required, the cache decorator can be constructed with only a Notifier and a Cache implementation, meaning that the underlying cache implementation is interchangeable.

[0077] In an optional embodiment, the method further includes: creating a cache factory for creating a cache object, instantiating it based on a defined cache decorator type, and passing in a pre-created NacosNotifier and a ConcurrentMapCache implementation to create an executable cache object.

[0078] Optionally, you can use the created cache object in SpringCache mode and use it in annotation mode. If you want to clear a certain parameter of the cache, the Spring framework will automatically call the evict method to automatically publish cache change events to other nodes.

[0079] Through the above step S102, multiple application nodes that match the initial data storage state and predetermined configuration center servers that interact with the multiple application nodes are determined, wherein the multiple application nodes are distributed nodes with interactive isolation; step S104, in the case where a cache change event occurs in a target node among the multiple application nodes, in response to the interaction between the target node and the configuration center server, a cache change event is published to other nodes among the multiple application nodes; step S106, based on the cache change event, the initial data storage state of the other nodes is updated to obtain other nodes refreshed to the target data storage state, wherein the first query result of the predetermined query based on the other nodes in the target data storage state matches the second query result of the predetermined query based on the target node where the cache change event occurs. The purpose of improving the flexibility of cache processing by utilizing the interaction between distributed application nodes and the configuration center server can be achieved, and the technical effect of removing the cache consistency refresh restrictions on interactively isolated distributed nodes is achieved, thereby solving the technical problem of large cache refresh limitations of interactively isolated distributed nodes in the related art.

[0080] Based on the above embodiments and optional embodiments, this application proposes an optional implementation method. Figure 2 is a schematic diagram of an optional cache processing method provided according to an embodiment of this application. As shown in Figure 2, the Nacos configuration center server interacts with multiple NotifiyCache cache containers, and each NotifiyCache cache container corresponds to its own NacosNotifier event publisher. Each application node is correspondingly provided with a Notifier event publisher interface, a Notified event receiver interface, and a Cache cache container.

[0081] The Nacos configuration center server receives the NacosNotifier event publisher named "node A" and uses the corresponding Notifier event publisher to perform active notification, sending the changed key object (target parameter). The publish method is used to write the cached Key class list of changes in CAS mode to the specified dataId (notifyCache.userInfo, regarded as user information cache) in the Nacos configuration center server.

[0082] If the NacosNotifier event publisher named "Node A" fails to send an event to the Nacos Configuration Center server, you can retry. If the retry fails, a log will be printed as an alarm so that you can manually publish the event to the Nacos Configuration Center server.

[0083] After publish writes the changed key sequence to the specified dataId in the Nacos configuration center server, the Nacos configuration center server pushes the key change event to the NacosNotifier event publisher named "node B" through a persistent connection. Through the Notified event receiver interface registered in the NacosNotifier event publisher named "node B", the Notified event receiver interface calls notify(Key key) to determine that the Key class object named "key" should be modified, and cleans up the key stored in the node named "node B".

[0084] Taking the Spring framework as an example, the NotifyCache custom cache interface and the SpringNotifyCacheDecorator custom cache decorator class are both used to interact with NotifiyCache as the cache container. The custom cache decorator implements the publish method of the Notifier interface by directly publishing events through the Notifier instance provided during construction. The decorator only acts as a call proxy. The notify method of the Notified interface is implemented by clearing the cache content in the local cache object according to the key in the parameter. The evit (used to clear a specific cache) and clear (used to clear all caches) methods of Spring's Cache interface are implemented by clearing the content in the cache according to the key in the method parameter, and calling the publish method to publish a cache change event.

[0085] The above optional implementation achieves at least the following: It leverages Nacos' configuration publishing and detection capabilities to implement a custom SpringCache cache refresh function upon change. By abstracting the Notifier interface, restrictions on implementation classes are removed. Furthermore, a user-specific cache is implemented by assembling an event publisher, event handler, and underlying cache storage. These components can be used independently and replaced on demand, increasing cache flexibility and avoiding the limitations of integrated frameworks or systems.

[0086] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0087] In this embodiment, a cache processing device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation methods. The details that have been described will not be repeated here. As used below, the terms "module" and "device" can be a combination of software and / or hardware that implements the predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.

[0088] According to an embodiment of the present application, an embodiment of a device for implementing a cache processing method is also provided. FIG3 is a schematic diagram of a cache processing device according to an embodiment of the present application. As shown in FIG3 , the cache processing device includes: an application node determination module 302, a cache change publishing module 304, and a cache processing module 306. The device is described below.

[0089] An application node determination module 302 is configured to determine a plurality of application nodes that match the initial data storage state, and predetermined configuration center servers that interact with the plurality of application nodes, wherein the plurality of application nodes are distributed nodes that are isolated from each other;

[0090] The cache change publishing module 304 is connected to the application node determination module 302 and is configured to publish the cache change event to other nodes in the multiple application nodes in response to the interaction between the target node and the configuration center server when a cache change event occurs in the target node among the multiple application nodes;

[0091] The cache processing module 306 is connected to the cache change publishing module 304, and is used to update the initial data storage status of other nodes based on the cache change event, and obtain other nodes refreshed to the target data storage status, wherein the first query result of the predetermined query based on the other nodes in the target data storage status matches the second query result of the predetermined query based on the target node where the cache change event occurs.

[0092] In a cache processing device provided by an embodiment of the present application, an application node determination module 302 is provided for determining multiple application nodes that match the initial data storage state, and a predetermined configuration center server that interacts with each of the multiple application nodes, wherein the multiple application nodes are distributed nodes with interactive isolation; a cache change publishing module 304 is connected to the application node determination module 302 and is used to publish a cache change event to other nodes in the multiple application nodes in response to the interaction between the target node and the configuration center server when a cache change event occurs at a target node among the multiple application nodes; a cache processing module 306 is connected to the cache change publishing module 304 and is used to update the initial data storage state of other nodes based on the cache change event to obtain other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query based on the other nodes in the target data storage state matches a second query result of a predetermined query based on the target node where the cache change event occurred. The purpose of utilizing the interaction between the distributed application nodes and the configuration center server to improve the flexibility of cache processing is achieved, and the technical effect of removing the cache consistency refresh restriction on the interactively isolated distributed nodes is achieved, thereby solving the technical problem of the large cache refresh limitation of the interactively isolated distributed nodes in the related art.

[0093] It should be noted that the above modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0094] It should be noted that the aforementioned application node determination module 302, cache change publishing module 304, and cache processing module 306 correspond to steps S102 to S106 in the embodiment. The examples and application scenarios implemented by these modules and corresponding steps are the same, but are not limited to the contents disclosed in the aforementioned embodiment. It should be noted that these modules, as part of the device, can be run on a computer terminal.

[0095] It should be noted that the optional or preferred implementation of this embodiment can be found in the relevant description in the embodiment, which will not be repeated here.

[0096] The cache processing device may also include a processor and a memory. The application node determination module 302, the cache change publishing module 304, the cache processing module 306, etc. are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions.

[0097] The processor includes a kernel, which retrieves the corresponding program unit from memory. There can be one or more kernels. Memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory includes at least one memory chip.

[0098] An embodiment of the present application provides a non-volatile storage medium on which a program is stored. When the program is executed by a processor, a cache processing method is implemented.

[0099] An embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: determining multiple application nodes that match the initial data storage state, and a predetermined configuration center server that interacts with the multiple application nodes, wherein the multiple application nodes are distributed nodes with interaction isolation; in the event that a cache change event occurs at a target node among the multiple application nodes, in response to the interaction between the target node and the configuration center server, publishing a cache change event to other nodes among the multiple application nodes; based on the cache change event, updating the initial data storage state of the other nodes to obtain other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query based on the other nodes in the target data storage state matches a second query result of a predetermined query based on the target node where the cache change event occurred. The device herein may be a server, a PC, etc.

[0100] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: determining multiple application nodes that match the initial data storage state, and a predetermined configuration center server that interacts with the multiple application nodes respectively, wherein the multiple application nodes are distributed nodes with interactive isolation; in the event that a cache change event occurs at a target node among the multiple application nodes, in response to the interaction between the target node and the configuration center server, publishing a cache change event to other nodes among the multiple application nodes; based on the cache change event, updating the initial data storage state of the other nodes to obtain other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query based on the other nodes in the target data storage state matches a second query result of a predetermined query based on the target node where the cache change event occurs.

[0101] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0102] The present application is described with reference to the flow chart and / or block diagram of the method, device (system), and computer program product according to the embodiment of the present application. It should be understood that each flow process and / or box in the flow chart and / or block diagram and the combination of the flow process and / or box in the flow chart and / or block diagram can be realized by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processing machine or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for realizing the function specified in one flow chart flow or multiple flows and / or one box or multiple boxes of the block diagram.

[0103] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0104] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0105] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0106] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0107] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0108] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0109] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0110] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims

1. A cache processing method, comprising: Determining a plurality of application nodes that match the initial data storage state, and predetermined configuration center servers that interact with the plurality of application nodes, respectively, wherein the plurality of application nodes are distributed nodes that are interactively isolated; When a cache change event occurs at a target node among the multiple application nodes, publishing the cache change event to other nodes among the multiple application nodes in response to interaction between the target node and the configuration center server; Based on the cache change event, the initial data storage state of the other nodes is updated to obtain the other nodes refreshed to the target data storage state, wherein a first query result of a predetermined query based on the other nodes in the target data storage state matches a second query result of a predetermined query based on the target node where the cache change event occurs.

2. The method according to claim 1, wherein the plurality of application nodes are respectively provided with an event publisher, the event publisher being configured to interact with the configuration center server, the method further comprising: The cache identifiers corresponding to the multiple application nodes are sent through the event publishers corresponding to the multiple application nodes, and the node cache information is generated in the configuration center server.

3. The method according to claim 2, wherein, in response to the interaction between the target node and the configuration center server, publishing the cache change event to other nodes in the plurality of application nodes comprises: Publishing the target parameters of the cache change event indication to the configuration center server through the event publisher of the target node as interaction between the target node and the configuration center server; In response to the interaction between the target node and the configuration center server, based on the target parameter, the node cache information is changed to obtain updated cache information in the configuration center server; When the event publisher of the other node detects that the cache information is updated, the cache change event is published to the other node.

4. The method according to claim 3, wherein after the event publisher of the target node publishes the target parameters of the cache change event indication to the configuration center server, the method further comprises: Determine the publishing result of executing the publishing to the configuration center server through the event publisher of the target node; When the publishing result indicates that the publishing has failed, performing a retry publishing to the configuration center server for a predetermined number of times through the event publisher of the target node to obtain a retry result; In the case that the retry result indicates that there is a retry failure, an alarm message indicating a publishing failure is sent to a predetermined receiving end.

5. The method according to claim 3, wherein the plurality of application nodes are respectively provided with an event receiver, the event receiver being configured to receive the cache change event published by an event publisher of the corresponding application node; and publishing the cache change event to the other nodes comprises: The cache change event is pushed to the event publishers of the other nodes through the configuration center server.

6. The method according to claim 5, wherein the updating of the initial data storage state of the other node based on the cache change event to obtain the other node refreshed to the target data storage state comprises: Notifying the event receiver of the other node using the event publisher of the other node based on the target parameter indicated by the cache change event; In response to the event receiver of the other node receiving the notification of the cache change event, the event receiver calls a predetermined cleanup function to clean up the initial data storage state of the other node, so as to obtain the other node refreshed to the target data storage state.

7. The method according to any one of claims 1 to 6, wherein the plurality of application nodes respectively interact with a predetermined database, the cache change event is executing a first data change value of a target parameter in the predetermined database and executing a second data change value of the target parameter in a local cache of the target node, the first data change value and the second data change value being more closely matched, and after obtaining the other nodes refreshed to the target data storage state, the method further comprises: When the target data storage state is a state in which the target parameter is cleared, and in response to a query request to execute the predetermined query on the other node, executing the predetermined query on the other node, obtaining a third query result that no parameter value is returned; If the third query result does not return a parameter value, executing the predetermined query on the predetermined database to obtain a first data change value as the first query result; In response to a query request to execute the predetermined query on the target node, the predetermined query is executed on the target node to obtain the second data change value as the second query result.

8. A cache processing device, comprising: An application node determination module, configured to determine a plurality of application nodes that match an initial data storage state, and predetermined configuration center servers that interact with the plurality of application nodes, wherein the plurality of application nodes are distributed nodes that are isolated from each other; a cache change publishing module, configured to publish, when a cache change event occurs in a target node among the multiple application nodes, the cache change event to other nodes among the multiple application nodes in response to interaction between the target node and the configuration center server; A cache processing module is used to update the initial data storage state of the other nodes based on the cache change event, and obtain the other nodes refreshed to the target data storage state, wherein the first query result of the predetermined query based on the other nodes in the target data storage state matches the second query result of the predetermined query based on the target node where the cache change event occurs.

9. A non-volatile storage medium storing a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the cache processing method according to any one of claims 1 to 7.

10. An electronic device comprising: One or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the cache processing method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Local cache refresh implementation method and device based on Redis

    CN108182152A

  • Method and apparatus for monitoring, notifying, and refreshing, computing device, and storage medium

    CN109167810A

  • Distributed caching method and system, computer equipment and storage medium

    CN111159233A

  • Data processing method, device and system

    CN114945026A

  • Cache processing method and device, storage medium and electronic equipment

    CN118250333A

Cited By

  • Distributed cache management method, system and device, storage medium and program product

    CN121210527A