Dynamic cache processing method and device
By combining large models with a dynamic cache processing method of reinforcement learning, the uniformity problem of system data cache is solved, the cache hit rate and system response speed are improved, and the system's concurrency and stability are enhanced.
Patent Information
- Application Number
- CN202510744077.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-16
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing technologies have difficulty solving the problem of uniformity in system data caching, resulting in long system response time, insufficient concurrency capabilities and unstable business systems.
A dynamic cache processing method based on a large model is adopted, combined with Redis and AOP, the cache status is verified through aspect programming, and reinforcement learning is used to adjust the cache strategy and content, predict hot data and load it dynamically.
Significantly improve cache hit rate, reduce database access frequency, optimize system response speed, enhance system performance and stability, and ensure data consistency.
Smart Images

Figure CN120653678A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data dynamics, and specifically provides a dynamic cache processing method and device. Background Art
[0002] Redis: An open-source, high-performance, key-value-based in-memory database. It can be used as a database, cache, and messaging middleware.
[0003] AOP (Aspect Oriented Programming): Aspect-oriented programming is a technology that achieves unified maintenance of program functions through pre-compilation and runtime dynamic proxy.
[0004] Reinforcement Learning (RL): A machine learning method that uses the interaction between an agent and its environment to learn optimal strategies to maximize cumulative rewards. Unlike supervised and unsupervised learning, RL does not require pre-labeled input-output pairs. Instead, it uses trial-and-error methods to obtain feedback signals from the environment to guide behavior.
[0005] How to solve the problem of uniformity of system data cache, improve system response time, enhance system concurrency capability, and ensure the stability of business system is an urgent problem to be solved by technical personnel in this field. Summary of the Invention
[0006] The present invention aims to address the above-mentioned deficiencies in the prior art and provides a highly practical dynamic cache processing method.
[0007] A further technical task of the present invention is to provide a dynamic cache processing device that is rationally designed, safe and applicable.
[0008] A dynamic cache processing method based on a large model. When a user initiates a business request, the backend service enters the aspect after receiving the request, first verifies the data cache status, and then retrieves the cache in Redis and returns it to the user after the verification is passed.
[0009] If there is no cached data in Redis, the main business processing begins. After the backend service completes the processing, the data is saved to the Redis service. The data in Redis is input into the prediction model to generate predicted hot spot data, which is also saved in Redis.
[0010] Finally, reinforcement learning is used to adjust the cache strategy and cache content.
[0011] Further, the specific steps are as follows:
[0012] S1. Verify the request through aspect programming;
[0013] S2, save the data to Redis;
[0014] S3, perform model prediction on the data in Redis;
[0015] S4. Adjust cache strategy and cache content through reinforcement learning.
[0016] Furthermore, in step S1, it further includes:
[0017] S1-1. Create a custom annotation class ConnectRedisCache and indicate that this annotation takes effect when the method and program are running;
[0018] S1-2. Add the @ConnectRedisCache annotation to the method that needs to cache data;
[0019] S1-3. Define the aspect class RedisCacheAspect and add the @Aspect annotation to the aspect class to indicate that this class is an aspect class.
[0020] S1-4. After receiving the front-end request, the back-end service enters the aspect's around notification. The ProceedingJoinPoint in the around notification is passed as a parameter for the enhancement method.
[0021] S1-5. Call the getMethod method of Signature to obtain the Method object of the method being proxied in step S1-2, and obtain the annotation of the proxied method through the getAnnotation method of Method;
[0022] S1-6. After obtaining the annotation, obtain the specific value in the ConnectRedisCache annotation;
[0023] S1-7. Use the generated cache key to query in Redis to check whether the corresponding cached data already exists in the cache. If the cache hits, the cached data is directly returned.
[0024] Furthermore, in step S1-1, a keyPrefix() method is added to the annotation class, and an element named keyPrefix is defined, which provides a string value when the annotation is subsequently used;
[0025] In step S1-3, the weaving point is configured, and the annotation in the above step S1-1 is used as the weaving point, indicating that the method using the annotation in step S1-1 will enter this section and perform corresponding processing in the section;
[0026] In step S1-4, the ProceedingJoinPoint method is called to obtain the signature information of the join point, that is, the Signature object, which contains detailed information about the join point;
[0027] In step S1-6, the input parameters are converted into a Map object, and the parameters are spliced to generate a Redis cache key.
[0028] Furthermore, in step S2, it further includes:
[0029] S2-1. If the cache misses, prepare to execute the target business method, obtain the latest data, execute the target business logic through the proceed method of ProceedingJoinPoint, and obtain the execution result of the method;
[0030] S2-2. Check whether the execution result is empty. If it is empty, return the default value. If the execution result is not empty, serialize the result and write it to the Redis cache so that subsequent requests can directly obtain data from the cache.
[0031] Furthermore, in step S3, it further includes:
[0032] S3-1. Get all relevant cache data in the Redis service;
[0033] S3-2. Preprocess the data, extract features from the preprocessed data, select the features, and perform standardization conversion after the selection is completed to finally obtain the specific features of the Redis cache data;
[0034] S3-3. Input the features into a pre-trained prediction model to determine whether the data will become hot data in the future.
[0035] S3-4. Load the intelligent prediction hotspot data into the cache in advance.
[0036] Furthermore, in step S4, it further includes:
[0037] S4-1, real-time monitoring of system load and cache hit rate indicators;
[0038] S4-2. Use reinforcement learning to optimize caching strategies for dynamically changing caching scenarios.
[0039] S4-3, problem modeling for cache scenarios;
[0040] S4-4. Construct a Q table to record the expected returns of state-action pairs and use the update formula to gradually learn the optimal strategy.
[0041] S4-5. Use the optimized cache strategy to adjust the cache content.
[0042] Furthermore, in step S4-3, State: describes the current state of the cache system;
[0043] Action: the action taken;
[0044] Reward: used to evaluate the effect of an action.
[0045] Furthermore, in step S4-4, the update formula is used:
[0046]
[0047] Where: Q(s t , a t ): In state s t Next, perform action a t The action-value function of
[0048] α: learning rate, which controls the step size of each update;
[0049] γ t+1 : Execute action a t Immediate rewards after
[0050] γ: discount factor, used to weigh the importance of current rewards and future rewards;
[0051] max a Q(s t+1 , a): In the next state s t+1 The maximum value of the optimal action is selected.
[0052] A dynamic cache processing device comprises: at least one memory and at least one processor;
[0053] The at least one memory is configured to store a machine-readable program;
[0054] The at least one processor is configured to call the machine-readable program to execute a dynamic cache processing method.
[0055] Compared with the prior art, the dynamic cache processing method and device of the present invention have the following outstanding beneficial effects:
[0056] This invention combines large models with reinforcement learning to dynamically predict and load hotspot data, significantly improving cache hit rates and reducing database access frequency, thereby lowering system load. By combining Redis with AOP, it reduces resource consumption from repeatedly executing business logic, optimizes system response speed, and improves overall performance.
[0057] By combining AOP and Redis, we ensure data consistency between the cache and the database, avoiding data synchronization delays. We use reinforcement learning to dynamically adjust the cache strategy to adapt to changing access patterns, further improving system efficiency and stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0059] Figure 1 It is a flowchart of a dynamic cache processing method. DETAILED DESCRIPTION
[0060] In order to enable those skilled in the art to better understand the solutions of the present invention, the present invention will be further described in detail below in conjunction with specific embodiments. Obviously, the embodiments described are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0061] A best embodiment is given below:
[0062] like Figure 1 As shown, a dynamic cache processing method in this embodiment is based on a large model. The user initiates a business request. After receiving the request, the backend service enters the aspect and first verifies the data cache status. After the verification is passed, the cache in Redis is retrieved and returned to the user.
[0063] If there is no cached data in Redis, the main business processing begins. After the backend service completes the processing, the data is saved to the Redis service. The data in Redis is input into the prediction model to generate predicted hot spot data, which is also saved in Redis.
[0064] Finally, reinforcement learning is used to adjust the cache strategy and cache content.
[0065] The specific steps are as follows:
[0066] S1. Verify the request through aspect programming;
[0067] Further including:
[0068] S1-1. Create a custom annotation class called ConnectRedisCache and specify that this annotation takes effect when methods and programs are running. Add a keyPrefix() method to the annotation class and define an element called keyPrefix. This element will provide a string value when the annotation is used later.
[0069] S1-2. Add the @ConnectRedisCache annotation to the method that needs to cache data;
[0070] S1-3. Define the aspect class RedisCacheAspect and add the @Aspect annotation to it to indicate that it is an aspect class. Configure the weaving point, using the annotation in step S1-1 as the weaving point. This indicates that methods using the annotation in step S1-1 will enter this aspect and perform the corresponding processing within the aspect.
[0071] S1-4. After receiving the front-end request, the back-end service enters the aspect's around notification. The ProceedingJoinPoint parameter is passed to the enhanced method. The ProceedingJoinPoint method is called to obtain the method signature information of the join point, that is, the Signature object. This object contains detailed information about the join point, such as the method name, parameter types, and return type.
[0072] S1-5. Call the getMethod method of Signature to obtain the Method object of the method being proxied in step 1-2. The Method object contains the method name, parameter types, return type, modifiers, etc. The annotation of the proxied method is obtained through the getAnnotation method of Method;
[0073] S1-6. After obtaining the annotation, get the specific value in the ConnectRedisCache annotation. Convert the input parameter to a Map object and perform parameter splicing to generate the Redis cache key.
[0074] S1-7. Use the generated cache key to query Redis and check whether the corresponding cached data is already in the cache. If the cache hits, the cached data is directly returned.
[0075] S2, save the data to Redis;
[0076] Further including:
[0077] S2-1. If the cache misses, prepare to execute the target business method to obtain the latest data. Execute the target business logic through the proceed method of ProceedingJoinPoint and obtain the execution result of the method.
[0078] S2-2. Check whether the execution result is empty. If so, return the default value. If the execution result is not empty, serialize the result and write it to the Redis cache so that subsequent requests can directly obtain data from the cache.
[0079] S3, perform model prediction on the data in Redis;
[0080] Further including:
[0081] S3-1. Obtain all relevant cache data in the Redis service, including user information, frequently used hot data, etc.
[0082] S3-2. Preprocess the data, extract features from the preprocessed data, select the features, and perform standardization conversion after the selection is completed to finally obtain the specific features of the Redis cache data;
[0083] S3-3. Input the features into a pre-trained prediction model to determine whether the data will become hot data in the future.
[0084] S3-4: Load intelligently predicted hotspot data into the cache in advance to improve cache hit rate and reduce response speed.
[0085] S4, adjust cache strategy and cache content through reinforcement learning;
[0086] Further including:
[0087] S4-1, real-time monitoring of various indicators such as system load and cache hit rate;
[0088] S4-2. Use reinforcement learning to optimize caching strategies for dynamically changing caching scenarios.
[0089] S4-3, problem modeling for cache scenarios;
[0090] State: Describes the current state of the cache system, including cache hit rate, cache capacity usage, data access frequency, network load, etc.
[0091] Action: The actions that can be taken include caching a piece of data, eliminating a piece of data, adjusting cache capacity allocation, etc.
[0092] Reward: used to evaluate the effectiveness of an action, such as improving cache hit rate, reducing access latency, and balancing system load.
[0093] S4-4, by constructing a Q table to record the expected returns of state-action pairs, and using the update formula, gradually learn the optimal strategy;
[0094] Use the update formula:
[0095]
[0096] Where: Q(s t , a t ): In state s t Next, perform action a t The action-value function of .
[0097] α: learning rate, which controls the step size of each update.
[0098] γ t+1 : Execute action a t Instant rewards after.
[0099] γ: Discount factor used to weigh the importance of current rewards and future rewards.
[0100] max a Q(s t+1 , a): In the next state s t+1 The maximum value of the optimal action is selected.
[0101] S4-5. Use the optimized cache strategy to adjust the cache content.
[0102] Based on the above method, a dynamic cache processing device in this embodiment includes: at least one memory and at least one processor;
[0103] The at least one memory is configured to store a machine-readable program;
[0104] The at least one processor is configured to call the machine-readable program to execute a dynamic cache processing method.
[0105] The above-mentioned specific implementation methods are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementation methods. Any technical solutions that conform to the above-mentioned specific implementation methods of the present invention and any appropriate changes or substitutions made thereto by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0106] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A dynamic cache processing method based on a large model, characterized in that: The user initiates a business request. After receiving the request, the backend service enters the aspect and verifies the data cache status. After the verification is passed, the cache in Redis is retrieved and returned to the user. If there is no cached data in Redis, the main business processing begins. After the backend service completes the processing, the data is saved to the Redis service. The data in Redis is input into the prediction model to generate predicted hot spot data, which is also saved in Redis. Finally, reinforcement learning is used to adjust the cache strategy and cache content.
2. A dynamic cache processing method according to claim 1, characterized in that: The specific steps are as follows: S1. Verify the request through aspect programming; S2, save the data to Redis; S3, perform model prediction on the data in Redis; S4. Adjust cache strategy and cache content through reinforcement learning.
3. A dynamic cache processing method according to claim 2, characterized in that: In step S1, it further includes: S1-1. Create a custom annotation class ConnectRedisCache and indicate that this annotation takes effect when the method and program are running; S1-2. Add the @ConnectRedisCache annotation to the method that needs to cache data; S1-3. Define the aspect class RedisCacheAspect and add the @Aspect annotation to the aspect class to indicate that this class is an aspect class. S1-4. After receiving the front-end request, the back-end service enters the aspect's around notification. The ProceedingJoinPoint in the around notification is passed as a parameter for the enhancement method. S1-5. Call the getMethod method of Signature to obtain the Method object of the method being proxied in step S1-2, and obtain the annotation of the proxied method through the getAnnotation method of Method; S1-6. After obtaining the annotation, obtain the specific value in the ConnectRedisCache annotation; S1-7. Use the generated cache key to query in Redis to check whether the corresponding cached data already exists in the cache. If the cache hits, the cached data is directly returned.
4. A dynamic cache processing method according to claim 3, characterized in that: In step S1-1, add the keyPrefix() method to the annotation class and define an element named keyPrefix to provide a string value when the annotation is used later; In step S1-3, the weaving point is configured, and the annotation in the above step S1-1 is used as the weaving point, indicating that the method using the annotation in step S1-1 will enter this section and perform corresponding processing in the section; In step S1-4, the ProceedingJoinPoint method is called to obtain the signature information of the join point, that is, the Signature object, which contains detailed information about the join point; In step S1-6, the input parameters are converted into a Map object, and the parameters are spliced to generate a Redis cache key.
5. A dynamic cache processing method according to claim 4, characterized in that: In step S2, further comprising: S2-1. If the cache misses, prepare to execute the target business method, obtain the latest data, execute the target business logic through the proceed method of ProceedingJoinPoint, and obtain the execution result of the method; S2-2. Check whether the execution result is empty. If it is empty, return the default value. If the execution result is not empty, serialize the result and write it to the Redis cache so that subsequent requests can directly obtain data from the cache.
6. A dynamic cache processing method according to claim 5, characterized in that: In step S3, further comprising: S3-1. Get all relevant cache data in the Redis service; S3-2. Preprocess the data, extract features from the preprocessed data, select the features, and perform standardization conversion after the selection is completed to finally obtain the specific features of the Redis cache data; S3-3. Input the features into a pre-trained prediction model to determine whether the data will become hot data in the future. S3-4. Load the intelligent prediction hotspot data into the cache in advance.
7. A dynamic cache processing method according to claim 6, characterized in that: In step S4, further comprising: S4-1, real-time monitoring of system load and cache hit rate indicators; S4-2. Use reinforcement learning to optimize caching strategies for dynamically changing caching scenarios. S4-3, problem modeling for cache scenarios; S4-4. Construct a Q table to record the expected returns of state-action pairs and use the update formula to gradually learn the optimal strategy. S4-5. Use the optimized cache strategy to adjust the cache content.
8. A dynamic cache processing method according to claim 7, characterized in that: In step S4-3, State: describes the current state of the cache system; Action: the action taken; Reward: used to evaluate the effect of an action.
9. A dynamic cache processing method according to claim 8, characterized in that: In step S4-4, the update formula is used: Where: Q(s t , a t ): In state s t Next, perform action a t The action-value function of α: learning rate, which controls the step size of each update; γ t+1 : Execute action a t Immediate rewards after γ: discount factor, used to weigh the importance of current rewards and future rewards; max a Q(s t+1 , a): In the next state s t+1 The maximum value of the optimal action is selected.
10. A dynamic cache processing device, characterized in that: include: at least one memory and at least one processor; The at least one memory is configured to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 9.