Business data caching method and device, computer equipment, readable storage medium and program product
By identifying business scenario types and conducting performance tests on candidate caching modes, the most suitable caching mode is selected for processing, which solves the problem of insufficient flexibility of existing caching technologies and improves the flexibility and performance of the system.
Patent Information
- Application Number
- CN202511217400.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-28
- Publication Date
- 2025-11-14
AI Technical Summary
Existing caching technologies cannot be adapted to different business needs, resulting in low flexibility and inefficiency, especially in high-concurrency environments. Furthermore, existing caching mechanisms involve unnecessary garbage collection and cleanup operations when dealing with expired cached items, which affects system performance.
By identifying the scenario types of business data, constructing test data and setting performance test parameters, conducting performance tests using multiple candidate caching modes, and selecting the optimal caching mode for caching processing, including adjusting locking mechanisms, tolerance, and cache timing units to adapt to different business needs.
It improves the flexibility and system performance of business data caching, adapts to changes in different business scenarios, reduces lock contention and unnecessary cache cleanup operations, and improves the overall efficiency of the system.
Smart Images

Figure CN120950552A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer software technology, and in particular to a business data caching method, apparatus, computer equipment, readable storage medium, and program product. Background Technology
[0002] In business systems, performance issues are most likely to arise when responding to data queries. This is because the volume of data handled in these queries is large and the filtering conditions are complex. Therefore, introducing caching into the business system architecture to cache frequently accessed data can achieve the goal of fast response. Caching technologies in related fields are often designed for specific scenarios. However, faced with diverse and complex business needs, these caching technologies cannot adapt to different business requirements, thus exhibiting a lack of flexibility. Summary of the Invention
[0003] Therefore, it is necessary to provide a business data caching method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve the flexibility of business data caching in response to the above-mentioned technical problems.
[0004] Firstly, this application provides a business data caching method, including:
[0005] Acquire business data and determine the business scenario type to which the business data belongs;
[0006] Based on the business data, construct corresponding test data, and determine the performance test parameters for the test data according to the business scenario type;
[0007] Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes;
[0008] Based on the performance test results of the at least two candidate caching modes, a target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode.
[0009] In conjunction with the first aspect, in one embodiment, the step of employing at least two pre-built candidate caching modes that match the business scenario type, and performing caching performance tests on the test data according to performance test parameters to obtain the performance test results of each of the at least two candidate caching modes, includes:
[0010] Identify at least two pre-built candidate caching patterns that match the business scenario type; the at least two candidate caching patterns are obtained by configuring the baseline caching pattern based on the business scenario type.
[0011] The cache performance of the test data is tested using the at least two candidate caching modes according to the performance test parameters, and the performance test results of the at least two candidate caching modes are obtained.
[0012] In conjunction with the first aspect, in one embodiment, determining at least two pre-built candidate caching patterns that match the business scenario type includes:
[0013] Determine at least one business caching requirement for the baseline caching mode and the business scenario type;
[0014] Based on the at least one business caching requirement, at least one cache control parameter of the baseline caching mode is configured to obtain at least two candidate caching modes that match the business scenario type.
[0015] In conjunction with the first aspect, in one embodiment, the cache control parameters include tolerance, cache timing unit and locking mechanism, and the business cache requirements include concurrency requirements, real-time requirements and consistency requirements;
[0016] The step involves configuring at least one cache control parameter of the baseline cache mode based on the at least one business cache requirement, to obtain at least two candidate cache modes that match the business scenario type, including:
[0017] Configure the locking mechanism according to the concurrency requirements, and determine the configured locking mechanism;
[0018] Configure the tolerance based on the concurrency requirements and the consistency requirements, and determine the configured tolerance;
[0019] Configure the cache timing unit according to the real-time requirements, and determine the configured cache timing unit;
[0020] Based on the configured locking mechanism, the configured tolerance, and the configured cache timing unit, at least two candidate cache modes that match the business scenario type are obtained.
[0021] In conjunction with the first aspect, in one embodiment, determining at least two pre-built candidate caching patterns that match the business scenario type includes:
[0022] Determine the pre-built cache pattern mapping relationship; the cache pattern mapping relationship includes candidate cache patterns corresponding to different business scenario types;
[0023] Based on the cache pattern mapping relationship, at least two candidate cache patterns that match the business scenario type are determined.
[0024] In conjunction with the first aspect, in one embodiment, the caching process for the business data using the target caching mode includes:
[0025] Determine the target operation for the business data;
[0026] Based on the target operation, the target control parameters are determined from the cache control parameters of the target cache mode;
[0027] The target operation is performed on the business data according to the target control parameters to perform caching processing on the business data.
[0028] In conjunction with the first aspect, in one embodiment, determining the target control parameters from the cache control parameters of the target cache mode according to the target operation includes at least one of the following:
[0029] If the target operation is a first cache operation, a locking mechanism is determined from the cache control parameters of the target cache mode. The first cache operation includes at least one of a write operation, an update operation, a computation operation, and a merge operation.
[0030] If the target operation is a second cache operation, the tolerance and cache timing unit are determined from the cache control parameters of the target cache mode, and the second cache operation includes a cache release operation.
[0031] In conjunction with the first aspect, in one embodiment, the performance test parameters include thread configuration information; the step of constructing corresponding test data based on the business data and determining performance test parameters for the test data according to the business scenario type includes:
[0032] Based on the attribute information of the business data, generate multiple key-value pairs, and construct test data based on the multiple key-value pairs;
[0033] The process involves employing at least two pre-built candidate caching modes that match the business scenario type, performing caching performance tests on the test data according to performance test parameters, and obtaining the performance test results for each of the at least two candidate caching modes, including:
[0034] Identify at least two threads that match the thread configuration information;
[0035] At least two pre-built candidate caching modes that match the business scenario type are used, and the caching performance is tested on the test data by the at least two threads to obtain the performance test results of each of the at least two candidate caching modes.
[0036] Secondly, this application also provides a business data caching device, comprising:
[0037] The data acquisition module is used to acquire business data and determine the business scenario type to which the business data belongs;
[0038] The parameter determination module is used to construct corresponding test data based on the business data and determine performance test parameters for the test data according to the business scenario type.
[0039] The performance testing module is used to perform cache performance testing on the test data according to the performance testing parameters using at least two pre-built candidate caching modes that match the business scenario type, and to obtain the performance test results of each of the at least two candidate caching modes.
[0040] The mode determination module is used to determine the target cache mode from the at least two candidate cache modes based on the performance test results of each of the at least two candidate cache modes, and to perform cache processing on the business data using the target cache mode.
[0041] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0042] Acquire business data and determine the business scenario type to which the business data belongs;
[0043] Based on the business data, construct corresponding test data, and determine the performance test parameters for the test data according to the business scenario type;
[0044] Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes;
[0045] Based on the performance test results of the at least two candidate caching modes, a target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode.
[0046] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0047] Acquire business data and determine the business scenario type to which the business data belongs;
[0048] Based on the business data, construct corresponding test data, and determine the performance test parameters for the test data according to the business scenario type;
[0049] Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes;
[0050] Based on the performance test results of the at least two candidate caching modes, a target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode.
[0051] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0052] Acquire business data and determine the business scenario type to which the business data belongs;
[0053] Based on the business data, construct corresponding test data, and determine the performance test parameters for the test data according to the business scenario type;
[0054] Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes;
[0055] Based on the performance test results of the at least two candidate caching modes, a target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode.
[0056] The aforementioned business data caching method, apparatus, computer equipment, computer-readable storage medium, and computer program product acquire business data and determine the business scenario type to which the business data belongs, providing a basis for subsequent performance test parameters and caching mode selection; construct corresponding test data based on the business data, and determine performance test parameters for the test data according to the business scenario type, laying the groundwork for accurately simulating business under the business scenario type in subsequent tests; further, employ at least two pre-constructed candidate caching modes that match the business scenario type, and conduct caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes, which can accurately evaluate the performance of different candidate caching modes, thus providing a basis for selecting the target caching mode; based on the performance test results of each of the at least two candidate caching modes, determine the target caching mode from the at least two candidate caching modes, and perform caching processing on the business data using the target caching mode; select the target caching mode that is suitable for the current business scenario type based on the test results, and apply it to the business data. This not only adapts to changes in different business scenario types and selects an appropriate caching mode, thereby improving the flexibility of business data caching, but also improves system performance based on the application of the most suitable target caching mode. Attached Figure Description
[0057] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0058] Figure 1 This is a flowchart illustrating a business data caching method in one embodiment;
[0059] Figure 2 This is a flowchart illustrating the cache performance testing steps in one embodiment;
[0060] Figure 3 This is a flowchart illustrating the candidate pattern determination steps in one embodiment;
[0061] Figure 4 This is a flowchart illustrating a business data caching method in another embodiment;
[0062] Figure 5 This is a structural block diagram of a service data caching device in one embodiment;
[0063] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0064] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0065] As described in the background section, the business data caching methods of related technologies suffer from low flexibility. The inventors' research revealed that this problem stems from the low efficiency of cache updates and expiration handling in existing caching systems, especially in high-concurrency environments. Traditional cache implementations such as ConcurrentHashMap (a concurrent hash table implementation in the Java standard library, supporting read and write operations in high-concurrency environments) and Guava Cache (a Java caching library supporting cache expiration, refresh, and statistics) may lead to performance bottlenecks and unnecessary resource consumption when handling large amounts of data write and update operations. Furthermore, existing caching mechanisms typically use coarse-grained timestamp comparisons when handling cache item expiration times, which may result in unnecessary garbage collection or cache cleanup operations, thus impacting overall system performance. Moreover, existing caching solutions often lack sufficient flexibility to meet the needs of different application scenarios, making it difficult to effectively configure and adjust them according to actual business requirements. The above problems arise because, in high-concurrency environments, traditional caching implementations use a large number of locking mechanisms to ensure thread safety, leading to increased lock contention and synchronization overhead, which reduces the efficiency of cache updates. Existing cache expiration mechanisms usually rely on comparison of global timestamps, which can lead to frequent garbage collection and unnecessary cache cleanup operations when dealing with large-scale caches, increasing the system burden. Existing caching solutions are often designed for specific scenarios, lacking sufficient flexibility and configurability, and are difficult to meet diverse and complex business needs.
[0066] Based on the above reasons, this application provides a business data caching method. By identifying the business scenario type to which the business data belongs, generating test data under the business scenario type and setting performance test parameters, and then conducting performance tests using multiple candidate caching modes, the method obtains the performance test results of each candidate caching mode. Based on the performance test results, the optimal caching mode is selected to cache the business data. This method can select the most suitable target caching mode for different business scenario types, thereby improving the flexibility of business data caching.
[0067] In one exemplary embodiment, such as Figure 1As shown, a business data caching method is provided. This embodiment illustrates the application of this method to a terminal's business system. It is understood that this method can also be applied to a server, or to a system including both a terminal and a server, and is implemented through interaction between the terminal and the server. The terminal can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, etc. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. In this embodiment, the method includes the following steps S102 to S108. Wherein:
[0068] Step S102: Obtain business data and determine the business scenario type to which the business data belongs.
[0069] Business data can be raw data generated during actual business operations within the business system architecture, such as transaction records, user requests, and logs, which require caching optimization to improve performance. Business scenario types can be the application scenario category to which the business belongs, determined by characteristics such as business objectives, access patterns, and performance requirements. These can include categories such as: high-concurrency query scenarios (e.g., e-commerce product detail pages), low-frequency write / high-frequency read scenarios (e.g., news article caching), real-time computing scenarios (e.g., financial risk control data streams), and strong consistency scenarios (e.g., inventory deduction systems).
[0070] Optionally, the business system acquires business data generated by the current business in real time. It performs semantic analysis on the text fields contained in the business data to determine the business scenario type to which the business data belongs. Alternatively, it extracts index identifiers from the business data and queries a pre-built mapping relationship between business data and business scenario types based on these index identifiers to determine the business scenario type to which the business data belongs. It should be noted that, in addition to the methods described above for determining the business scenario type to which business data belongs, other data processing methods can also be used, as long as they achieve the effect of determining the business scenario type based on the business data; no specific limitations are imposed on these methods.
[0071] Step S104: Construct corresponding test data based on business data, and determine performance test parameters for the test data according to the business scenario type.
[0072] The test data can be a simulated dataset generated from business data for performance testing, and it must retain the inherent information of the original data. The performance test parameters can be test configuration standards set according to the type of business scenario.
[0073] Optionally, the business system constructs corresponding test data based on the inherent information of the business data, and determines performance test parameters that can simulate the operating environment of the business scenario corresponding to the business scenario type according to the business scenario type. These performance test parameters are used to perform performance tests on the test data.
[0074] Step S106: Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters, and obtain the performance test results of each of the at least two candidate caching modes.
[0075] Among them, the candidate caching mode can be a caching method designed in advance or in real time, which can be selected for different business scenario types and is used to manage the entire process of caching and processing of business data.
[0076] Cache performance testing can be a stress test performed on candidate caching patterns on test data to evaluate the system's performance during runtime. The performance test results can be quantified metrics output by each candidate caching pattern during the test, including operations per second (Ops / sec) and average latency, used to compare their performance.
[0077] Optionally, the business system employs at least two pre-built candidate caching modes that match the business scenario type. A test framework is built according to performance test parameters and benchmark tools. Within this framework, each candidate caching mode is used sequentially to perform caching performance tests on the test data, obtaining performance test results for each of the at least two candidate caching modes. The benchmark tool can be the JMH (Java Microbenchmark Harness) framework, a framework for Java micro-benchmarking that can accurately measure code performance. During caching performance testing, the benchmark tool can collect performance metrics of caching operations as performance test results.
[0078] Step S108: Based on the performance test results of at least two candidate caching modes, determine the target caching mode from the at least two candidate caching modes, and perform caching processing on the business data using the target caching mode.
[0079] The target caching pattern can be the optimal caching strategy selected based on performance test results, and is ultimately applied to the caching processing of actual business data.
[0080] Optionally, the business system compares the performance test results of at least two candidate caching modes to obtain the comparison results. Based on the comparison results, the candidate caching mode with the best performance test results among the at least two candidate caching modes is determined as the target caching mode, and the business data is cached using the target caching mode.
[0081] In the aforementioned business data caching method, the method acquires business data and determines the business scenario type to which the business data belongs, providing a basis for subsequent performance testing parameters and caching mode selection. Based on the business data, corresponding test data is constructed, and performance testing parameters for the test data are determined according to the business scenario type, laying the groundwork for accurately simulating the business under the business scenario type in subsequent tests. Furthermore, at least two pre-constructed candidate caching modes matching the business scenario type are used to perform caching performance tests on the test data according to the performance testing parameters, obtaining the performance test results for each of the at least two candidate caching modes. This allows for accurate evaluation of the performance of different candidate caching modes, thus providing a basis for selecting the target caching mode. Based on the performance test results of each of the at least two candidate caching modes, the target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode. Based on the test results, the target caching mode adapted to the current business scenario type is selected and applied to the business data. This not only adapts to changes in different business scenario types and selects an appropriate caching mode, thereby improving the flexibility of business data caching, but also improves system performance based on the application of the most suitable target caching mode.
[0082] In one exemplary embodiment, such as Figure 2 As shown, step S106 employs at least two pre-built candidate caching modes that match the business scenario type, and performs caching performance tests on the test data according to performance test parameters to obtain the performance test results for each of the at least two candidate caching modes, including steps S202 to S204. Wherein:
[0083] Step S202: Determine at least two pre-built candidate caching patterns that match the business scenario type.
[0084] Among them, at least two candidate caching modes are configured based on the business scenario type against the baseline caching mode; the baseline caching mode can be an open-source caching library that the system can directly call, such as Ehcache (a local distributed caching framework), Hazelcast (an in-memory distributed computing platform), Caffeine (a high-performance local caching library), Guava (a lightweight local cache), and ConcurrentHashMap (a thread-safe hash table), etc.
[0085] Optionally, the business system may determine at least two candidate cache patterns that match the business scenario type from multiple cache patterns pre-built based on different business scenario types and baseline cache patterns, or the business system may build at least two candidate cache patterns based on the current business scenario type and baseline cache pattern after determining the business scenario type to which the current business data belongs.
[0086] Step S204: Use at least two candidate caching modes to perform caching performance tests on the test data according to the performance test parameters, and obtain the performance test results of each of the at least two candidate caching modes.
[0087] Optionally, the business system calls the benchmark testing tool to build a test framework according to the performance test parameters, and sequentially uses at least two candidate caching modes to perform caching performance tests on the test data, and obtains multiple system performance indicators during the caching process, and obtains the performance test results of at least two candidate caching modes respectively.
[0088] In this embodiment, at least two candidate caching modes are prepared based on the type of business scenario and different baseline caching modes to obtain diversified caching modes, which further improves the adaptability and flexibility of caching business data. Performance testing methods are used to quantify the advantages and disadvantages of each candidate caching mode, providing a scientific basis for the selection of candidate caching modes.
[0089] In one exemplary embodiment, such as Figure 3 As shown, step S202 determines at least two pre-built candidate caching patterns that match the business scenario type, including steps S302 to S304. Wherein:
[0090] Step S302: Determine at least one business caching requirement for the baseline caching mode and the business scenario type.
[0091] Among them, business caching requirements can be functional or non-functional requirements of the business system's caching layer, determined by the type of business scenario, and directly affecting the choice of caching strategy.
[0092] Optionally, the business system determines at least one business caching requirement for the base caching mode for the business scenario type. For example, if the current business scenario type is financial transaction data display, then this business scenario type has a business caching requirement of high concurrency and high real-time for the base caching mode. Or, if the current business scenario type is managing payment balance, then this business scenario type has a business requirement of strong consistency for the base caching mode.
[0093] Step S304: Based on at least one business caching requirement, configure at least one cache control parameter of the baseline caching mode to obtain at least two candidate caching modes that strongly match the business scenario type.
[0094] Among them, the cache control parameters can be adjustable configuration items in the baseline cache mode, and these parameters can be modified to adapt to different business needs.
[0095] Optionally, the business system configures at least one cache control parameter related to the business cache requirement of the baseline cache mode according to at least one business cache requirement, so that the configured baseline cache mode can meet the business cache requirements of the business scenario and obtain at least two candidate cache modes that match the business scenario type; for example, if the business cache requirement is a high-concurrency requirement, then it is necessary to select a baseline cache mode that can support high-concurrency operations and configure the cache control parameters related to high concurrency in the baseline cache mode.
[0096] In this embodiment, the business scenario type and corresponding business caching requirements are clearly defined. By adjusting the control parameters, a variety of candidate solutions can be quickly generated, which facilitates subsequent performance evaluation and optimization. It takes into account both the functional requirements of the business and non-functional performance indicators, ensuring that the candidate caching methods meet the business requirements while also optimizing system performance.
[0097] In an exemplary embodiment, the cache control parameters include tolerance, cache timing unit, and locking mechanism; the business cache requirements include concurrency requirements, real-time requirements, and consistency requirements; step S304 configures at least one cache control parameter of the baseline cache mode according to at least one business cache requirement, to obtain at least two candidate cache modes that match the business scenario type, including:
[0098] Configure the locking mechanism according to concurrency requirements to determine the configured locking mechanism; configure the tolerance according to concurrency and consistency requirements to determine the configured tolerance; configure the cache timing unit according to real-time requirements to determine the configured cache timing unit; based on the configured locking mechanism, configured tolerance, and configured cache timing unit, obtain at least two candidate cache modes that match the business scenario type.
[0099] Among these, tolerance can be the degree of data inaccuracy or delay that the business can accept. It is a key parameter for balancing performance and consistency and can postpone unnecessary expiration checks in cache processing. For example, the product details page can allow delayed updates of cached data (such as tolerating 5 minutes of old data). The cache timing unit can be the timing unit precision of the timer in the cache mode. It is the precision unit of time-related parameters in cache operations and affects expiration checks, refresh frequency, etc. The locking mechanism can be a synchronization strategy to control concurrent access to cached data and avoid data races or dirty reads. It includes mechanisms such as optimistic locking, pessimistic locking, and lock-free structures.
[0100] Among them, concurrency requirements can be the business's requirements for parallel read and write capabilities, which are usually determined by the number of users or peak requests, such as high-concurrency read and high-concurrency write requirements; real-time requirements can be the business's sensitivity to data update latency, such as stock price display in business scenarios with strong real-time requirements; consistency requirements can be the business's strictness regarding the consistency between cache and data source, specifically including strong consistency (such as payment balance) and eventual consistency (such as social media likes).
[0101] Optionally, the business system configures the locking mechanism based on concurrency requirements, determining the configured locking mechanism. For example, for high concurrency requirements, the locking mechanism configuration may include using optimistic locking or a lock-free structure to reduce lock contention and synchronization overhead. The business system also configures tolerance based on concurrency and consistency requirements, determining the configured tolerance. Specifically, higher concurrency and consistency requirements necessitate setting a longer tolerance period, such as an 80% expiration time. Conversely, if concurrency requirements are not limited but consistency requirements are low, tolerance may not be required or may be set to a shorter duration. The tolerance for time periods; in addition, the business system configures the cache timing unit according to real-time requirements, and determines the configured cache timing unit. Specifically, configuring the cache timing unit is actually selecting timers with different timing unit precisions. The higher the real-time requirement, the higher the precision timer is used, while the default timer can be used if the real-time requirement is not high. Furthermore, the business system adjusts the corresponding adjustment items in at least one baseline cache mode based on the configured locking mechanism, the configured tolerance, and the configured cache timing unit to obtain at least two candidate cache modes that match the business scenario type.
[0102] In this embodiment, selecting an appropriate locking mechanism based on the concurrency requirements of the business scenario type can reduce lock contention and improve throughput. The higher the concurrency requirements of the business scenario type, the tolerance can be appropriately relaxed to reduce system pressure. Conversely, the higher the consistency requirements, the shorter the tolerance time should be set to ensure data synchronization frequency. Furthermore, flexibly selecting different precision cache timing units based on real-time requirements further improves the flexibility of business data caching to meet the needs of different business scenario types.
[0103] In an exemplary embodiment, step S202 determines at least two pre-built candidate caching patterns that match the business scenario type, including:
[0104] Determine the pre-built cache pattern mapping relationship; based on the cache pattern mapping relationship, determine at least two candidate cache patterns that match the business scenario type.
[0105] The cache mode mapping relationship can refer to a predefined set of rules or a configuration table, which is used to clarify the correspondence between different business scenario types and applicable candidate cache modes. Its core purpose is to quickly lock in possible optimization strategies through scenario-based matching and avoid repeated experimental tuning. The cache mode mapping relationship includes candidate cache modes corresponding to different business scenario types.
[0106] Optionally, the business system determines different business scenario types based on historically processed business data, further identifies the business caching requirements for each scenario type, and adjusts the cache control parameters for at least two baseline caching modes. This results in multiple candidate caching modes associated with each business scenario, and a caching mode mapping relationship is constructed based on the relationships between these candidate modes. This mapping can be built by setting indexes to generate a mapping table. The business system obtains the pre-constructed caching mode mapping relationship, queries the mapping relationship using the current business scenario type, and determines at least two candidate caching modes that match the business scenario type. It is understood that the method for constructing candidate caching modes in this embodiment is consistent with the method described in the previous embodiments.
[0107] Specifically, the candidate cache patterns are constructed by using "Caffeine.newBuilder()" or "CacheBuilder.newBuilder()" (two methods in the Caffeine cache library used to create a configured cache builder) to create a cache builder, setting the initial capacity, expiration policy (tolerance and expiration time), and a custom time counter (cache timing unit). For one of the baseline cache patterns, Caffeine, the default time counter is replaced by calling FakeTicker (a simulated time timer) to precisely control the elapsed time in the test environment. For another baseline cache pattern, Guava, FakeTicker is also used to simulate the elapsed time. Furthermore, to address different real-time and consistency requirements, the tolerance and custom timer of Caffeine are further differentiated. Caffeine with write tolerance, a longer expiration time, and the default timer is constructed, as well as Caffeine without write tolerance, a shorter expiration time, and the simulated time timer, are built to handle strong consistency business scenarios and high real-time business scenarios respectively, resulting in three candidate cache patterns. Understandably, write tolerance can reduce unnecessary expiration checks. Specifically, Caffeine postpones expiration checks for a period before the actual expiration time of a cached item (within the write tolerance range), thereby reducing unnecessary garbage collection and cache cleanup operations. Using a custom time counter like FakeTicker allows for precise control over time elapsed in the test environment, facilitating performance and benchmark testing. FakeTicker allows for simulating rapid time elapsed in the test environment, accelerating the expiration handling testing process. It's worth noting that for strongly consistent business scenarios, other cache consistency protocols can also be used to ensure cached data consistency, replacing optimistic locking mechanisms.
[0108] In this embodiment, by pre-constructing candidate cache patterns under different business scenario types and further constructing a cache pattern mapping relationship between business scenario types and cache patterns, it is convenient to directly query the mapping relationship to obtain the constructed candidate cache patterns when filtering matching candidate cache patterns for real-time business scenario types, thereby improving the efficiency of selecting the appropriate target cache pattern.
[0109] In an exemplary embodiment, step S108, which involves caching business data according to a target caching pattern, includes:
[0110] Determine the target operation for the business data; based on the target operation, determine the target control parameters from the cache control parameters of the target cache mode; execute the target operation for the business data according to the target control parameters to cache the business data.
[0111] The target operation can be any operation involved in the current moment of the cache processing flow.
[0112] The target control parameters can be the mechanism or method used in the cache control parameters when performing the target operation.
[0113] Optionally, the business system determines the target operation that needs to be executed in the business data caching process at the current moment, and further determines the target control parameters that need to be used corresponding to the target operation from the cache control parameters of the target caching mode, and executes the target operation on the business data according to the configuration of the target control parameters to cache the business data.
[0114] In this embodiment, the current target operation for business data is determined, and control parameters are filtered according to the operation type of the target operation to ensure that the caching mechanism meets the actual caching requirements. In actual execution, the target operation is executed according to the target control parameters, which enhances the scenario optimization capability of the caching system, reduces the cost of debugging and tuning, and further improves the flexibility and performance adaptability of the cache.
[0115] In an exemplary embodiment, the steps in the above embodiments, determining the target control parameters from the cache control parameters of the target cache mode based on the target operation, include at least one of the following:
[0116] If the target operation is a first cache operation, the locking mechanism is determined from the cache control parameters of the target cache mode;
[0117] If the target operation is a second cache operation, the tolerance and cache timing unit are determined from the cache control parameters of the target cache mode.
[0118] The first cache operation includes at least one of write, update, computation, and merge operations; the second cache operation includes cache release. The write operation can be an operation that writes new key-value pairs of business data to the cache using the `put` method. In a high-concurrency environment, multiple threads may simultaneously attempt to write data to the cache. The update operation includes cache update operations and conditional update operations. A cache update operation can be an operation that updates existing key-value pairs in the cache using the `replace` method. This method checks if the key exists in the cache before updating, and only performs the update operation if the key exists. A conditional update operation can be an operation that updates a cache item when a specific condition is met using the `replaceConditionally` method. This method allows specifying a conditional predicate before updating, and only performs the update operation when the condition is met, or using a callback mechanism to implement the conditional update operation, ensuring that the update operation is triggered when a specific condition is met. The computation operation includes computation operations and conditional computation operations. A computation operation can be an operation that computes and stores a new value in the cache using the `compute` method. This method allows inserting a new value when the key does not exist in the cache, or... Cache operations can be implemented in several ways: updating the existing value when the key exists, or using functional programming languages to simplify complex calculations by leveraging their built-in functional features; conditional computation operations can be performed using the `computeIfPresent` method to calculate and update the value when the key exists, allowing complex calculations to be executed without unnecessary operations on non-existent keys; merging operations can be performed using the `merge` method to combine two values in the cache, allowing merging of existing and new values when the key exists, or inserting a new value when the key does not exist, or using distributed caching to ensure efficient merging of existing and new values when the key exists, or inserting a new value when the key does not exist; and cache release operations refer to the process of determining the lifecycle of data stored in the cache to ensure its validity and consistency. The core purpose is to check whether the cached data is still within its set validity period or meets specific expiration conditions, thus determining whether it needs to be reloaded, refreshed, or deleted. Alternatively, scheduled tasks can be used to periodically clean up expired cache items, rather than relying on the cache's own expiration mechanism.
[0119] Optionally, if the target operation at the current moment is a first cache operation, the business system determines the locking mechanism configured for the target cache mode from the cache control parameters of the target cache mode. For example, if the locking mechanism configured for the target cache mode is a lock-free hash table, then the target operation will be performed using a lock-free hash table, which can achieve efficient write, update, calculation, and merge operations, ensuring performance in a high-concurrency environment. If the locking mechanism configured for the target cache mode is a pessimistic lock, then the first cache operation will be performed using a pessimistic lock mechanism, which can meet the caching needs of business application scenarios with low performance requirements.
[0120] It's important to note that besides using lock-free hash tables, lock-free mechanisms can also utilize other lock-free data structures (such as skip lists and lock-free linked lists) to implement cache write and update operations, reducing lock contention and synchronization overhead. Furthermore, conditional update and computation operations can employ transaction mechanisms in addition to optimistic locking, ensuring that cache items are updated or computed atomically when specific conditions are met, rather than relying on optimistic locking. Merge operations can also use distributed transactions, ensuring efficient merging of existing and new values when the key exists, or insertion of a new value when the key does not exist, rather than using local merge operations.
[0121] Optionally, if the target operation at the current moment belongs to the second cache operation, the business system determines the tolerance and cache timing unit configured in the target cache mode from the cache control parameters of the target cache mode. For example, if the tolerance configured in the cache control parameters of the target cache mode is one day and the cache timing unit is the timing unit of the default timer, then when performing the cache release operation, the retention time of the timed business data stored in the cache is timed using the default timer. To check whether the business data meets the cache release operation, the retention time of the timed data needs to be compared with the sum of the tolerance and the preset expiration time to determine whether the business data meets the expiration processing conditions. If it does, the cache release operation is performed; otherwise, the business data continues to be retained in the cache.
[0122] It's worth noting that the second cache operation can also employ a sliding window algorithm for cache expiration management. This involves maintaining a list of cached items within a time window and periodically cleaning up expired items, rather than relying on global timestamp comparisons. Instead of using a fixed tolerance value, expiration checks are postponed for a period before the actual expiration time of a cached item (e.g., 50% of the expiration time). This allows for dynamic adjustment of the write tolerance based on specific business needs.
[0123] In this embodiment, the applicable target control parameters for the target operation are dynamically determined according to the type of the target operation, including locking mechanism or tolerance and timing unit. This enables the performance of cache operations and reasonable cache data management to be guaranteed in a high-concurrency environment, thereby improving system performance and further enhancing the flexibility of business data caching.
[0124] In an exemplary embodiment, the performance test parameters include thread configuration information; step S104 constructs corresponding test data based on business data, and determines the performance test parameters for the test data according to the business scenario type, including:
[0125] Based on the attribute information of the business data, generate multiple key-value pairs, and construct test data based on the multiple key-value pairs.
[0126] Among these, attribute information can be inherent attributes of business data, fields or metadata describing features or categories, which determine the generation logic and caching behavior of test data. Key-value pairs can be the basic unit for storing data in the caching system, consisting of a key and a value, used to simulate real caching operations.
[0127] Optionally, the business system uses a random number generator, such as ScrambledZipfianGenerator, to generate multiple key-value pairs with random values but consistent with the attribute information of the business data, based on the attribute information of the business data. This ensures that the data distribution conforms to the actual application scenario. Understandably, the number of key-value pairs is less than the number of business data. The business system loads multiple key-value pairs into the cache in batches to complete the cache warm-up process, thus serving as test data.
[0128] In an exemplary embodiment, step S106 employs at least two pre-built candidate caching modes that match the business scenario type, performs caching performance testing on the test data according to performance test parameters, and obtains the performance test results for each of the at least two candidate caching modes, including:
[0129] Identify at least two threads that match the thread configuration information; use at least two pre-built candidate caching modes that match the business scenario type, and perform caching performance tests on the test data using at least two threads to obtain the performance test results of each of the at least two candidate caching modes.
[0130] The thread configuration information can be a set of parameters that control the concurrency simulation in performance testing, determining how to simulate real request pressure through multi-threading, including the number of threads, thread lifecycle, task allocation strategy, etc.; and the thread can be the smallest execution unit that simulates user requests in performance testing, with each thread independently performing cache operations (such as read / write).
[0131] Optionally, the business system determines the thread configuration information required to simulate the business scenario based on the business scenario type, and further determines at least two threads that match the thread configuration information. Each thread independently maintains a ThreadState object to record the current thread's state information, including the random number generator and the current index. Before each thread starts, the ThreadState object is initialized and a unique random index is assigned to it to facilitate monitoring the task execution of each thread. Furthermore, the business system adopts at least two pre-built candidate caching modes that match the business scenario type, and performs caching performance tests on the test data using at least two threads to obtain the performance test results of each of the at least two candidate caching modes.
[0132] In this embodiment, test data that conforms to the distribution characteristics of actual applications is generated, and the distribution is consistent with the attribute information of business data. Multi-threading is used to simulate actual pressure and evaluate the performance of different caching modes. By comparing multiple candidate solutions, the caching strategy most suitable for the current business scenario is selected, making the caching performance test closer to the actual business application and better reflecting the actual caching pressure. This results in more objective and accurate performance test results, which helps to select the most suitable target caching mode.
[0133] In one exemplary embodiment, determining the target cache mode from at least two candidate cache modes based on the performance test results of each of the at least two candidate cache modes includes:
[0134] The performance test results of at least two candidate caching modes are processed using a preset scoring algorithm to obtain the performance scores of each of the at least two candidate caching modes; based on the performance scores of each of the at least two candidate caching modes, the target caching mode is determined from the at least two candidate caching modes.
[0135] The preset scoring algorithm can be a pre-designed mathematical or logical model used to quantify performance test results (such as latency, throughput, hit rate, etc.) into a comparable comprehensive score, thereby objectively evaluating the merits of different caching modes.
[0136] Among them, the performance score can be a quantitative evaluation value obtained by processing the test results of the candidate caching modes through a scoring algorithm, which is used to compare the overall performance of different modes horizontally.
[0137] Optionally, the business system uses a preset scoring algorithm to process the performance test results of at least two candidate caching modes separately. Specifically, the performance test results include multiple performance indicators. Each performance indicator is compared with a preset scoring table of performance indicator value ranges to determine the score of each performance indicator. Then, based on the preset weight and score of each performance indicator, a weighted sum is performed to obtain the performance score of the performance test results. Further, the business system sorts the performance scores of at least two candidate caching modes in descending or ascending order, and determines the candidate caching mode with the highest performance score from at least two candidate caching modes as the target caching mode.
[0138] In this embodiment, the performance of various candidate caching modes is quantitatively compared through a preset scoring algorithm and weighting mechanism, so as to systematically and objectively select the optimal target caching mode.
[0139] In one exemplary embodiment, such as Figure 4 As shown, applied to, for example Figure 4 The main program shown provides another method for caching business data, including:
[0140] The system corresponding to the main program includes an expiration processor, a data processor, and a cache builder.
[0141] Step 1: Construct cache instances (candidate cache modes). Build a Caffeine cache implementation with write tolerance optimization. During cache initialization, set `expireAfterWrite` to one day and enable write tolerance. Test the cache's write and update performance using operations such as `put`, `replace`, and `compute` under high concurrency. Build a Caffeine cache implementation without write tolerance optimization. During cache initialization, set `expireAfterWrite` to nanoseconds and disable write tolerance. Test the cache's write and update performance using operations such as `put`, `replace`, and `compute` under high concurrency. Build a Guava cache implementation. During cache initialization, set `expireAfterWrite` to one day and use a custom `FakeTicker` to simulate the passage of time. Test the cache's write and update performance using operations such as `put`, `replace`, and `compute` under high concurrency.
[0142] For example, ConcurrentHashMap can be used as the underlying implementation of the cache, and the write and update performance of the cache can be optimized by manually implementing an expiration mechanism. This approach can periodically clean up expired cache items by introducing scheduled tasks, but it may lead to high resource consumption and garbage collection overhead. Implementations based on other caching libraries include using other open-source caching libraries (such as Ehcache, Hazelcast, etc.) as the underlying implementation of the cache, and optimizing the write and update performance of the cache by configuring different expiration policies. This approach can be flexibly configured according to specific business needs, but its performance in high-concurrency environments may not be as good as the Caffeine optimization approach.
[0143] Step 2: Perform cache performance testing on the above cache instances. Using the JMH (Java Microbenchmark Harness) framework, collect performance metrics for cache operations, including operations per second (Ops / sec) and average latency. The JMH framework ensures the accuracy and reliability of performance test results by executing cache operations concurrently through multi-threading. Benchmark tests using the JMH framework are conducted to verify the effectiveness of Caffeine's write tolerance optimization. Benchmark tests using the JMH framework are also conducted to verify the effectiveness of Guava caching. Finally, benchmark tests using the JMH framework are conducted to verify the effectiveness of Guava caching, obtaining performance test results for the three cache instances.
[0144] For example, the specific implementation of caching operations during the test is as follows: Cache write operation: The `put` method writes new key-value pairs to the cache. In a high-concurrency environment, multiple threads may simultaneously attempt to write data to the cache. To avoid lock contention, Caffeine uses a lock-free implementation based on a hash table to ensure the efficiency of write operations. During the write process, Caffeine automatically handles cache size limitations and removes old cache items when necessary. Cache update operation: The `replace` method updates existing key-value pairs. This method checks if the key exists in the cache before updating; the update operation is only performed if the key exists. Caffeine reduces the possibility of lock contention and improves the concurrency of update operations by using an optimistic locking mechanism. Conditional update operation: The `replaceConditionally` method updates cache items when a specific condition is met. This method allows specifying a conditional predicate before updating; the update operation is only performed when the condition is met. This operation achieves efficient conditional updates through Caffeine's optimistic locking mechanism, reducing lock contention and synchronization overhead. Computation operation: The `compute` method computes and stores new values in the cache. This method allows inserting a new value when the key does not exist in the cache, or updating an existing value when the key exists. Caffeine implements efficient computation operations using a lock-free concurrent hash table, ensuring performance in high-concurrency environments. Conditional computation operations, using the `computeIfPresent` method, compute and update the value of a key when it exists in the cache. This method allows complex computational logic to be performed when the key exists, without unnecessary operations on non-existent keys. This operation, implemented lock-free by Caffeine, ensures efficient conditional computation. Merge operations, using the `merge` method, merge two values in the cache. This method allows merging an existing value and a new value when the key exists, or inserting a new value when the key does not exist. Caffeine implements efficient merge operations using a lock-free concurrent hash table, ensuring performance in high-concurrency environments. Expiration handling optimizations: When a cached item is close to expiration, Caffeine reduces unnecessary expiration checks by introducing write tolerance. Specifically, Caffeine postpones expiration checks for a period of time before the actual expiration time of cached items (i.e., within the write tolerance range), thereby reducing unnecessary garbage collection and cache cleanup operations.
[0145] Step 3: Based on the business application scenario (business scenario type) and the verification of performance test results, determine the caching implementation method under the business application scenario and cache the business data.
[0146] In this embodiment, the following improvements are made: First, cache update efficiency is improved: By introducing a lock-free implementation based on a hash table, lock contention and synchronization overhead are reduced, significantly improving the performance of cache write and update operations, especially in high-concurrency environments. Second, resource consumption for expiration handling is reduced: By introducing a write tolerance mechanism, unnecessary expiration checks are postponed, reducing garbage collection and cache cleanup operations, lowering system resource consumption, and improving overall performance. Third, the accuracy of the cache expiration mechanism is improved: By using a custom time counter, the elapsed time can be precisely controlled, ensuring the accuracy of expiration handling and avoiding accidental deletion or retention of cached items due to time errors. Fourth, the flexibility of cache operations is enhanced: By providing multiple cache implementation options, the optimal cache strategy can be flexibly selected according to different application scenarios to meet diverse business needs. Fifth, conditional update and calculation operations are improved: By introducing conditional update and calculation operations, cached items can be updated or calculated efficiently when specific conditions are met, reducing unnecessary operations and improving system response speed. Sixth, efficient merge operations are provided: Through the merge method, existing values and new values can be efficiently merged when the key exists, or new values can be inserted when the key does not exist, avoiding repeated lookup and insertion operations and improving overall system performance. Reduced lock contention and synchronization overhead: By using optimistic locking, the likelihood of lock contention is reduced, improving the concurrency of cache operations, especially in high-concurrency environments. Support for large-scale cache testing: Benchmarking using the JMH framework allows for precise evaluation of the performance of different cache implementations, helping developers choose the most suitable caching strategy and ensuring efficient system operation. Precise control over time elapsed: Using a custom time counter allows for precise control over time elapsed in the test environment, facilitating performance and benchmark testing and improving test accuracy and reliability. Improved system response speed and stability: By optimizing cache write, update, and expiration mechanisms, unnecessary resource consumption and garbage collection operations are reduced, improving system response speed and stability, particularly under high load and high concurrency environments.
[0147] It should be understood that although the steps in the flowcharts of the embodiments described above 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 steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0148] Based on the same inventive concept, this application also provides a business data caching device for implementing the business data caching method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more business data caching device embodiments provided below can be found in the limitations of the business data caching method described above, and will not be repeated here.
[0149] In one exemplary embodiment, such as Figure 5 As shown, a business data caching device 500 is provided, including: a data acquisition module 501, a parameter determination module 502, a performance testing module 503, and a mode determination module 504, wherein:
[0150] The data acquisition module 501 is used to acquire business data and determine the business scenario type to which the business data belongs;
[0151] The parameter determination module 502 is used to construct corresponding test data based on business data and determine the performance test parameters for the test data according to the business scenario type.
[0152] The performance testing module 503 is used to perform cache performance testing on test data according to performance test parameters using at least two pre-built candidate cache modes that match the business scenario type, and obtain the performance test results of each of the at least two candidate cache modes.
[0153] The mode determination module 504 is used to determine the target cache mode from at least two candidate cache modes based on the performance test results of each of the at least two candidate cache modes, and to perform cache processing on business data using the target cache mode.
[0154] Furthermore, in one embodiment, the performance testing module 503 is also used to determine at least two pre-built candidate caching modes that match the business scenario type; the at least two candidate caching modes are configured based on the business scenario type for the baseline caching mode; the at least two candidate caching modes are used to perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes.
[0155] Furthermore, in one embodiment, the performance testing module 503 is also used to determine at least one business cache requirement of the baseline cache mode and the business scenario type; and to configure at least one cache control parameter of the baseline cache mode according to the at least one business cache requirement to obtain at least two candidate cache modes that match the business scenario type.
[0156] Furthermore, in one embodiment, the performance testing module 503 is also used to configure the locking mechanism according to concurrency requirements and determine the configured locking mechanism; configure the tolerance according to concurrency requirements and consistency requirements and determine the configured tolerance; configure the cache timing unit according to real-time requirements and determine the configured cache timing unit; and obtain at least two candidate cache modes that match the business scenario type based on the configured locking mechanism, the configured tolerance, and the configured cache timing unit.
[0157] Furthermore, in one embodiment, the performance testing module 503 is also used to determine a pre-built cache mode mapping relationship; the cache mode mapping relationship includes candidate cache modes corresponding to different business scenario types; based on the cache mode mapping relationship, at least two candidate cache modes that match the business scenario type are determined.
[0158] Furthermore, in one embodiment, the mode determination module 504 is also configured to determine a target operation for the business data; determine target control parameters from the cache control parameters of the target cache mode according to the target operation; and perform the target operation on the business data according to the target control parameters to cache the business data.
[0159] Furthermore, in one embodiment, the mode determination module 504 is also configured to determine a locking mechanism from the cache control parameters of the target cache mode when the target operation belongs to a first cache operation, wherein the first cache operation includes at least one of a write operation, an update operation, a calculation operation, and a merge operation; and to determine a tolerance and a cache timing unit from the cache control parameters of the target cache mode when the target operation belongs to a second cache operation, wherein the second cache operation includes a cache release operation.
[0160] Furthermore, in one embodiment, the performance testing module 503 is also used to generate multiple key-value pairs based on the attribute information of the business data, and construct test data based on the multiple key-value pairs; using at least two pre-built candidate caching modes that match the business scenario type, the caching performance is tested on the test data through at least two threads to obtain the performance test results of each of the at least two candidate caching modes.
[0161] Each module in the aforementioned business data caching device 500 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 a computer device, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0162] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores business data, business scenario types, test data, performance test parameters, performance test results, candidate cache patterns, and target cache patterns. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a business data caching method.
[0163] Those skilled in the art will understand that Figure 6 The structure shown 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 combine certain components, or have different component arrangements.
[0164] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0165] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0166] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0167] 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 used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0168] 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, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0169] 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 application.
[0170] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. 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. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A business data caching method, characterized in that, The method includes: Acquire business data and determine the business scenario type to which the business data belongs; Based on the business data, construct corresponding test data, and determine the performance test parameters for the test data according to the business scenario type; Using at least two pre-built candidate caching modes that match the business scenario type, perform caching performance tests on the test data according to the performance test parameters to obtain the performance test results of each of the at least two candidate caching modes; Based on the performance test results of the at least two candidate caching modes, a target caching mode is determined from the at least two candidate caching modes, and the business data is cached using the target caching mode.
2. The method according to claim 1, characterized in that, The process involves employing at least two pre-built candidate caching modes that match the business scenario type, performing caching performance tests on the test data according to performance test parameters, and obtaining the performance test results for each of the at least two candidate caching modes, including: Identify at least two pre-built candidate caching patterns that match the business scenario type; the at least two candidate caching patterns are obtained by configuring the baseline caching pattern based on the business scenario type. The cache performance of the test data is tested using the at least two candidate caching modes according to the performance test parameters, and the performance test results of the at least two candidate caching modes are obtained.
3. The method according to claim 2, characterized in that, The determination of at least two pre-built candidate caching patterns that match the business scenario type includes: Determine at least one business caching requirement for the baseline caching mode and the business scenario type; Based on the at least one business caching requirement, at least one cache control parameter of the baseline caching mode is configured to obtain at least two candidate caching modes that match the business scenario type.
4. The method according to claim 3, characterized in that, The cache control parameters include tolerance, cache timing unit, and locking mechanism; the business cache requirements include concurrency requirements, real-time requirements, and consistency requirements. The step involves configuring at least one cache control parameter of the baseline cache mode based on the at least one business cache requirement, to obtain at least two candidate cache modes that match the business scenario type, including: Configure the locking mechanism according to the concurrency requirements, and determine the configured locking mechanism; Configure the tolerance based on the concurrency requirements and the consistency requirements, and determine the configured tolerance; Configure the cache timing unit according to the real-time requirements, and determine the configured cache timing unit; Based on the configured locking mechanism, the configured tolerance, and the configured cache timing unit, at least two candidate cache modes that match the business scenario type are obtained.
5. The method according to claim 2, characterized in that, The determination of at least two pre-built candidate caching patterns that match the business scenario type includes: Determine the pre-built cache pattern mapping relationship; the cache pattern mapping relationship includes candidate cache patterns corresponding to different business scenario types; Based on the cache pattern mapping relationship, at least two candidate cache patterns that match the business scenario type are determined.
6. The method according to claim 1, characterized in that, The caching process for the business data using the target caching mode includes: Determine the target operation for the business data; Based on the target operation, the target control parameters are determined from the cache control parameters of the target cache mode; The target operation is performed on the business data according to the target control parameters to perform caching processing on the business data.
7. The method according to claim 6, characterized in that, The step of determining the target control parameters from the cache control parameters of the target cache mode according to the target operation includes at least one of the following: If the target operation is a first cache operation, a locking mechanism is determined from the cache control parameters of the target cache mode. The first cache operation includes at least one of a write operation, an update operation, a computation operation, and a merge operation. If the target operation is a second cache operation, the tolerance and cache timing unit are determined from the cache control parameters of the target cache mode, and the second cache operation includes a cache release operation.
8. The method according to any one of claims 1 to 7, characterized in that, The performance test parameters include thread configuration information; the process of constructing corresponding test data based on the business data and determining performance test parameters for the test data according to the business scenario type includes: Based on the attribute information of the business data, generate multiple key-value pairs, and construct test data based on the multiple key-value pairs; The process involves employing at least two pre-built candidate caching modes that match the business scenario type, performing caching performance tests on the test data according to performance test parameters, and obtaining the performance test results for each of the at least two candidate caching modes, including: Identify at least two threads that match the thread configuration information; At least two pre-built candidate caching modes that match the business scenario type are used, and the caching performance is tested on the test data by the at least two threads to obtain the performance test results of each of the at least two candidate caching modes.
9. A business data caching device, characterized in that, The device includes: The data acquisition module is used to acquire business data and determine the business scenario type to which the business data belongs; The parameter determination module is used to construct corresponding test data based on the business data and determine performance test parameters for the test data according to the business scenario type. The performance testing module is used to perform cache performance testing on the test data according to the performance testing parameters using at least two pre-built candidate caching modes that match the business scenario type, and to obtain the performance test results of each of the at least two candidate caching modes. The mode determination module is used to determine the target cache mode from the at least two candidate cache modes based on the performance test results of each of the at least two candidate cache modes, and to perform cache processing on the business data using the target cache mode.
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 steps of the method according to any one of claims 1 to 8.