Distributed cache optimization method based on adaptive probability filtering and server atomic script
By combining adaptive probabilistic filtering with server-side atomic scripts, the problems of cache penetration and data consistency in distributed caching systems are solved, achieving efficient penetration prevention and data synchronization, reducing system complexity and resource waste, and adapting to changing business needs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU ARTECH
- Filing Date
- 2026-06-23
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, distributed caching systems face problems such as cache penetration and data consistency. Traditional solutions cannot adapt to changes in request frequency, leading to resource waste and database load conflicts. Static parameters in probabilistic filtering structures result in uncontrollable false positive rates. Cache and database updates lack cross-level atomicity guarantees, resulting in high system complexity and poor scalability.
By combining adaptive probability filtering with server-side atomic scripts, requests are intercepted through application-layer dynamic proxies, and expiration times and hash functions are dynamically adjusted to achieve cross-level atomic synchronization. A two-way rollback mechanism and feedback correction processing are introduced to support business logic decoupling and resource-aware degradation.
It achieves high-precision penetration prevention and control, end-to-end data consistency and synchronization, reduces system complexity and maintenance costs, improves cache resource utilization and system stability, and adapts to changing business needs.
Smart Images

Figure CN122432220A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed computing and data storage technology, specifically to a distributed caching optimization method based on adaptive probability filtering and server-side atomic scripts. Background Technology
[0002] The rapid development of distributed computing and data storage technologies has made high-concurrency, highly available distributed systems a core infrastructure in fields such as the internet, finance, and e-commerce. Distributed caching, as a key component in distributed systems to improve data access performance and reduce the load on the underlying database, can significantly shorten interface response time and support the processing of massive concurrent requests by temporarily storing frequently accessed data in high-speed storage media. However, in actual large-scale deployment and operation, distributed caching systems consistently face two major technical challenges: cache penetration and data consistency.
[0003] To address the cache penetration problem, existing technologies commonly employ methods such as null caching and probabilistic filtering (e.g., Bloom filters). However, all of these solutions have significant technical limitations: (1) Null value caching methods typically use a fixed expiration time (TTL), which cannot be dynamically adjusted according to the request frequency. When facing malicious high-frequency attacks, the fixed expiration time causes null values to expire frequently and continue to penetrate into the database, creating a contradiction between cache space redundancy and database overload.
[0004] (2) The traditional probability filtering structure has a fixed bit array size and number of hash functions after initialization. It cannot adjust the filtering rules in real time according to the dynamic increase or decrease of the underlying data scale, resulting in an uncontrollable false judgment rate and even the situation where valid data is mistakenly intercepted.
[0005] (3) Existing fallback strategies such as rate limiting and circuit breaking are passive protections that cannot fundamentally solve the penetration problem. Furthermore, the threshold configuration is difficult and can easily injure normal business requests.
[0006] To address the data consistency issue between caches and databases, existing technologies (such as Cache-Aside and Write-Through patterns) primarily rely on different asynchronous or synchronous update strategies. However, in multi-threaded concurrency and distributed deployment scenarios, these solutions suffer from insurmountable drawbacks: (1) Due to the lack of true atomicity guarantee between database updates and cache operations, the timing of operations is easily disordered during network jitter or concurrent competition, resulting in the long-term retention of dirty data.
[0007] (2) Although the introduction of locking mechanisms can alleviate concurrency conflicts, traditional locking mechanisms cannot achieve cross-level "database-cachate" atomic closed loops, and increase system complexity, with the risk of deadlock and significant performance degradation.
[0008] Furthermore, in existing technologies, cache penetration prevention and consistency assurance are typically implemented as independent modules, lacking a collaborative optimization mechanism. At the same time, cache operation logic is generally deeply coupled with business code, resulting in high system development and maintenance costs, poor scalability, and difficulty in quickly adapting to changing business needs. Summary of the Invention
[0009] The purpose of this invention is to overcome the shortcomings of existing technologies and provide a distributed cache optimization method based on adaptive probabilistic filtering and server-side atomic scripts. This method aims to solve the technical problems in existing technologies, such as the waste of cache resources and database load contradiction caused by the fixed expiration time of null value caching methods, the uncontrollable false judgment rate and the problem of false interception of valid data under data scale fluctuations due to the static parameters of traditional probabilistic filtering structures, the problem of dirty data retention in distributed environments caused by the lack of cross-level atomicity guarantees for cache and database update operations, and the system performance loss and deep logical coupling caused by the introduction of complex synchronization lock mechanisms. This invention achieves high-precision penetration prevention and control, end-to-end atomic data synchronization, and transparent decoupling of business logic.
[0010] To achieve the above objectives, this invention provides a distributed cache optimization method based on adaptive probability filtering and server-side atomic scripts, comprising the following steps: Interception Decoupling and Feature Extraction: By intercepting query and write requests from the business system to the target database through the application layer dynamic proxy module, the cache governance logic is transparently decoupled from the business logic, and the feature information of the requests is extracted. Pre-filtering verification logic: The feature information is input into a preset adaptive probability filtering structure for existence verification; if it is determined that it does not exist, an empty result is returned directly to the business system. Query branch and penetration prevention logic: If it is determined that it exists, the distributed cache and the target database are searched sequentially; in response to the distributed cache not being hit and the target database query result being empty, the access frequency of the feature information within a preset window period is counted, and the differentiated null value expiration time is dynamically calculated based on the negative correlation mapping model between access frequency and expiration time, and the corresponding null value placeholder is stored in the distributed cache, wherein the expiration time allocated for high-frequency penetration requests is shorter than the expiration time allocated for low-frequency penetration requests; Write branch atomic synchronization logic: For write requests, the application layer uses a concurrency lock mechanism to control the serialization of the current feature information and executes an update operation for the target database; in response to a successful database update, the server-side atomic script is called to perform atomic synchronization on the distributed cache side; Two-way rollback and feedback mechanism: If any operation in the target database update or the atomic synchronization fails, a two-way rollback mechanism is triggered: the submitted database update operation is revoked and the concurrency lock is released; at the same time, a retry request is initiated based on a preset exponential backoff algorithm until the preset retry limit is reached or synchronization is successful.
[0011] Furthermore, the adaptive probability filtering structure is dynamically reconstructed in the following manner: Real-time monitoring of the magnitude of valid feature items and the theoretical misclassification rate in the distributed cache; When the order of magnitude exceeds a preset capacity threshold, or the theoretical false positive rate exceeds a preset deviation threshold, the target bit array length and the number of hash functions are recalculated in a background thread, and a new filtering structure is constructed. A double-buffered switching logic is adopted: the interception function of the original filter structure is maintained during the reconstruction of the new filter structure, and after the reconstruction is completed and the verification is passed, the lossless switching between the old and new structures is achieved through an atomic renaming instruction.
[0012] Furthermore, the differentiated null value expiration times are cleaned up in the following way: By combining application-layer scheduled tasks with the time-to-live verification instructions on the distributed cache side, expired null placeholders are periodically scanned and deleted.
[0013] Furthermore, the server-side atomic script introduces logical version verification during atomic synchronization: When the application layer initiates a synchronization request, it carries a logical version number generated based on the application layer's atomic clock. The server-side atomic script compares the logical version number with the version identifier of the existing data in the distributed cache: if the logical version number is not earlier than the version identifier, then an overwrite is performed and the version identifier is updated; otherwise, a version conflict status code is returned to the application layer and the writing is terminated.
[0014] Furthermore, the application-layer dynamic proxy module supports intercepting business methods of interface type and class type, so as to weave cache management logic into the business call chain through aspect-oriented programming without modifying the core code of the business system.
[0015] Furthermore, the method also includes: dynamically configuring differentiated cache management strategies on business methods through custom annotations, wherein the cache management strategies include at least cache expiration time, penetration prevention threshold and retry count set for different business scenarios.
[0016] Furthermore, the method is executed through a unified, encapsulated cache management component, which provides a standardized cache operation interface and incorporates resource-aware degradation logic. Real-time sampling of the response latency metrics of the distributed cache and the load metrics of the target database; When the response latency indicator exceeds a preset performance threshold, or the database load indicator exceeds a preset security threshold, the verification depth of the adaptive probability filtering structure is automatically reduced, or circuit breaking and degradation are performed on non-core business processes by directly accessing the origin server.
[0017] Furthermore, the cache management component also implements self-optimization of the cache strategy: Integrated cache hit rate statistics function, outputting cache running status data through scheduled tasks; Based on the cache hit rate statistics and penetration rate data, the parameter thresholds of the adaptive probability filtering structure and the range of the differential null value expiration time are automatically adjusted.
[0018] Furthermore, the method also includes feedback correction processing: When the number of times the adaptive probability filtering structure determines that a target database query result is empty reaches a preset threshold, a false judgment detection signal is triggered. In response to the false positive sensing signal, the feature weight of the feature information in the adaptive probability filtering structure is dynamically increased, or it is moved to a temporary filtering whitelist.
[0019] Furthermore, the method also includes periodically performing consistency checks: The distributed cache is compared with the data in the target database by version number or timestamp. If an inconsistency is detected, the distributed cache is forcibly synchronized with the data in the target database.
[0020] This invention addresses the technical pain points of distributed caching technology, such as rigid penetration prevention and control, non-atomic data synchronization, high logical coupling, and unbalanced resource management. Through the organic combination of adaptive probability filtering, dynamic negative correlation null value caching, and cross-level atomic synchronization mechanisms, it achieves the following significant technical effects: This invention addresses the shortcomings of traditional solutions in adapting to changes in data scale by employing a dynamically reconfigurable adaptive probabilistic filtering structure. Combined with a double-buffered smooth switching logic, it ensures uninterrupted interception during filter rule updates, effectively maintaining cache hit rates. Furthermore, the introduced feedback correction mechanism enables the system to detect and correct misjudgments online. By dynamically increasing feature weights or moving data to a temporary whitelist, it avoids business anomalies caused by erroneous interception of valid data, significantly reducing the pressure of invalid database queries.
[0021] This invention identifies request popularity based on the Exponentially Weighted Moving Average (EWMA) algorithm and innovatively establishes a negative correlation mapping model between access frequency and expiration time. Shorter expiration times are allocated to high-frequency illegal requests, quickly releasing cache space while ensuring effective interception and preventing cache space redundancy and memory overflow caused by massive malicious requests. Longer expiration times are allocated to low-frequency requests, ensuring long-term continuous interception. This dynamic allocation mechanism improves cache resource utilization while building a more resilient security barrier.
[0022] This invention leverages the single-threaded atomic execution characteristic of server-side scripts, combined with logical version comparison, to effectively avoid the risk of write overwriting caused by network out-of-order delivery or concurrent contention. The bidirectional rollback mechanism ensures that if any link in the database and cache update chain fails, state rollback can be achieved, guaranteeing strong data consistency and solving the persistent problem of long-term retention of dirty data in traditional models.
[0023] Based on an application-layer dynamic proxy and aspect-oriented programming (AOP) architecture, the system achieves zero intrusion of caching optimization logic into business code. Developers can flexibly configure differentiated caching strategies simply through custom annotations, and implement standardized interface calls through uniformly encapsulated components. This design significantly reduces development complexity and maintenance costs, enabling the system to quickly adapt to changing business needs in different fields such as finance and e-commerce.
[0024] The resource-aware degradation logic and consistency inspection function built into this invention enable the system to detect abnormal fluctuations in cache latency and database load in real time. By automatically reducing the verification depth or triggering circuit breaker degradation, it can effectively prevent the system from experiencing a cascading failure under extreme pressure. Regular inspection and verification provide a last line of defense for data consistency, realizing the system's closed-loop self-optimization and self-healing, and significantly improving the overall service availability in high-concurrency scenarios. Attached Figure Description
[0025] Figure 1 This is a schematic diagram of the distributed caching optimization method of the present invention. Detailed Implementation
[0026] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0027] This embodiment provides a distributed cache optimization method based on adaptive probabilistic filtering and server-side atomic scripts. This method aims to achieve intelligent prevention of cache penetration, atomic synchronization of data updates, and decoupled management of cache governance logic through the collaboration of application-layer dynamic mechanisms and distributed cache server primitives, without relying on additional third-party middleware. Specifically, it improves the stability and data consistency of the distributed system when handling high-concurrency requests through deep interaction between Java custom components and Redis native interfaces.
[0028] like Figure 1 As shown, the distributed caching optimization method described in this embodiment mainly includes the following steps: S101: Interception decoupling and feature extraction.
[0029] By intercepting query and write requests from the business system to the target database through the application-layer dynamic proxy module, the cache governance logic is transparently decoupled from the business logic, and the characteristic information of the requests is extracted.
[0030] In practice, this embodiment utilizes a custom cache interception component developed based on Java dynamic proxies to perform interception actions. This custom cache interception component integrates a hybrid proxy mode combining JDK dynamic proxies and CGLIB dynamic proxies, enabling comprehensive interception of business methods of interface types and class types within the business system. This component can be directly integrated into existing Java application environments without modifying the core code of the business system, exhibiting extremely low migration costs and non-intrusive characteristics.
[0031] S102: Pre-filtering verification logic.
[0032] The extracted feature information is input into a preset adaptive probability filtering structure for existence verification; if it is determined that it does not exist, an empty result is returned directly to the business system.
[0033] In this embodiment, the adaptive probability filtering structure is specifically implemented using an adaptive Bloom filter integrated into the Java cache interception component. For illegal requests determined by the Bloom filter to be non-existent, the component will directly terminate subsequent operations and return an empty result, thus avoiding access to the distributed cache server or the underlying database and blocking the risk of penetration caused by invalid requests at the source.
[0034] S103: Query branch and penetration prevention logic.
[0035] If the adaptive probability filtering structure determines that a hit has occurred (i.e., the data may exist), then the distributed cache and the target database are searched sequentially.
[0036] In this process, the distributed cache is implemented using Redis. After passing the filtering verification, the Java custom cache interception component first retrieves the Redis cache; if the cache misses, it further triggers the query logic for the target database. In response to the case where the distributed cache misses and the query result of the target database is empty, the system counts the access frequency of this feature information within a preset window period, and dynamically calculates the differentiated null value expiration time based on the negative correlation mapping model between access frequency and expiration time, and then stores the corresponding null value placeholder in the distributed cache. This embodiment overcomes the shortcomings of fixed parameters in traditional solutions through the dual mechanism of dynamic null value caching and adaptive Bloom filter. Specifically, the system will count the historical query frequency of feature information in real time: for the identified high-frequency penetration requests, the system will shorten the corresponding null value expiration time to avoid a large number of invalid records occupying Redis memory space for a long time; for low-frequency requests, a longer expiration time is allocated to ensure the continuity of interception. In addition, the system also uses Java scheduled tasks in conjunction with Redis time-to-live verification instructions (such as TTL commands) to periodically and actively clean up expired null value cache, thereby effectively avoiding memory redundancy problems.
[0037] S104: Write branch atomic synchronization logic.
[0038] For write requests, the application layer uses a concurrency lock mechanism to serialize the current request characteristic information and executes an update operation on the target database. After the database update is successful, the server-side atomic script is called to perform atomic synchronization on the distributed cache side.
[0039] The write requests encompass database modification operations such as adding, deleting, and updating data. This embodiment intercepts all write operations using aspect-oriented programming (AOP) and implements concurrency control using Java ReentrantLock, ensuring strict sequentiality for update operations on the same characteristic data in a distributed or multi-threaded environment. After ensuring successful database transaction commit, the system calls a server-side atomic script written in Lua. This script encapsulates the specific cache update or deletion logic using Redis transaction mechanisms (such as the MULTI and EXEC commands). By leveraging the single-threaded atomic execution capability of Lua scripts on the Redis server, the pseudo-atomicity problem caused by the lack of rollback support in traditional Redis transactions is resolved, ensuring consistency between database and cache operations.
[0040] S105: Two-way rollback and feedback mechanism.
[0041] If either the target database update or the atomic synchronization fails, a bidirectional rollback mechanism is triggered: the submitted database update operation is revoked and the concurrency lock is released; at the same time, a retry request is initiated based on a preset exponential backoff algorithm until the retry limit is reached or synchronization is successful.
[0042] Specifically, if a database-level update operation fails, the system will directly release the concurrent lock without triggering a cache operation. If the synchronization logic on the distributed cache side malfunctions, the system will use a transaction rollback mechanism to undo the impact on the cache side and synchronously roll back committed database operations, while recording detailed exception logs. Subsequently, the system will execute a custom compensation strategy through the built-in Java retry mechanism to ensure that the data eventually becomes consistent.
[0043] As an optional implementation, the adaptive probabilistic filtering structure described in this embodiment can be dynamically reconstructed based on the effective data scale in the distributed cache. Specifically, by monitoring the magnitude of effective feature items and the theoretical false positive rate in real time, when the indicators exceed a preset deviation threshold, the system recalculates the size of the bit array and the number of hash functions in a background thread and constructs a new filtering structure. By employing double-buffering switching logic, the system can maintain the original interception function during reconstruction. After the new structure is constructed and verified, a lossless replacement is performed using atomic renaming instructions, thereby solving the technical problem of uncontrollable false positive rate in traditional Bloom filters.
[0044] As an optional implementation, the server-side atomic script in this embodiment introduces a logical version verification mechanism during synchronization. The application layer carries a logical version number generated based on an atomic clock when initiating a request. The server-side script compares the version identifier of existing data in Redis and only performs an overwrite write if the requested version is not earlier than the current version. This mechanism effectively avoids timing discrepancies and write overwrite risks in a distributed network environment.
[0045] As an optional implementation, this embodiment also supports dynamically configuring differentiated cache management strategies on business methods through Java custom annotations. Developers can define specific expiration times, penetration prevention thresholds, and retry strategies in the annotations according to the timeliness requirements of different business data, thereby achieving refined business governance and preventing valid data from being mistakenly discarded.
[0046] As an optional implementation, the method described in this embodiment relies on a unified, decoupled cache management component. This component is a custom Redis cache management tool based on Java, which internally encapsulates a high-performance Lettuce client to replace the traditional Jedis driver, thereby significantly improving the system's concurrent processing capabilities. This component provides standardized interfaces (such as query, update, and delete), achieving complete separation between cache governance logic and business code. The component also integrates unified exception handling and resource-aware degradation logic: the system samples Redis response latency and database load metrics in real time; once the pressure exceeds the warning threshold, it will automatically execute actions such as reducing the validation depth or circuit breaking degradation to prioritize the normal response of application interfaces.
[0047] Furthermore, the cache management component also possesses self-optimization capabilities. The system periodically collects Redis cache hit rate and runtime status data through Java scheduled tasks, and automatically fine-tunes the parameter thresholds of the adaptive probability filter and the range of the dynamic null cache based on the statistical results, providing data support for continuous optimization of system performance.
[0048] As an optional implementation, this embodiment also includes a feedback correction process. When the system detects that the frequency of Bloom filter hits but the underlying database query results are actually empty reaches a preset threshold, a misjudgment detection signal will be triggered. In response to this signal, the system will dynamically increase the weight of the corresponding feature in the filtering structure, or temporarily move it to a specific filtering whitelist, thereby continuously reducing the interference of misjudgments on business through a feedback loop.
[0049] In addition, this embodiment also provides a periodic data consistency inspection function. The system compares the version number or timestamp in the distributed cache with the target database. If an inconsistency is found, the system forces cache synchronization based on the data in the database and records the inconsistency log for system auditing.
[0050] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. It should be noted that any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A distributed caching optimization method based on adaptive probability filtering and server-side atomic scripts, characterized in that, Includes the following steps: Interception Decoupling and Feature Extraction: By intercepting query and write requests from the business system to the target database through the application layer dynamic proxy module, the cache governance logic is transparently decoupled from the business logic, and the feature information of the requests is extracted. Pre-filtering verification logic: The feature information is input into a preset adaptive probability filtering structure for existence verification; if it is determined that it does not exist, an empty result is returned directly to the business system. Query branch and penetration prevention logic: If it is determined that it exists, the distributed cache and the target database are searched sequentially; in response to the distributed cache not being hit and the target database query result being empty, the access frequency of the feature information within a preset window period is counted, and the differentiated null value expiration time is dynamically calculated based on the negative correlation mapping model between access frequency and expiration time, and the corresponding null value placeholder is stored in the distributed cache, wherein the expiration time allocated for high-frequency penetration requests is shorter than the expiration time allocated for low-frequency penetration requests; Write branch atomic synchronization logic: For write requests, the application layer uses a concurrency lock mechanism to control the serialization of the current feature information and executes an update operation for the target database; in response to a successful database update, the server-side atomic script is called to perform atomic synchronization on the distributed cache side; Two-way rollback and feedback mechanism: If any operation in the target database update or the atomic synchronization fails, a two-way rollback mechanism is triggered: the submitted database update operation is revoked and the concurrency lock is released; at the same time, a retry request is initiated based on a preset exponential backoff algorithm until the preset retry limit is reached or synchronization is successful.
2. The method according to claim 1, characterized in that, The adaptive probability filtering structure is dynamically reconstructed in the following way: Real-time monitoring of the magnitude of valid feature items and the theoretical misclassification rate in the distributed cache; When the order of magnitude exceeds a preset capacity threshold, or the theoretical false positive rate exceeds a preset deviation threshold, the target bit array length and the number of hash functions are recalculated in a background thread, and a new filtering structure is constructed. A double-buffered switching logic is adopted: the interception function of the original filter structure is maintained during the reconstruction of the new filter structure, and after the reconstruction is completed and the verification is passed, the lossless switching between the old and new structures is achieved through an atomic renaming instruction.
3. The method according to claim 1, characterized in that, The differentiated null value expiration time is cleaned up in the following way: By combining application-layer scheduled tasks with the time-to-live verification instructions on the distributed cache side, expired null placeholders are periodically scanned and deleted.
4. The method according to claim 1, characterized in that, The server-side atomic script incorporates logical version verification during atomic synchronization: When the application layer initiates a synchronization request, it carries a logical version number generated based on the application layer's atomic clock. The server-side atomic script compares the logical version number with the version identifier of the existing data in the distributed cache: if the logical version number is not earlier than the version identifier, then an overwrite is performed and the version identifier is updated; otherwise, a version conflict status code is returned to the application layer and the writing is terminated.
5. The method according to claim 1, characterized in that, The application-layer dynamic proxy module supports intercepting business methods of interface and class types, so as to weave cache management logic into the business call chain through aspect-oriented programming without modifying the core code of the business system.
6. The method according to claim 1, characterized in that, The method further includes: dynamically configuring differentiated cache management strategies on business methods through custom annotations, wherein the cache management strategies include at least cache expiration time, penetration prevention threshold and retry count set for different business scenarios.
7. The method according to claim 1, characterized in that, The method is executed through a unified, encapsulated cache management component, which provides a standardized cache operation interface and has built-in resource-aware degradation logic. Real-time sampling of the response latency metrics of the distributed cache and the load metrics of the target database; When the response latency indicator exceeds a preset performance threshold, or the database load indicator exceeds a preset security threshold, the verification depth of the adaptive probability filtering structure is automatically reduced, or circuit breaking and degradation are performed on non-core business processes by directly accessing the origin server.
8. The method according to claim 7, characterized in that, The cache management component also enables self-optimization of the cache strategy: Integrated cache hit rate statistics function, outputting cache running status data through scheduled tasks; Based on the cache hit rate statistics and penetration rate data, the parameter thresholds of the adaptive probability filtering structure and the range of the differential null value expiration time are automatically adjusted.
9. The method according to claim 1, characterized in that, The method also includes feedback correction processing: When the number of times the adaptive probability filtering structure determines that a target database query result is empty reaches a preset threshold, a false judgment detection signal is triggered. In response to the false positive sensing signal, the feature weight of the feature information in the adaptive probability filtering structure is dynamically increased, or it is moved to a temporary filtering whitelist.
10. The method according to any one of claims 1 to 9, characterized in that, The method also includes periodically performing consistency checks: The distributed cache is compared with the data in the target database by version number or timestamp. If an inconsistency is detected, the distributed cache is forcibly synchronized with the data in the target database.