Cache management method and device, computer equipment and storage medium
By decoupling caching logic from business code through custom annotations and AOP technology, version control is achieved, solving the problems of code coupling and high cleanup costs in cache management, and improving the efficiency of cache management and system response speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING BAILONGMA TECHNOLOGY CO LTD
- Filing Date
- 2025-12-04
- Publication Date
- 2026-05-01
AI Technical Summary
Existing cache management technologies suffer from high code coupling, high cleanup costs, and lack of version management, making them difficult to adapt to complex business scenarios and multi-cached collaborative management.
By employing custom annotations and aspect-oriented programming (AOP) techniques, target business methods are marked with custom annotations to generate cache keys and version keys. Version control mechanisms are used to compare and update cached content, thereby decoupling the caching logic from the business code and enabling version management.
It improves code simplicity and maintainability, reduces cache cleanup costs, increases cache cleanup efficiency, reduces unnecessary database access and computation, and improves system response speed.
Smart Images

Figure CN121958281A_ABST
Abstract
Description
Cache management methods, apparatus, computer equipment and storage media Technical Field
[0001] This application relates to the field of software development technology, and in particular to a cache management method, apparatus, computer device, and storage medium. Background Technology
[0002] In the current technological context, with increasing business complexity, caching has become a key means to improve system performance and reduce database pressure. However, the methods of caching and related technologies have obvious limitations: On the one hand, explicit cache management requires developers to manually call cache read / write interfaces in business code and manually clear the cache when data changes, resulting in high coupling between cache logic and business logic, high code redundancy, and poor maintainability. Although some frameworks provide simple cache encapsulation based on annotations such as @Cacheable, @CachePut, and @CacheEvict, they still cannot support complex business scenarios such as multi-cache linkage management, cache version control, and reading different caches based on value conditions. On the other hand, when permissions are involved, etc. In scenarios involving multiple cache associations, existing technologies require manual cleanup of multiple related caches, which is not only cumbersome but also incurs significant performance overhead. Furthermore, cache version control lacks a unified mechanism, requiring most systems to explicitly handle version numbers in business code to determine cache validity. This lacks versatility and automation, making it difficult to adapt to hierarchical and interconnected business needs. In addition, while Aspect-Oriented Programming (AOP) technology has been widely used to decouple business logic from cross-cutting concerns (such as logging and transactions), providing a technical foundation for the extraction and unified reuse of cache management logic, related technologies have not yet fully integrated with AOP to achieve deep fusion of caching and version control, failing to solve the aforementioned problems of complex cache usage, high cleanup costs, and lack of version management. Summary of the Invention
[0003] Therefore, it is necessary to provide a cache management method, apparatus, computer equipment, and storage medium that can solve the problems of complex cache usage, high cleanup costs, and lack of version management, in order to address the aforementioned technical issues.
[0004] Firstly, a cache management method is provided, the method comprising: determining a custom annotation; marking a target business method that needs to enable caching based on the custom annotation; intercepting calls to the target business method marked by the custom annotation based on aspect-oriented programming; in response to the completion of interception, generating a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; in response to the current version number being higher than or equal to the target version number, returning the cache content; and in response to the current version number being lower than the target version number, executing the target business method and updating the cache content.
[0005] Optionally, determining custom annotations and marking target business methods that require caching functionality based on the custom annotations includes: determining custom annotations, wherein the custom annotations include a first custom annotation and a second custom annotation, the first custom annotation being used to enable the caching component, and the second custom annotation being used to mark the return value of the business method as needing to be cached; determining target business methods that require caching functionality; and marking target business methods that require caching functionality based on the custom annotations.
[0006] Optionally, intercepting calls to target business methods marked by the target custom annotation based on aspects includes: in response to receiving an aspect registration request, registering the aspect based on the aspect registration request; defining a pointcut and configuring rules for the pointcut in the aspect, wherein the rules for the pointcut are configured to match business methods marked by the custom annotation; in response to the target business method being called, matching the characteristics of the target business method based on the aspect according to the rules of the pointcut; in response to a successful match, interrupting the execution flow of the target business method and transferring the execution right of the target business method to the around advice method of the aspect.
[0007] Optionally, generating a cache key and version key corresponding to the target business method call based on the configuration information defined in the custom annotation and the relevant attributes of the target business method includes: parsing the configuration information defined in the custom annotation, wherein the configuration information is a key prefix or namespace; obtaining the signature of the target business method and the parameters of the target business method call; generating a cache key for uniquely identifying the target business method call based on the key prefix or namespace, the signature, and the parameters through a string concatenation mechanism; and generating a version key that identifies the data scope based on the key prefix or namespace and the key business identifier in the parameters.
[0008] Optionally, before reading the cached content corresponding to the cache key, the method further includes: constructing a cache entity in a unified format, the cache entity including at least a version number field and a data value field; filling the current version number into the version number field; filling the actual result obtained by executing the target business method into the data value field; defining the cache entity filled with the version number field and the data value field as the cached content; associating the cached content with the cache key and storing it in the cache system.
[0009] Optionally, based on the version key, determining the current version number and reading the cached content corresponding to the cache key, and comparing the current version number with the target version number in the cached content includes: querying the current version number from the cache system based on the version key; querying the cached content from the cache system based on the cache key, parsing the cached content to obtain the target version number and a cached value; comparing the current version number with the target version number to obtain a comparison result; and determining whether the cached content is valid based on the comparison result.
[0010] Optionally, determining whether the cached content is valid based on the comparison result includes: in response to the current version number being higher than or equal to the target version number, determining that the cached content is valid and returning the cached value; in response to the current version number being lower than the target version number, determining that the cached content is invalid, executing the target business method and updating the cached value.
[0011] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: determining a custom annotation; marking a target business method that requires caching based on the custom annotation; intercepting calls to the target business method marked by the custom annotation based on aspect-oriented programming; in response to the interception being completed, generating a cache key and a version key corresponding to the call to the target business method based on configuration information defined in the custom annotation and relevant attributes of the target business method; determining the current version number based on the version key, reading the cached content corresponding to the cache key, and comparing the current version number with the target version number in the cached content; in response to the current version number being higher than or equal to the target version number, returning the cached content; and in response to the current version number being lower than the target version number, executing the target business method and updating the cached content.
[0012] Fourthly, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: determining a custom annotation; marking a target business method that needs to enable caching based on the custom annotation; intercepting calls to the target business method marked by the target custom annotation based on aspect-oriented programming; in response to the completion of interception, generating a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; in response to the current version number being higher than or equal to the target version number, returning the cache content; in response to the current version number being lower than the target version number, executing the target business method and updating the cache content.
[0013] Fifthly, a computer program product is provided, comprising a computer program that, when executed by a processor, performs the following steps: determining a custom annotation; marking a target business method requiring caching functionality based on the custom annotation; intercepting calls to the target business method marked by the custom annotation based on aspect-oriented programming; in response to interception completion, generating a cache key and a version key corresponding to the call to the target business method based on configuration information defined in the custom annotation and relevant attributes of the target business method; determining the current version number based on the version key, reading the cached content corresponding to the cache key, and comparing the current version number with the target version number in the cached content; in response to the current version number being higher than or equal to the target version number, returning the cached content; and in response to the current version number being lower than the target version number, executing the target business method and updating the cached content.
[0014] The aforementioned cache management method, apparatus, computer device, and storage medium, the method comprising: determining a custom annotation; marking a target business method that needs to enable caching based on the custom annotation; intercepting calls to the target business method marked by the custom annotation based on aspect-oriented programming; in response to interception completion, generating a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; in response to the current version key... If the current version number is higher than or equal to the target version number, the cached content is returned; if the current version number is lower than the target version number, the target business method is executed and the cached content is updated. This application completely decouples the caching logic from the business code through AOP and annotations, improving the simplicity and maintainability of the code. Through the version control mechanism, only one global version number needs to be updated to invalidate all associated caches in batches, avoiding the performance impact caused by traversing and deleting caches in traditional solutions, and improving cache cleanup efficiency. At the same time, lazy updating and intelligent reuse of cache are achieved through version comparison, reducing unnecessary database access and calculation, effectively reducing system load, and improving overall response speed. Attached Figure Description
[0015] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 is an application environment diagram of the cache management method in one embodiment; Figure 2 is a flowchart of the cache management method in one embodiment; Figure 3 is another flowchart of the cache management method in one embodiment; Figure 4 is an injection flowchart of the custom key concatenation implementation method in one embodiment; Figure 5 is a flowchart of concatenating cache keys in one embodiment; Figure 6 is a flowchart of the super administrator permission update process in one embodiment; Figure 7 is a structural block diagram of the cache management device in one embodiment; Figure 8 is an internal structure diagram of the computer device in one embodiment. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0018] It should be understood that, in the description of this application, unless the context explicitly requires it, words such as "including" or "comprising" throughout the specification should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to".
[0019] It should also be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0020] It should be noted that the terms "S1," "S2," etc., are used only for descriptive purposes and do not specifically refer to the order or sequence, nor are they intended to limit this application. They are merely for the convenience of describing the method of this application and should not be construed as indicating the sequential order of the steps. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0021] The cache management method provided in this application can be applied to the application environment shown in Figure 1. Terminal 102 communicates with a data processing platform set up on server 104 via a network. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0022] In one embodiment, as shown in Figures 2-3, a cache management method is provided. Taking the application of this method to the terminal in Figure 1 as an example, the method includes the following steps: S1: Determine the custom annotation, and mark the target business method that needs to enable the caching function based on the custom annotation.
[0023] It should be noted that a custom annotation is a Java metadata marker defined by the developer. It is used to add structured information to the code and is often used in frameworks to implement declarative programming. The custom annotation includes a first custom annotation and a second custom annotation. The first custom annotation is used to enable the caching component, and the second custom annotation is used to mark the return value of the business method as needing to be cached. The first custom annotation is EnableAutoCache, and the second custom annotation is CacheHelper. A business method refers to a code unit in a software system that implements specific business logic and functions. It directly corresponds to business requirements and includes data processing (such as CRUD operations), business rule validation, calculation and decision logic, and external service calls.
[0024] S2: Based on aspect interception, the call to the target business method marked by the target custom annotation is intercepted.
[0025] It should be noted that aspect refers to AOP (Aspect-Oriented Programming), a software development paradigm that improves code modularity and maintainability by separating cross-cutting concerns (such as logging, transactions, and permissions) from core business logic. It implements these concerns in a declarative manner, avoiding the distribution of duplicate code across multiple business classes, thereby reducing code redundancy and enhancing code readability, maintainability, and reusability.
[0026] S3: In response to the completion of interception, generate a cache key and version key corresponding to the target business method call based on the configuration information defined in the custom annotation and the relevant attributes of the target business method.
[0027] It should be noted that caching is a temporary storage mechanism used to speed up data access and reduce the frequency of access to the underlying data source. Configuration information refers to elements directly declared in custom annotations (such as @CacheHelper) that control caching behavior. These can include key prefixes or namespaces, such as key=USER. Related attributes refer to information about this specific call that can only be determined when the business method is run. These can include signatures (such as class name and method name) and actual parameter values. The actual parameter values are the specific parameter values passed when the business method is called. The cache key refers to the valueKey corresponding to the cached content, and the version key refers to the versionKey corresponding to version control. In the application, version control refers to the maintenance of version numbers of cached data to realize cache validity judgment and update strategies.
[0028] S4: Based on the version key, determine the current version number, read the cache content corresponding to the cache key, and compare the current version number with the target version number in the cache content.
[0029] It should be noted that the cached content is a unified structured object, mainly containing two core parts: Content Version Number: Records the global version state when the cached data was generated, which is the basis for determining the validity of the cache; Cache Value: The actual result data returned by the target business method, which is the business entity stored in the cache. This structure binds the data with its version information, so that the system does not need to execute business logic, but can determine the validity of the data and directly return the corresponding cache value by simply comparing the version number. The content used for comparison is...
[0030] S5: In response to the current version number being higher than or equal to the target version number, return the cached content.
[0031] S6: In response to the current version number being lower than the target version number, execute the target business method and update the cached content.
[0032] In the above implementation, AOP and annotations completely decouple the caching logic from the business code, improving the simplicity and maintainability of the code. Through the version control mechanism, all associated caches can be invalidated in batches by updating only a global version number, avoiding the performance impact caused by traversing and deleting caches in traditional solutions, and improving cache cleanup efficiency. At the same time, lazy updating and intelligent reuse of caches are achieved through version comparison, reducing unnecessary database access and calculation, effectively reducing system load, and improving overall response speed.
[0033] In some specific implementations, determining custom annotations and marking target business methods that require caching functionality based on these custom annotations includes: determining custom annotations, wherein the custom annotations include a first custom annotation and a second custom annotation, the first custom annotation being used to enable the caching component, and the second custom annotation being used to mark the return value of the business method as needing to be cached; determining target business methods that require caching functionality; and marking target business methods that require caching functionality based on the custom annotations.
[0034] In some specific implementations, intercepting calls to target business methods marked by the target custom annotation based on aspect includes: in response to receiving an aspect registration request, registering the aspect based on the aspect registration request, wherein the aspect registration request is generally issued when the application starts, and the aspect registration method is a common method, the specific process of which will not be elaborated here; defining a pointcut and configuring the rules of the pointcut in the aspect, wherein the rules of the pointcut are configured to match business methods marked by the custom annotation, and the pointcut definition method and the pointcut rule configuration method are both common methods, the specific process of which is described here. Further details are omitted; in response to the invocation of the target business method, the aspect is matched with the characteristics of the target business method according to the rules of the pointcut, wherein the invocation characteristics of the target business method are matched with the conditions defined in the pointcut rules, and the characteristics may include annotation metadata, method signature, and execution context, etc.; in response to a successful match, the execution flow of the target business method is interrupted, and the execution right of the target business method is transferred to the around advice method of the aspect, wherein around advice is an enhancement type in AOP that allows the aspect to have complete control over the execution of the target business method.
[0035] In some specific implementations, generating cache keys and version keys corresponding to the target business method call, based on the configuration information defined in the custom annotation and the relevant attributes of the target business method, includes: parsing the configuration information defined in the custom annotation, where the configuration information is a key prefix or namespace; obtaining the signature of the target business method and the parameters of the target business method call, wherein the parameters are actual variables or values passed to the business method at runtime, such as the getUser(Long) method for querying user information. The id passed in when the method is called is 123, which is the parameter for this call. Based on the key prefix or namespace, the signature, and the parameter, a cache key for uniquely identifying the target business method call is generated through a string concatenation mechanism. As shown in Figure 5, the string concatenation mechanism is a program processing method that combines multiple strings end-to-end to form a new string. For example, static configurations from custom annotations (such as the key prefix USER) and dynamic attributes from method calls (such as method signatures and parameter values) are concatenated in a predetermined order and separated by a separator (such as a colon), such as generating USER: getUserById: 123. In addition, as shown in Figure 4, the concatenation method of the cache key and version key can be customized. Based on the key prefix or namespace and the key business identifier in the parameter, a version key identifying the data category is generated. The data category refers to a category defined by specific business logic and has A set or boundary of data with the same invalidation condition. For example, in a permission system, the permission data of a super administrator role and all its subordinate sub-roles constitute a data category. This category is identified by a shared version key (e.g., ROLE:SUPER_ADMIN). When the core data within the category (e.g., super administrator permissions) changes, only the version number of the version key needs to be incremented to invalidate all associated caches within the category in batches, without the need for individual cleanup. As shown in Figure 6, when the resources owned by the super administrator role are reduced, based on the premise that the permissions of all roles must not exceed the super administrator's permissions, the resource caches of all roles under the super administrator role need to be updated. Otherwise, an unauthorized operation will occur. This includes updating the resources owned by the super administrator role and updating the version number of all role resources that depend on the super administrator role's resources (they share a single version number, so it only needs to be set once). The next time a role obtains the resources owned by the role, it will follow the process of this application.
[0036] In some specific implementations, before reading the cached content corresponding to the cache key, the method further includes: constructing a cache entity with a unified format, the cache entity including at least a version number field and a data value field; filling the current version number into the version number field; filling the actual result obtained by executing the target business method into the data value field; defining the cache entity filled with the version number field and the data value field as the cached content; associating the cached content with the cache key and storing it in the cache system.
[0037] Specifically, a cache entity with a unified format is constructed. The cache entity includes a version field and a value field. The version field stores the current cached version information, and the value field stores the actual return content of the target method. The version field is the version number field, and the value field is the data value field.
[0038] In some specific implementations, determining the current version number based on the version key and reading the cached content corresponding to the cache key, and comparing the current version number with the target version number in the cached content includes: querying the current version number from the cache system based on the version key; querying the cached content from the cache system based on the cache key, parsing the cached content to obtain the target version number and a cached value; comparing the current version number with the target version number to obtain a comparison result; and determining whether the cached content is valid based on the comparison result.
[0039] In some specific implementations, determining whether the cached content is valid based on the comparison result includes: in response to the current version number being higher than or equal to the target version number, determining that the cached content is valid and returning the cached value; in response to the current version number being lower than the target version number, determining that the cached content is invalid, executing the target business method and updating the cached value.
[0040] Specifically, the cache entity corresponding to valueKey and the version value corresponding to versionKey are read from the cache. It is then determined whether the version field value in the cache entity is greater than the version value corresponding to versionKey. If the version field value in the cache entity is greater than or equal to the version value corresponding to versionKey, the content stored in the value field of the cache entity is directly returned. Otherwise, the target business method is executed, the return result is obtained, and the cache entity and the version value corresponding to versionKey are updated.
[0041] The above cache management method includes: determining a custom annotation; marking target business methods that need to enable caching based on the custom annotation; intercepting calls to target business methods marked by the custom annotation based on aspect-oriented programming; in response to the completion of interception, generating a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; in response to the current version number being greater than or equal to... The target version number is used to return the cached content; in response to the current version number being lower than the target version number, the target business method is executed and the cached content is updated; this application completely decouples the caching logic from the business code through AOP and annotations, improving the simplicity and maintainability of the code. Through the version control mechanism, only one global version number needs to be updated to invalidate all associated caches in batches, avoiding the performance impact caused by traversing and deleting caches in traditional solutions, and improving cache cleanup efficiency. At the same time, lazy updating and intelligent reuse of the cache are achieved through version comparison, reducing unnecessary database access and calculation, effectively reducing system load, and improving overall response speed.
[0042] It should be understood that although the steps in the flowcharts of Figures 2-6 are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in Figures 2-6 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0043] In one embodiment, as shown in Figure 7, a cache management device is provided, comprising: a marking module, configured to determine a custom annotation and mark a target business method that needs to enable caching based on the custom annotation; an interception module, configured to intercept calls to the target business method marked by the target custom annotation based on aspect ratios; a generation module, configured to generate a cache key and a version key corresponding to the call to the target business method in response to the completion of interception, based on the configuration information defined in the custom annotation and the relevant attributes of the target business method; a comparison module, configured to determine the current version number based on the version key, read the cache content corresponding to the cache key, and compare the current version number with the target version number in the cache content; a first processing module, configured to return the cache content in response to the current version number being higher than or equal to the target version number; and a second processing module, configured to execute the target business method and update the cache content in response to the current version number being lower than the target version number.
[0044] In a preferred embodiment of the present invention, the marking module is specifically used to: determine custom annotations, wherein the custom annotations include a first custom annotation and a second custom annotation, the first custom annotation being used to enable a caching component, and the second custom annotation being used to mark the return value of a business method as needing to be cached; determine the target business method that needs to enable caching functionality; and mark the target business method that needs to enable caching functionality based on the custom annotations.
[0045] In a preferred embodiment of the present invention, the interception module is specifically configured to: in response to receiving an aspect registration request, register the aspect based on the aspect registration request; define a pointcut and configure the rules of the pointcut in the aspect, wherein the rules of the pointcut are configured to match business methods marked by the custom annotation; in response to the target business method being invoked, match the features of the target business method based on the aspect and the rules of the pointcut; in response to a successful match, interrupt the execution flow of the target business method and transfer the execution right of the target business method to the around advice method of the aspect.
[0046] In a preferred embodiment of the present invention, the generation module is specifically used to: parse the configuration information defined in the custom annotation, wherein the configuration information is a key prefix or namespace; obtain the signature of the target business method and the parameters of the target business method call; generate a cache key for uniquely identifying the target business method call based on the key prefix or namespace, the signature, and the parameters through a string concatenation mechanism; and generate a version key that identifies the data category based on the key prefix or namespace and the key business identifier in the parameters.
[0047] In a preferred embodiment of the present invention, the generation module is further configured to: construct a cache entity in a unified format, the cache entity including at least a version number field and a data value field; fill the current version number into the version number field; fill the actual result obtained by executing the target business method into the data value field; define the cache entity filled with the version number field and the data value field as the cache content; associate the cache content with the cache key and store it in the cache system.
[0048] In a preferred embodiment of the present invention, the comparison module is specifically used for: querying the current version number from the cache system based on the version key; querying the cached content from the cache system based on the cache key; parsing the cached content to obtain the target version number and the cached value; comparing the current version number with the target version number to obtain a comparison result; and determining whether the cached content is valid based on the comparison result.
[0049] In a preferred embodiment of the present invention, the comparison module is further configured to: determine that the cached content is valid and return the cached value in response to the current version number being higher than or equal to the target version number; and determine that the cached content is invalid in response to the current version number being lower than the target version number, execute the target business method and update the cached value.
[0050] For specific limitations regarding the cache management device, please refer to the limitations on the cache management method above, which will not be repeated here. Each module in the aforementioned cache management device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0051] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in Figure 8. The computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a cache management method. The display screen of the computer device may be a liquid crystal display (LCD) or an electronic ink display. The input devices of the computer device may be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse, etc.
[0052] Those skilled in the art will understand that the structure shown in Figure 8 is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or may combine certain components, or may have different component arrangements.
[0053] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps: S1: Determine a custom annotation, and based on the custom annotation, mark a target business method that requires caching; S2: Intercept calls to the target business method marked by the target custom annotation based on aspect-oriented programming; S3: In response to the completion of interception, generate a cache key and a version key corresponding to the call to the target business method based on the configuration information defined in the custom annotation and the relevant attributes of the target business method; S4: Based on the version key, determine the current version number, read the cache content corresponding to the cache key, and compare the current version number with the target version number in the cache content; S5: In response to the current version number being higher than or equal to the target version number, return the cache content; S6: In response to the current version number being lower than the target version number, execute the target business method and update the cache content.
[0054] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: S1: Determine a custom annotation, and mark a target business method that needs to enable caching based on the custom annotation; S2: Intercept calls to the target business method marked by the target custom annotation based on aspect-oriented programming; S3: In response to the completion of interception, generate a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; S4: Determine the current version number based on the version key, read the cache content corresponding to the cache key, and compare the current version number with the target version number in the cache content; S5: In response to the current version number being higher than or equal to the target version number, return the cache content; S6: In response to the current version number being lower than the target version number, execute the target business method and update the cache content.
[0055] In one embodiment, a computer program product is provided, the computer program product including a computer program, which, when executed by a processor, performs the following steps: S1: Determine a custom annotation, and mark a target business method that needs to enable caching based on the custom annotation; S2: Intercept calls to the target business method marked by the target custom annotation based on aspect-oriented programming; S3: In response to the completion of interception, generate a cache key and a version key corresponding to the call to the target business method according to the configuration information defined in the custom annotation and the relevant attributes of the target business method; S4: Determine the current version number based on the version key, read the cache content corresponding to the cache key, and compare the current version number with the target version number in the cache content; S5: In response to the current version number being higher than or equal to the target version number, return the cache content; S6: In response to the current version number being lower than the target version number, execute the target business method and update the cache content.
[0056] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0057] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0058] The embodiments described above are merely examples of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application.
Claims
1. A cache management method, characterized in that, The method includes: determining a custom annotation; marking target business methods that require caching functionality based on the custom annotation; intercepting calls to the target business methods marked by the custom annotation based on aspect-oriented programming; in response to the completion of interception, generating a cache key and a version key corresponding to the call to the target business method based on the configuration information defined in the custom annotation and the relevant attributes of the target business method; determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; in response to the current version number being higher than or equal to the target version number, returning the cache content; in response to the current version number being lower than the target version number, executing the target business method and updating the cache content.
2. The cache management method according to claim 1, characterized in that, The process of determining custom annotations and marking target business methods that require caching functionality based on these custom annotations includes: determining custom annotations, wherein the custom annotations include a first custom annotation and a second custom annotation, the first custom annotation being used to enable the caching component, and the second custom annotation being used to mark the return value of the business method as needing to be cached; determining target business methods that require caching functionality; and marking target business methods that require caching functionality based on the custom annotations.
3. The cache management method according to claim 1, characterized in that, The interception of calls to target business methods marked by the target custom annotation based on aspect includes: in response to receiving an aspect registration request, registering the aspect based on the aspect registration request; defining a pointcut and configuring rules for the pointcut in the aspect, wherein the rules for the pointcut are configured to match business methods marked by the custom annotation; in response to the target business method being called, matching the characteristics of the target business method based on the aspect according to the rules of the pointcut; in response to a successful match, interrupting the execution flow of the target business method and transferring the execution right of the target business method to the around advice method of the aspect.
4. The cache management method according to claim 1, characterized in that, Generating a cache key and a version key corresponding to the target business method call, based on the configuration information defined in the custom annotation and the relevant attributes of the target business method, includes: parsing the configuration information defined in the custom annotation, where the configuration information is a key prefix or namespace; obtaining the signature of the target business method and the parameters of the target business method call; generating a cache key to uniquely identify the target business method call using a string concatenation mechanism based on the key prefix or namespace, the signature, and the parameters; and generating a version key that identifies the data scope based on the key prefix or namespace and the key business identifier in the parameters.
5. The cache management method according to claim 2, characterized in that, Before reading the cached content corresponding to the cache key, the method further includes: constructing a cache entity with a unified format, the cache entity including at least a version number field and a data value field; filling the current version number into the version number field; filling the actual result obtained by executing the target business method into the data value field; defining the cache entity filled with the version number field and the data value field as the cached content; associating the cached content with the cache key and storing it in the cache system.
6. The cache management method according to claim 5, characterized in that, Based on the version key, the current version number is determined, and the cached content corresponding to the cache key is read. Comparing the current version number with the target version number in the cached content includes: retrieving the current version number from the cache system based on the version key; retrieving the cached content from the cache system based on the cache key, parsing the cached content to obtain the target version number and a cached value; comparing the current version number with the target version number to obtain a comparison result; and determining whether the cached content is valid based on the comparison result.
7. The cache management method according to claim 6, characterized in that, Based on the comparison result, determining whether the cached content is valid includes: in response to the current version number being higher than or equal to the target version number, determining that the cached content is valid and returning the cached value; in response to the current version number being lower than the target version number, determining that the cached content is invalid, executing the target business method and updating the cached value.
8. A cache management device, characterized in that, The device includes: a marking module for determining custom annotations and marking target business methods that require caching functionality based on the custom annotations; an interception module for intercepting calls to target business methods marked by the target custom annotations based on aspect ratios; a generation module for generating a cache key and a version key corresponding to the call to the target business method in response to the completion of interception, based on the configuration information defined in the custom annotations and the relevant attributes of the target business method; a comparison module for determining the current version number based on the version key, reading the cache content corresponding to the cache key, and comparing the current version number with the target version number in the cache content; a first processing module for returning the cache content in response to the current version number being higher than or equal to the target version number; and a second processing module for executing the target business method and updating the cache content in response to the current version number being lower than the target version number.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.