Cache operation method and device, electronic equipment, storage medium and program product
By determining the cache information code in the application code of the application and instantiating the general cache instance, the development efficiency problem caused by different applications operating different types of caches is solved, and efficient cache operation processing is achieved.
Patent Information
- Application Number
- CN202410012025.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-03
- Publication Date
- 2025-07-04
AI Technical Summary
In electronic devices, operating different types of caches for different applications requires writing a large amount of cache code, resulting in inefficient development.
By determining the cache information code in the application code of the application, and instantiating the target cache instance with the general cache code, it realizes the target data operations in the target cache, including query, update or delete operations.
There is no need to write cache code for each application that operates different types of caches, which improves the development efficiency of the application.
Smart Images

Figure CN120255894A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular, to a cache operation method, apparatus, electronic device, storage medium, and program product. Background Art
[0002] In an electronic device, multiple types of caches can be provided. For example, a Remote Dictionary Server (Redis) cache, a distributed cache (memcached cache), etc.
[0003] In the related art, multiple application programs can be deployed in an electronic device. Different application programs can operate different types of caches. However, in the above manner, it is necessary to write cache codes for operating different types of caches for different application programs, and the writing workload is large, resulting in low development efficiency of the application programs. Summary of the Invention
[0004] Multiple aspects of this application provide a cache operation method, apparatus, electronic device, storage medium, and program product to improve the development efficiency of application programs.
[0005] In a first aspect, an embodiment of this application provides a cache operation method, including:
[0006] Determine cache information code in the application code of the application program, and determine the target cache to be operated by the application program and the target data information of the target data to be operated according to the cache information code;
[0007] Determine the target cache instance corresponding to the application program, where the target cache instance is obtained by instantiating a general cache code, and the general cache code is a general code for operating multiple types of caches;
[0008] Operate and process the target data in the target cache through the target cache instance.
[0009] In a possible implementation manner, determining the target cache instance corresponding to the target application program includes:
[0010] If a cache instance corresponding to the application program exists in the preset storage space, determine the cache instance corresponding to the application program existing in the preset storage space as the target cache instance; or,
[0011] If a cache instance corresponding to the application program does not exist in the preset storage space, generate the target cache instance.
[0012] In a possible implementation manner, generating the target cache instance includes:
[0013] In the configuration file corresponding to the application, determine the cache configuration information of the target cache corresponding to the application;
[0014] Determine the program information of the application;
[0015] According to the cache configuration information and the program information, perform instantiation processing on the general cache code to obtain the target cache instance.
[0016] In a possible implementation manner, determining cache information code in the application code of the application includes:
[0017] During the execution of the application code of the application, if there is a preset flag bit in the target line code of the application code, determine the target line code as the cache information code.
[0018] In a possible implementation manner, the cache information code includes an identification line code and a filtering line code; according to the cache information code, determining the target cache to be operated by the application and the target data information includes:
[0019] Perform parsing processing on the identification line code to obtain a target cache identifier and a target data identifier;
[0020] Perform parsing processing on the filtering line code to obtain a data filtering condition;
[0021] Determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition.
[0022] In a possible implementation manner, performing operation processing on the target data in the target cache through the target cache instance includes:
[0023] Determine the cache operation code corresponding to the cache information code in the application code, where the cache operation code includes an operation code for operating on the target data in the target cache;
[0024] According to the cache operation code, call the target cache instance to perform operation processing on the target data in the target cache.
[0025] In a possible implementation manner, the operation processing is used to request to perform at least one of the following operations on the target data in the target cache: query, update, or delete; according to the cache operation code, calling the target cache instance to perform operation processing on the target data in the target cache includes:
[0026] Determine whether the target data exists in the target cache through the target cache instance;
[0027] If the target data exists in the target cache, call the target cache instance according to the cache operation code to perform operation processing on the target data in the target cache.
[0028] In a possible implementation manner, the method further includes:
[0029] If the target data does not exist in the target cache, obtain the target data from the database according to the cache operation code, and store the target data in the target cache.
[0030] In a possible implementation manner, performing operation processing on the target data in the target cache includes at least one of the following:
[0031] Query the target data in the target cache;
[0032] Update the target data in the target cache;
[0033] Write the target data into the target cache;
[0034] Delete the target data in the target cache.
[0035] In a second aspect, an embodiment of the present application provides a cache operation device, including: a first determination module, a second determination module, and a processing module, where
[0036] The first determination module is configured to determine cache information code in the application code of the application program, and determine the target cache to be operated by the application program and the target data information of the target data to be operated according to the cache information code;
[0037] The second determination module is configured to determine a target cache instance corresponding to the application program, where the target cache instance is obtained by instantiating a general cache code, and the general cache code is a general code for operating multiple types of caches;
[0038] The processing module is configured to perform operation processing on the target data in the target cache through the target cache instance.
[0039] In a possible implementation manner, the second determination module is specifically configured to:
[0040] If a cache instance corresponding to the application program exists in the preset storage space, determine the cache instance corresponding to the application program existing in the preset storage space as the target cache instance; or,
[0041] If there is no cache instance corresponding to the application program in the preset storage space, generate the target cache instance.
[0042] In a possible implementation manner, the second determination module is specifically configured to:
[0043] In the configuration file corresponding to the application program, determine the cache configuration information of the target cache corresponding to the application program;
[0044] Determine the program information of the application program;
[0045] According to the cache configuration information and the program information, perform instantiation processing on the general cache code to obtain the target cache instance.
[0046] In a possible implementation manner, the first determination module is specifically configured to:
[0047] During the execution of the application code of the application program, if there is a preset flag bit in the target line code of the application code, determine the target line code as the cache information code.
[0048] In a possible implementation manner, the cache information code includes an identification line code and a filtering line code; the first determination module is specifically configured to:
[0049] Perform parsing processing on the identification line code to obtain a target cache identifier and a target data identifier;
[0050] Perform parsing processing on the filtering line code to obtain a data filtering condition;
[0051] Determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition.
[0052] In a possible implementation manner, the processing module is specifically configured to:
[0053] In the application code, determine the cache operation code corresponding to the cache information code, where the cache operation code includes an operation code for operating on the target data in the target cache;
[0054] According to the cache operation code, call the target cache instance to perform operation processing on the target data in the target cache.
[0055] In a possible implementation manner, the operation processing is used to request to perform at least one of the following operations on the target data in the target cache: query, update, or delete; the processing module is specifically configured to:
[0056] Determine whether the target data exists in the target cache through the target cache instance;
[0057] If the target data exists in the target cache, call the target cache instance according to the cache operation code to perform operation processing on the target data in the target cache.
[0058] In a possible implementation manner, the processing module is further configured to:
[0059] If the target data does not exist in the target cache, obtain the target data from the database according to the cache operation code, and store the target data in the target cache.
[0060] In a possible implementation manner, performing operation processing on the target data in the target cache includes at least one of the following:
[0061] Query the target data in the target cache;
[0062] Update the target data in the target cache;
[0063] Write the target data in the target cache;
[0064] Delete the target data in the target cache.
[0065] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor;
[0066] The memory stores computer execution instructions;
[0067] The processor executes the computer execution instructions stored in the memory, so that the processor executes the method according to any one of the first aspect.
[0068] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored, and when the computer execution instructions are executed by a processor, they are used to implement the method according to any one of the first aspect.
[0069] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the method according to any one of the first aspect.
[0070] Embodiments of the present application provide a cache operation method, apparatus, electronic device, storage medium, and program product. The electronic device can determine cache information code in the application code of an application program, and based on the cache information code, determine the target cache to be operated on by the application program and the target data information of the target data to be operated on; determine the target cache instance corresponding to the application program, where the target cache instance is obtained by instantiating a general cache code; and perform operation processing on the target data in the target cache through the target cache instance. Since for different application programs, different cache instances corresponding to the application programs can be obtained by instantiating the general cache code. The application program can call the corresponding cache instance to operate on the corresponding target cache. Compared with the prior art, there is no need to write cache code for operating different types of caches for each application program, so the development efficiency of the application program is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation of the present application. In the drawings:
[0072] Figure 1 FIG. is a schematic diagram of a scenario provided by an exemplary embodiment of the present application;
[0073] Figure 2 FIG. is a schematic flowchart of a cache operation method provided by an exemplary embodiment of the present application;
[0074] Figure 3 FIG. is a schematic diagram of a preset storage space provided by an exemplary embodiment of the present application;
[0075] Figure 4 FIG. is a flowchart of a cache operation method provided by an exemplary embodiment of the present application;
[0076] Figure 5 FIG. is a schematic diagram of cache operation code provided by an exemplary embodiment of the present application;
[0077] Figure 6 FIG. is a schematic diagram of the process of a cache operation method provided by an exemplary embodiment of the present application;
[0078] Figure 7 FIG. is a schematic structural diagram of a cache operation apparatus provided by an exemplary embodiment of the present application;
[0079] Figure 8 FIG. is a schematic structural diagram of an electronic device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0080] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards, and corresponding operation entrances are provided for users to choose to authorize or reject.
[0081] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts shall fall within the scope of protection of this application.
[0082] Figure 1 A schematic diagram of a scenario provided for an exemplary embodiment of this application. Please refer to Figure 1 , multiple application programs and multiple caches can be provided in an electronic device. For example, the multiple application programs can be Application Program 01, Application Program 02,..., Application Program n respectively; the multiple caches can be Cache 01, Cache 02,..., Cache m. Among them, both n and m are integers greater than or equal to 1.
[0083] For any one application program, the application program can have a corresponding cache instance. For example, Application Program 01 can have a corresponding Cache Instance 01, Application Program 02 can have a corresponding Cache Instance 02,..., Application Program n can have a corresponding Cache Instance n. These n cache instances are obtained by instantiating the general cache code.
[0084] The application program can call the cache instance to operate the corresponding target cache. For example, Application Program 01 can call Cache Instance 01 to operate Cache 01, and Application Program 02 can also call Cache Instance 02 to operate Cache 01.
[0085] In the related art, multiple application programs can be deployed in an electronic device. Different application programs can operate different types of caches. However, in the above method, it is necessary to write cache codes for operating different types of caches for different application programs, and the writing workload is large, resulting in low development efficiency of the application programs.
[0086] In the embodiments of the present application, for different applications, different cache instances corresponding to the applications can be obtained by instantiating the general cache code. The application can call the corresponding cache instance to operate on the corresponding target cache. Compared with the prior art, there is no need to write cache code for operating different types of caches for each application, which improves the development efficiency of the application.
[0087] Next, the technical solution shown in the present application will be described in detail through specific embodiments. It should be noted that the following several embodiments can exist independently or be combined with each other. For the same or similar content, it will not be repeated in different embodiments.
[0088] Figure 2 It is a flowchart of a cache operation method provided for an exemplary embodiment of the present application. Please refer to Figure 2 , the method may include:
[0089] S201. Determine cache information code in the application code of the application, and determine the target cache to be operated by the application and the target data information of the target data to be operated according to the cache information code.
[0090] The execution subject of the embodiments of the present application can be an electronic device or a cache operation device provided in the electronic device. The cache operation device can be implemented by software or by a combination of software and hardware. The cache operation device can be a processor in the electronic device. For the sake of easy understanding, in the following, the execution subject is taken as an electronic device for illustration.
[0091] Application code refers to the code for running the application.
[0092] Cache information code is cache code marked with annotations. The annotations can include CacheExtend annotation and Cacheable annotation. These two annotations can be marked on the same function.
[0093] The Cacheable annotation can be used to indicate that the corresponding function needs to operate on the cache; the CacheExtend annotation is an extension of the Cacheable annotation. The CacheExtend annotation can be used to mark data screening conditions, and the data screening conditions can be expiration time or version number, etc.
[0094] There can be multiple caches in the electronic device. For any application, the application can operate on the corresponding target cache.
[0095] The target data information may include a target data identifier and a data filtering condition. For example, in target data information 01, the target data identifier may be "with a digital prefix of abc", and the data filtering condition may be "expiration time is one day".
[0096] For example, when the electronic device starts application 01, it can execute application code 1 of application 01, determine the cache information code in application code 1, and based on the cache information code, determine that the target cache to be operated by application 01 is cache 01, and the target data information includes a target data identifier of "with a digital prefix of abc" and a data filtering condition of "expiration time is one day".
[0097] S202. Determine the target cache instance corresponding to the application.
[0098] The target cache instance is obtained by instantiating the general cache code. The target cache instance may include the cache type, port number, and / or cache address of the target cache, etc.
[0099] The cache type may include Redis cache, memcached cache, etc.
[0100] The general cache code may also be referred to as the general cache framework. The general cache code is a general code for operating multiple types of caches. By using the general cache code, the implementation differences of different applications operating different caches can be masked. By instantiating the general cache code, different types of caches can be adapted, making it transparent to the upper-layer applications.
[0101] For any application, the application may have a corresponding cache instance. The application can call the cache instance to operate the corresponding target cache.
[0102] In an optional embodiment, the target cache instance corresponding to the target application can be determined in the following manner: If there is a cache instance corresponding to the application in the preset storage space, then the cache instance corresponding to the application existing in the preset storage space is determined as the target cache instance; if there is no cache instance corresponding to the application in the preset storage space, then a target cache instance is generated.
[0103] A preset storage space may be provided in the electronic device.
[0104] Next, in combination with Figure 3 , the preset storage space will be described.
[0105] Figure 3 This is a schematic diagram of the preset storage space provided for the exemplary embodiment of the present application. Please refer to Figure 3, multiple cache instances can be stored in the preset storage space. The multiple cache instances can be cache instance 01, cache instance 02, ……, cache instance n.
[0106] Optionally, the electronic device can determine whether there is a cache instance corresponding to the application program according to the program information of the application program. Among them, the program information can include a program identifier or a program name, etc. For example, the program information of application program 01 can include the program identifier APP-001.
[0107] If there is a cache instance corresponding to the application program in the preset storage space, the cache instance can be determined as the target cache instance; if there is no cache instance corresponding to the application program in the preset storage space, a target cache instance corresponding to the application program can be generated.
[0108] For example, if the program information of application program 01 is APP-001, the electronic device can determine the cache instance corresponding to application program 01 in the preset storage space according to the program information APP-001. If there is cache instance 01 corresponding to application program 01 in the preset storage space, cache instance 01 can be determined as the target cache instance; if there is no cache instance corresponding to application program 01 in the preset storage space, a target cache instance corresponding to application program 01 can be generated.
[0109] S203. Operate and process the target data in the target cache through the target cache instance.
[0110] In an alternative embodiment, the target data in the target cache can be operated and processed through the target cache instance in the following manner: determine the cache operation code corresponding to the cache information code in the application code; call the target cache instance according to the cache operation code to operate and process the target data in the target cache.
[0111] The cache operation code can include the operation code for operating on the target data in the target cache, that is, the cache operation code can be the code for writing an operation function.
[0112] The cache operation code can be located after the cache information code. For example, in the application code, the 5th and 6th lines of code can be the cache information code, and the 7th to 20th lines of code can be the cache operation code.
[0113] The target data refers to the data determined according to the target data information in the target cache.
[0114] For example, if the target cache to be operated by application 01 is cache 01, the target data information includes that the target data identifier is "with a digital prefix of abc" and the data screening condition is "expiration time is one day", and the target cache instance is cache instance 01, the electronic device can determine the cache operation code corresponding to the cache information code in the application code 1 of application 01, and call cache instance 01 according to the cache operation code to operate on 100 target data in cache 01 that have a digital prefix of abc and an expiration time of one day according to the target data information, so as to perform operation processing on the 100 target data.
[0115] In the embodiment of the present application, the electronic device can determine the cache information code in the application code of the application, and determine the target cache to be operated by the application and the target data information of the target data to be operated according to the cache information code; determine the target cache instance corresponding to the application, and the target cache instance is obtained by instantiating the general cache code; and perform operation processing on the target data in the target cache through the target cache instance. Since for different applications, different cache instances corresponding to different applications can be obtained by instantiating the general cache code. The application can call the corresponding cache instance to operate on the corresponding target cache. Compared with the prior art, there is no need to write cache codes for operating different types of caches for each application, so the development efficiency of the application is improved.
[0116] Next, on the basis of the Figure 2 shown embodiment, combined with Figure 4 , the above cache operation method will be described in detail.
[0117] Figure 4 This is a flowchart of a cache operation method provided by an exemplary embodiment of the present application. Please refer to Figure 4 , the method may include:
[0118] S401. Determine the cache information code in the application code of the application.
[0119] The cache information code may include an identification line code and a screening line code.
[0120] Optionally, the identification line code may be a Cacheable annotation code; the form of the identification line code may be @Cacheable(value = target cache identifier, key = target data identifier).
[0121] For example, the identification line code may be as follows:
[0122] @Cacheable(value = Cache_1, key = abc_123456), where the target cache identifier is Cache_1, the target data identifier is abc_123456, and the data prefix of the target data is "abc".
[0123] Optionally, the filtering line code can be the CacheExtend annotation code. The form of the filtering line code can be @CacheExtend(data filtering condition). Among them, the data filtering condition can be the expiration time or version number, etc.
[0124] For example, the filtering line code can be as follows:
[0125] @CacheExtend(expiredTime = 24 * 60 * 60), indicating that the data filtering condition is that the expiration time is one day (i.e., 86400 seconds).
[0126] In an optional embodiment, the cache information code can be determined in the application code of the application in the following manner: during the execution of the application code of the application, if there is a preset flag bit in the target line code of the application code, the target line code is determined as the cache information code.
[0127] Optionally, the preset flag bit can include "@Cacheable" and "@CacheExtend".
[0128] For example, if the preset flag bits are "@Cacheable" and "@CacheExtend", if the electronic device determines that there is @CacheExtend in the target line code 01 during the execution of the application code of the application, and if there is the preset flag bit @Cacheable in the target line code 02, the target line code 01 and the target line code 02 can be determined as the cache information code. Among them, the target line code 01 can be the filtering line code, and the target line code 02 can be determined as the identification line code.
[0129] It should be noted that the order of the identification line code and the filtering line code is not limited.
[0130] S402. Parse and process the identification line code to obtain the target cache identifier and the target data identifier.
[0131] For example, if the identification line code is as shown in the above example, the identification line code can be parsed and processed to obtain the target cache identifier as Cache_1 and the target data identifier with the data prefix of "abc".
[0132] S403. Parse and process the filtering line code to obtain the data filtering condition.
[0133] For example, if the filtering line code is as shown in the above example, the filtering line code can be parsed to obtain the data filtering condition: the expiration time is one day.
[0134] S404. Determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition.
[0135] Optionally, the electronic device can determine the cache corresponding to the target cache identifier as the target cache among multiple caches according to the target cache identifier. For example, if the target cache identifier is Cache_1, the cache 01 corresponding to Cache_1 can be determined as the target cache among multiple caches.
[0136] For example, if the target data identifier has a data prefix of "abc" and the data filtering condition is that the expiration time is one day, it can be determined that the target data information 01 includes having a data prefix of "abc" and an expiration time of one day.
[0137] S405. Determine whether there is a cache instance corresponding to the application program in the preset storage space.
[0138] Optionally, the electronic device can determine whether there is a cache instance corresponding to the application program in the preset storage space according to the program information of the application program. If so, step S406 can be executed; if not, step S407 can be executed.
[0139] For example, if the program information of application program 01 is APP-001, the electronic device can determine whether there is a cache instance corresponding to application program 01 in the preset storage space according to this program information APP-001. If so, step S406 can be executed; if not, step S407 can be executed.
[0140] S406. Determine the cache instance corresponding to the application program existing in the preset storage space as the target cache instance.
[0141] For example, if the cache instance 01 is stored in the preset storage space and the cache instance 01 is the cache instance corresponding to the application program 01, the cache instance 01 can be determined as the target cache instance.
[0142] S407. Generate a target cache instance.
[0143] Since there is no target cache instance corresponding to the application program in the preset storage space, the general cache code can be instantiated to generate a target cache instance.
[0144] In an optional embodiment, a target cache instance can be generated in the following manner: In the configuration file corresponding to the application, determine the cache configuration information of the target cache corresponding to the application; determine the program information of the application; and perform instantiation processing on the general cache code according to the cache configuration information and the program information to obtain the target cache instance.
[0145] For any application, the application can have a corresponding configuration file.
[0146] Optionally, the configuration file corresponding to the application can be obtained, and information such as the cache identifier, cache type, port number, and cache address of the target cache can be obtained in the configuration file, so it can be determined that the cache configuration information includes information such as the cache identifier, cache type, port number, and cache address.
[0147] For example, in the configuration file 1 corresponding to application 01, the cache identifier of the target cache is obtained as cache-1, the cache type is Redis cache, the port number is 0101, and the cache address is address 1, so it can be determined that the cache configuration information 1 corresponding to application 01 for the target cache can include: the cache identifier is cache-1, the cache type is Redis cache, the port number is 0101, and the cache address is address 1.
[0148] Optionally, the electronic device can also determine the program information corresponding to the application. The program information can include the program identifier or program name, etc. For example, the program information 1 of application 01 can include the program identifier APP-001.
[0149] After the electronic device determines the cache configuration information of the target cache corresponding to the application and the program information of the application, it can perform instantiation processing on the general cache code according to the cache configuration information and the program information to obtain the target cache instance corresponding to the application.
[0150] Optionally, the general cache code can be instantiated in the following manner to obtain the target cache instance corresponding to the application: The electronic device can update the cache identifier in the general cache code to the cache identifier of the target cache, update the cache type to the cache type of the target cache, update the port number to the port number of the target cache, update the cache address to the cache address of the target cache, etc.; the electronic device can also update the program identifier in the general cache code to the program identifier corresponding to the application, etc.
[0151] For example, if the cache configuration information 1 may include: the cache type is Redis cache, the port number is 0101, and the cache address is Address 1, and the program information 1 of application 01 includes the program identifier APP-001, then the general cache code can be instantiated according to the cache configuration information 1 and the program information 1 to generate the target cache instance corresponding to application 01, that is, cache instance 01. The cache type in cache instance 01 is Redis cache, the port number is 0101, the cache address is Address 1, and the program identifier is APP-001.
[0152] In the technical solution of this application, the general cache code can be instantiated, and the target cache instance corresponding to the application can be obtained without writing additional adaptation code, so as to operate different types of caches, improving the development efficiency of the application.
[0153] S408. Determine the cache operation code corresponding to the cache information code in the application code.
[0154] The cache operation code is located after the cache information code. After the cache information code, there is the cache operation code corresponding to the cache information code.
[0155] Next, in combination with Figure 5 , the cache operation code will be described.
[0156] Figure 5 It is a schematic diagram of the cache operation code provided for the exemplary embodiment of this application. Please refer to Figure 5 , for example, if the 5th line of code is the identification line code and the 6th line of code is the filtering line code, then the cache information code includes the 5th line of code and the 6th line of code. Then, after the cache information code, the cache operation code can be determined. Assume that the cache operation code corresponding to the cache information code may include the 7th line of code to the 20th line of code.
[0157] S409. According to the cache operation code, call the target cache instance to perform operation processing on the target data in the target cache.
[0158] The operation processing can be used to request to query, update, or delete the target data in the target cache.
[0159] In an optional embodiment, the following method can be used to call the target cache instance according to the cache operation code to perform operation processing on the target data in the target cache: through the target cache instance, determine whether the target data exists in the target cache; if the target data exists in the target cache, then according to the cache operation code, call the target cache instance to perform operation processing on the target data in the target cache.
[0160] Optionally, if the target data does not exist in the target cache, the target data is obtained from the database according to the cache operation code, and the target data is stored in the target cache.
[0161] Optionally, for an electronic device, the electronic device may have a corresponding database.
[0162] For example, if the target cache is Cache 01, and the target data information 01 includes a data prefix of "abc" and an expiration time of one day. If the target cache instance is Cache Instance 01, then through Cache Instance 01, it can be determined whether there is at least one target data corresponding to the target data information 01 in Cache 01; if there is at least one target data corresponding to the target data information 01 in the target cache, then according to the cache operation code, Cache Instance 01 can be called, and at least one target data in Cache 01 can be queried, updated, or deleted; if there is no target data in the target cache, then according to the cache operation code, at least one target data corresponding to the target data information 01 can be obtained from the database, and the at least one target data can be stored in Cache 01.
[0163] Optionally, the operation processing of the target data in the target cache may include at least one of the following: querying the target data in the target cache; updating the target data in the target cache; writing the target data in the target cache; deleting the target data in the target cache.
[0164] For example, if the target cache is Cache 01, the operation processing may include at least one of the following: querying the target data in Cache 01 through Cache Instance 01, updating the target data in Cache 01 through Cache Instance 01, writing the target data in Cache 01 through Cache Instance 01, or deleting the target data in Cache 01 through Cache Instance 01.
[0165] In the technical solution of this application, a general cache code can be abstracted, shielding the implementation differences of operating different types of caches, providing a standard interface and annotation method, and the general cache code can be encapsulated into a module. The application can depend on this module, instantiate this module according to the cache configuration information and program information to automatically configure the cache instance, without writing additional adaptation code. By marking the CacheExtend annotation and Cacheable annotation on the method that needs to use the cache, the adaptation of different cache types can be completed, making the upper-layer application unaware.
[0166] In an embodiment of the present application, an electronic device may determine cache information code in the application code of an application program, parse and process the identification line code in the cache information code to obtain a target cache identifier, a target data identifier, and parse and process the filtering line code in the cache information code to obtain a data filtering condition. The electronic device may determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition. The electronic device may determine whether there is a cache instance corresponding to the application program in the preset storage space. If so, the cache instance corresponding to the application program existing in the preset storage space may be determined as the target cache instance; if not, a target cache instance may be generated. The electronic device may determine cache operation code corresponding to the cache information code in the application code, and call the target cache instance according to the cache operation code to perform operation processing on the target data in the target cache. Since for different application programs, different cache instances corresponding to different application programs can be obtained by instantiating the general cache code. The application program may call the corresponding cache instance to operate the corresponding target cache. Compared with the prior art, there is no need to write cache code for operating different types of caches for each application program, so the development efficiency of the application program is improved.
[0167] Next, on the basis of any of the above embodiments, in combination with Figure 6 , through specific examples, the above cache operation method will be further described.
[0168] Figure 6 It is a schematic diagram of the process of a cache operation method provided by an exemplary embodiment of the present application. Please refer to Figure 6 , which includes steps ①②③④⑤⑥⑦⑧. Among them, steps ①② belong to process 1 of initializing and generating a cache instance, and steps ③④⑤⑥⑦⑧ belong to process 2 of calling the cache instance when starting the application program.
[0169] Application 01 corresponds to application code, and executing the application code can start and run Application 01.
[0170] In process 1 of initializing and generating a cache instance, in step ①, the application code of Application 01 may be executed to obtain the configuration file and program information of Application 01.
[0171] In the configuration file, it may be obtained that the cache identifier of the target cache corresponding to Application 01 is cache-1, Redis cache, the port number is 0101, and the cache address is Address 1, etc. Then, it may be determined that the cache configuration information of the target cache corresponding to Application 01 may include: the cache identifier is cache-1, the cache type is Redis cache, the port number is 0101, and the cache address is Address 1.
[0172] The program information corresponding to Application 01 may include the program identifier APP-001.
[0173] In step ②, the electronic device may determine a general cache code and instantiate the general cache code according to the cache configuration information and the program information to obtain the cache instance 01 corresponding to Application 01.
[0174] Optionally, the cache instance 01 may be saved in a preset storage space.
[0175] In the process 2 of calling the cache instance when starting the application, in step ③, the application code of Application 01 may be executed to enter the cache enhancement aspect. In the cache enhancement aspect, the cache information code may be determined, that is, the cache information code is determined in the application code. The cache information code may include an identification line code and a filtering line code. The identification line code may be a Cacheable annotation code. The identification line code may be parsed to obtain a target cache identifier and a target data identifier. For example, the target cache identifier may be Cache_1, and the target data identifier may be with a data prefix of "abc".
[0176] In step ④, the filtering line code may be parsed to obtain a data filtering condition. For example, the data filtering condition may be: the expiration time is one day.
[0177] In step ⑤, the target data information may be determined according to the target data identifier and the data filtering condition. For example, if the target data identifier is with a data prefix of "abc" and the data filtering condition is that the expiration time is one day, then it may be determined that the target data information includes a data prefix of "abc" and an expiration time of one day.
[0178] In step ⑥, the cache corresponding to the target cache identifier may be determined as the target cache. For example, if the target cache identifier is Cache_1, then the cache 01 corresponding to Cache_1 may be determined as the target cache.
[0179] Since in process 1, the cache instance 01 corresponding to Application 01 has been generated and the cache instance 01 has been stored in the preset storage space, in step ⑦, the electronic device may determine the cache instance 01 corresponding to Application 01 in the preset storage space according to the program information of Application 01. The electronic device may determine the cache operation code in the application code and, through the cache operation code, call the cache instance 01 to operate on the target data in the cache 01.
[0180] If the target data information includes a data prefix of "abc" and an expiration time of one day, cache instance 01 can be called to determine whether there is target data in cache 01 with a data prefix of "abc" and an expiration of one day. If cache 01 exists, the target data can be processed; if it does not exist in cache 01, the target data can be obtained from the database corresponding to the electronic device and stored in cache 01.
[0181] Optionally, the operation processing may include querying the target data in cache 01 through cache instance 01, updating the target data in cache 01 through cache instance 01, writing the target data in cache 01 through cache instance 01, or deleting the target data in cache 01 through cache instance 01.
[0182] In the embodiments of the present application, the electronic device can execute the application code of the application, obtain the configuration file and program information of the application, and perform instantiation processing on the general cache code according to the configuration file and program information to obtain the target cache instance corresponding to the application, so as to initialize and generate the target cache instance of the application; during the process of calling the target cache instance when starting the application, the electronic device can execute the application code and determine the cache information code in the application code. The electronic device can parse the identification line code in the cache information code to obtain the target cache identification and the target data identification, and can parse the filtering line code in the cache information code to obtain the data filtering condition. The electronic device can determine the cache corresponding to the target cache identification as the target cache, and determine that the target data information includes the target data identification and the data filtering condition. The electronic device can determine the cache instance corresponding to the application in the preset storage space, and determine the cache instance corresponding to the application in the preset storage space as the target cache instance. The electronic device can determine the cache operation code corresponding to the cache information code in the application code, and according to the cache operation code, call the target cache instance to perform operation processing on the target data in the target cache. Since for different applications, different cache instances corresponding to different applications can be obtained by instantiating the general cache code. The application can call the corresponding cache instance to operate the corresponding target cache. Compared with the prior art, there is no need to write cache codes for operating different types of caches for each application, so the development efficiency of the application is improved.
[0183] Figure 7 The structure diagram of a cache operation device is provided for the exemplary embodiments of the present application. Please refer to Figure 7 The cache operation device 10 may include: a first determination module 11, a second determination module 12, and a processing module 13, where
[0184] The first determination module 11 is configured to determine cache information code in the application code of the application program, and determine a target cache to be operated by the application program and target data information of target data to be operated according to the cache information code;
[0185] The second determination module 12 is configured to determine a target cache instance corresponding to the application program, where the target cache instance is obtained by instantiating general cache code, and the general cache code is general code for operating multiple types of caches;
[0186] The processing module 13 is configured to perform operation processing on the target data in the target cache through the target cache instance.
[0187] The cache operation device provided by the embodiment of the present application can execute the technical solutions shown in the above method embodiments, and its implementation principle and beneficial effects are similar, and will not be described in detail here.
[0188] In a possible implementation manner, the second determination module 12 is specifically configured to:
[0189] If there is a cache instance corresponding to the application program in the preset storage space, determine the cache instance corresponding to the application program existing in the preset storage space as the target cache instance; or,
[0190] If there is no cache instance corresponding to the application program in the preset storage space, generate the target cache instance.
[0191] In a possible implementation manner, the second determination module 12 is specifically configured to:
[0192] In the configuration file corresponding to the application program, determine cache configuration information of the target cache corresponding to the application program;
[0193] Determine program information of the application program;
[0194] According to the cache configuration information and the program information, perform instantiation processing on the general cache code to obtain the target cache instance.
[0195] In a possible implementation manner, the first determination module 11 is specifically configured to:
[0196] During the execution of the application code of the application program, if there is a preset flag bit in the target line code of the application code, determine the target line code as the cache information code.
[0197] In a possible implementation manner, the cache information code includes an identification line code and a screening line code; the first determination module 11 is specifically configured to:
[0198] Parse the identification line code to obtain a target cache identifier and a target data identifier;
[0199] Parse the filtering line code to obtain a data filtering condition;
[0200] Determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition.
[0201] In a possible implementation manner, the processing module 13 is specifically configured to:
[0202] Determine a cache operation code corresponding to the cache information code in the application code, where the cache operation code includes an operation code for operating on the target data in the target cache;
[0203] According to the cache operation code, call the target cache instance to perform an operation process on the target data in the target cache.
[0204] In a possible implementation manner, the operation process is used to request to perform at least one of the following operations on the target data in the target cache: query, update, or delete; the processing module 13 is specifically configured to:
[0205] Determine whether the target data exists in the target cache through the target cache instance;
[0206] If the target data exists in the target cache, call the target cache instance according to the cache operation code to perform an operation process on the target data in the target cache.
[0207] In a possible implementation manner, the processing module is further configured to:
[0208] If the target data does not exist in the target cache, obtain the target data from the database according to the cache operation code and store the target data in the target cache.
[0209] In a possible implementation manner, performing an operation process on the target data in the target cache includes at least one of the following:
[0210] Query the target data in the target cache;
[0211] Update the target data in the target cache;
[0212] Write the target data in the target cache;
[0213] Delete the target data in the target cache.
[0214] The cache operation device provided by the embodiments of the present application can execute the technical solutions shown in the above method embodiments. The implementation principles and beneficial effects are similar and will not be elaborated here.
[0215] An exemplary embodiment of the present application provides a schematic structural diagram of an electronic device. Please refer to Figure 8 , the electronic device 20 may include a processor 21 and a memory 22. Exemplarily, the processor 21 and the memory 22 are interconnected with each other through a bus 23.
[0216] The memory 22 stores computer execution instructions;
[0217] The processor 21 executes the computer execution instructions stored in the memory 22, so that the processor 21 executes the method shown in the above method embodiments.
[0218] Optionally, a data security center may be provided in the electronic device. The data security center may be a product for classifying, grading, and analyzing a large amount of data and logs. A large amount of cache technology will be applied in each system of the product. There are multiple deployment environments for the data security center, such as test environments, production environments, private cloud environments, etc. Different types of caches are used in different deployment environments. The electronic device can, through the technical solution of the present application, enable the data security center to adapt to the caches in each deployment environment.
[0219] Correspondingly, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored, and when the computer execution instructions are executed by a processor, they are used to implement the method described in the above method embodiments.
[0220] Correspondingly, an embodiment of the present application may further provide a computer program product, including a computer program, which when executed by a processor, can implement the method shown in the above method embodiments.
[0221] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.
[0222] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and combinations of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device generate means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0223] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory produce a manufacture including instruction means that implement the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0224] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are performed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0225] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0226] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.
[0227] A computer-readable medium includes both permanent and non-permanent, removable and non-removable media and can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media, such as modulated data signals and carrier waves.
[0228] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or apparatus comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or apparatus. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising the element.
[0229] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A caching operation method, characterized in that, Including: Determine cache information code in the application code of the application program, and determine the target cache to be operated by the application program and the target data information of the target data to be operated according to the cache information code; Determine the target cache instance corresponding to the application program, where the target cache instance is obtained by instantiating the general cache code, and the general cache code is the general code for operating multiple types of caches; Operate and process the target data in the target cache through the target cache instance.
2. The method according to claim 1, wherein Determining the target cache instance corresponding to the target application program includes: If there is a cache instance corresponding to the application program in the preset storage space, determine the cache instance corresponding to the application program existing in the preset storage space as the target cache instance; or, If there is no cache instance corresponding to the application program in the preset storage space, generate the target cache instance.
3. The method according to claim 2, wherein Generating the target cache instance includes: Determine the cache configuration information of the target cache corresponding to the application program in the configuration file corresponding to the application program; Determine the program information of the application program; Perform instantiation processing on the general cache code according to the cache configuration information and the program information to obtain the target cache instance.
4. The method according to any one of claims 1 to 3, characterized in that, Determining cache information code in the application code of the application program includes: During the execution of the application code of the application program, if there is a preset flag bit in the target line code of the application code, determine the target line code as the cache information code.
5. The method according to any one of claims 1 to 4, characterized in that The cache information code includes an identification line code and a filtering line code; determining the target cache to be operated by the application program and the target data information according to the cache information code includes: Perform parsing processing on the identification line code to obtain a target cache identifier and a target data identifier; Perform parsing processing on the filtering line code to obtain a data filtering condition; Determine the cache corresponding to the target cache identifier as the target cache, and determine that the target data information includes the target data identifier and the data filtering condition.
6. The method according to any one of claims 1-5, characterized in that, Operating and processing the target data in the target cache through the target cache instance includes: Determine the cache operation code corresponding to the cache information code in the application code, where the cache operation code includes an operation code for operating the target data in the target cache; Call the target cache instance according to the cache operation code to operate and process the target data in the target cache.
7. The method according to claim 6, wherein The operation processing is used to request to perform at least one of the following operations on the target data in the target cache: query, update, delete; Calling the target cache instance according to the cache operation code to operate and process the target data in the target cache includes: Judge whether the target data exists in the target cache through the target cache instance; If the target data exists in the target cache, the target cache instance is called according to the cache operation code to perform operation processing on the target data in the target cache.
8. The method according to claim 7, wherein The method further includes: If the target data does not exist in the target cache, the target data is obtained from the database according to the cache operation code, and the target data is stored in the target cache.
9. The method according to any one of claims 1-8, characterized in that, Performing operation processing on the target data in the target cache includes at least one of the following: Querying the target data in the target cache; Updating the target data in the target cache; Writing the target data in the target cache; Deleting the target data in the target cache.
10. A cache operation device, characterized in that, Includes: A first determination module, a second determination module, and a processing module, where The first determination module is configured to determine cache information code in the application code of the application program, and determine the target cache to be operated by the application program and the target data information of the target data to be operated according to the cache information code; The second determination module is configured to determine the target cache instance corresponding to the application program, the target cache instance is obtained by instantiating a general cache code, and the general cache code is a general code for operating multiple types of caches; The processing module is configured to perform operation processing on the target data in the target cache through the target cache instance.
11. An electronic device, characterized in that, Includes: At least one processor; And A memory communicatively connected to the at least one processor; Wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the electronic device to execute the method according to any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, Computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the method according to any one of claims 1-9 is implemented.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, the method according to any one of claims 1-9 is implemented.