Self-adaptive caching method and device, storage medium and program product
By providing a unified interface and dynamically loading the cache library in the cache system, the problems of complex cache mode switching, inconsistent data, and waste of resources in the existing technology are solved, and the system flexibility, easy maintenance and performance improvement are achieved.
Patent Information
- Application Number
- CN202510065582.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-02-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When existing caching technology switches between multiple cache modes, it leads to increased code complexity, inconsistent versions, difficult maintenance, and may lead to inconsistent data, waste of resources and increased operation and maintenance costs in single-node scenarios.
By providing a unified interface and dynamic loading of the target cache library, the cache mode is flexibly switched according to business needs, reducing code complexity, reducing developer workload, and reducing the coupling between business code and cache implementation.
It improves the flexibility and easy maintenance of the system, reduces resource waste and operation and maintenance costs, and significantly improves the system's response speed and overall performance.
Smart Images

Figure CN119474158A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of information storage technology, and in particular to an adaptive cache method, device, storage medium, and program product. Background Art
[0002] Currently, cache technology is widely used to improve system performance and response speed. Developers need to write different codes for different cache modes such as memory cache and distributed cache. The existence of multiple cache modes significantly increases the complexity of code development, which easily leads to inconsistencies between versions and increased maintenance difficulties. Moreover, in a single-node scenario, the introduction of distributed cache may cause unnecessary waste of resources and increase in operation and maintenance costs, because distributed cache systems usually require more resources to support their functions. On the contrary, in a multi-node scenario, if only memory cache is used, data inconsistency may occur, because the memory cache of each node is independent and data consistency cannot be guaranteed. In addition, high code coupling is also a problem with the existing technology. In many cases, the cache logic is tightly coupled with the business code, which limits the flexibility of the cache system and causes a lot of code modification work when the cache implementation needs to be adjusted or replaced. Summary of the invention
[0003] In view of this, the embodiments of the present disclosure provide an adaptive caching method, device, storage medium, and program product, which can provide a unified interface and dynamic loading of the target cache library, facilitate the selection of appropriate cache modes according to business needs and flexibly switch them, reduce code complexity, reduce the workload of developers, and reduce the coupling between business code and cache implementation, thereby improving the flexibility and maintainability of the system.
[0004] In a first aspect, an embodiment of the present disclosure provides an adaptive caching method, which adopts the following technical solution: Determine the target cache type and target storage space based on the business scenario; Based on the target cache type, loading the target cache library into the target device; Building a unified interface, wherein the unified interface encapsulates multiple cache functions; In response to the application layer calling the unified interface, determining a target cache function from a plurality of cache functions; The target cache function is performed on the target storage space by calling the target cache library.
[0005] Optionally, the loading a target cache library to a target device based on the target cache type includes: Setting cache mode parameters in a configuration file of the application according to the target cache type; Based on the cache mode parameters, a target cache library is loaded into the target device.
[0006] Optionally, the building of a unified interface includes: Setting a unified interface, encapsulating multiple cache functions in the unified interface; Obtain the operation interfaces of two or more cache libraries; Build adapters for each cache library; The adapter is used to map the unified interface to the operation interface of the corresponding cache library.
[0007] Optionally, the multiple cache functions include a cache mechanism and a cache operation API; wherein the cache mechanism includes at least one of clearing cache, cache expiration time, cache maximum capacity and invalidation callback; the cache operation API includes at least one of adding cache, querying cache, invalidating cache, updating cache, querying cache size and querying whether cache exists.
[0008] Optionally, the cache mechanism is configured by a preset external configuration file, and the external configuration file adopts the SpringBoot YAML format; Monitor changes in the external configuration file, and when the external configuration file is updated, obtain a new cache mechanism configuration; The settings of the target cache library are updated based on the new cache mechanism configuration.
[0009] Optionally, create two or more library files in the specified directory; Register the implementation class information of two or more preset cache libraries into different library files; When adding a new cache library, create a new library file in the specified directory; Register the implementation class information of the new cache library into the new library file.
[0010] Optionally, a Metrics measurement framework is integrated into the unified interface; Using the Metrics measurement framework to collect performance data when the target cache function is executed; The performance data is visually displayed.
[0011] In a second aspect, the embodiment of the present disclosure further provides an adaptive cache system, which adopts the following technical solution: A determination module is used to determine the target cache type and target storage space based on the business scenario; A loading module, used for loading a target cache library into a target device based on the target cache type; A construction module, used to construct a unified interface, wherein the unified interface encapsulates multiple cache functions; A response module, configured to determine a target cache function from a plurality of cache functions in response to a call of the unified interface by the application layer; An execution module is used to execute the target cache function on the target storage space by calling the target cache library.
[0012] In a third aspect, the embodiments of the present disclosure further provide a computer device, which adopts the following technical solution: The computer device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any of the above-mentioned adaptive caching methods.
[0013] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute any of the above-mentioned adaptive caching methods.
[0014] In a fifth aspect, an embodiment of the present disclosure further provides a computer program product, including a computer program / instruction, which implements the steps of any of the above methods when executed by a processor.
[0015] The adaptive caching method provided by the embodiment of the present disclosure can automatically adapt to different operating environments, whether it is a single service or a distributed environment, by determining the target cache type and target storage space according to the business scenario, which enables the cache system to dynamically adjust its behavior to utilize available resources in the best way. In addition, by selecting the appropriate cache type according to actual needs, resource waste can be effectively avoided and costs can be reduced. By building a unified interface to encapsulate multiple cache functions to shield the underlying implementation details, developers do not need to care about the details of the underlying cache implementation, which reduces the complexity of the code, reduces maintenance costs, and helps to maintain the consistency and readability of the code. Since the cache logic is abstracted through a unified interface, loose coupling is achieved between the business code and the cache implementation, which means that the cache implementation can be more easily changed or upgraded without modifying the business logic code, thereby improving the flexibility and scalability of the system. The design of the unified interface allows developers to integrate cache functions more quickly without writing different codes for different cache systems, which not only speeds up the development process, but also reduces the occurrence of errors and improves development efficiency. Finally, by calling the target cache library, the target cache function is performed on the target storage space. This adaptive caching method reduces the need for manual configuration and management of the cache, allowing operation and maintenance personnel to more easily manage and monitor the cache system, thereby improving the stability and reliability of the system, and significantly improving the system's response speed and overall performance.
[0016] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the following preferred embodiments are specifically cited and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 A schematic diagram of a flow chart of an adaptive caching method provided in an embodiment of the present disclosure; Figure 2 A schematic diagram of a process for constructing a unified interface provided by an embodiment of the present disclosure; Figure 3 A flowchart of a configuration update method provided in an embodiment of the present disclosure; Figure 4 A principle block diagram of an adaptive cache system provided by an embodiment of the present disclosure; Figure 5A schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0019] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0020] It should be clear that the following embodiments of the present disclosure are described by specific specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other in the absence of conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0021] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0022] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The drawings only show components related to the present disclosure rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0023] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.
[0024] Reference Figure 1 The present disclosure provides an adaptive caching method, comprising the following steps: S1: Determine the target cache type and target storage space based on the business scenario; S2: Based on the target cache type, load the target cache library to the target device; S3: Build a unified interface that encapsulates multiple cache functions; S4: in response to the application layer calling the unified interface, determining a target cache function from a plurality of cache functions; S5: Execute the target cache function on the target storage space by calling the target cache library.
[0025] The adaptive caching method disclosed in the present invention can automatically adapt to different operating environments, whether it is a single service or a distributed environment, by determining the target cache type and target storage space according to the business scenario, which enables the cache system to dynamically adjust its behavior to utilize available resources in the best way. In addition, by selecting the appropriate cache type according to actual needs, resource waste can be effectively avoided and costs can be reduced. By building a unified interface to encapsulate multiple cache functions to shield the underlying implementation details, developers do not need to care about the details of the underlying cache implementation, which reduces the complexity of the code, reduces maintenance costs, and helps to maintain the consistency and readability of the code. Since the cache logic is abstracted through a unified interface, loose coupling is achieved between the business code and the cache implementation, which means that the cache implementation can be more easily changed or upgraded without modifying the business logic code, thereby improving the flexibility and scalability of the system. The design of the unified interface allows developers to integrate cache functions more quickly without writing different codes for different cache systems, which not only speeds up the development process, but also reduces the occurrence of errors and improves development efficiency. Finally, by calling the target cache library, the target cache function is performed on the target storage space. This adaptive caching method reduces the need for manual configuration and management of the cache, allowing operation and maintenance personnel to more easily manage and monitor the cache system, thereby improving the stability and reliability of the system, and significantly improving the system's response speed and overall performance.
[0026] In summary, by providing a unified interface and dynamic loading of the target cache library, it is beneficial to flexibly switch between different cache modes according to business needs without the need for developers to modify additional code, thereby improving the flexibility and maintainability of the system.
[0027] In S1, the target cache type includes at least one of a memory cache and a distributed cache. With the emergence of new cache types in the future, the target cache type may also include new cache types. The target storage space refers to the actual area in the target cache library used to store data, such as a hash table in a memory cache, a key-value pair storage space in a distributed cache, or a file block in a file cache.
[0028] One way to implement "determine the target cache type and target storage space based on the business scenario" is to manually analyze the business scenario to determine which type of cache to use and the location of the storage space. This method relies on the developer's experience and understanding of business needs. For example, based on the analysis of the business scenario of an e-commerce website, memory cache and local storage space are selected to store product information and user sessions to improve access speed.
[0029] Another way to implement "determine the target cache type and target storage space based on the business scenario" is that the system automatically senses the business scenario and determines the target cache type and target storage space. This requires the system to monitor business traffic, data access patterns, and system performance indicators, analyze user input and system-generated data to determine the cache requirements of the business scenario, and then dynamically adjust the cache strategy, which includes the target cache type and target storage space that are suitable for the business scenario. For example, full-site acceleration services (such as content delivery networks CDN) can automatically distinguish between dynamic content and static content, and apply different cache strategies based on the characteristics of the content.
[0030] In S2, in a distributed system, the target device refers to a physical server or virtual machine that runs an application or cache service. For a single application, the target device refers to the specific environment in which the application runs, such as a specific computer, mobile device, or container (such as a Docker container).
[0031] Set the cache mode parameter in the application configuration file according to the target cache type. For example, the cache mode parameter is cache.mode. If the target cache type is memory cache, the value of cache.mode is set to memory. If the target cache type is distributed cache, the value of cache.mode is set to distributed.
[0032] When the application starts, the target cache library is loaded to the target device and initialized according to the cache mode parameters in the configuration file. For example, for the memory cache mode, the Caffeine library is loaded, which means that Caffeine is used as the underlying infrastructure to obtain the underlying logic implementation of the memory cache; for the distributed cache mode, the Redis library is loaded, which means that Redis is used as the underlying infrastructure to obtain the underlying logic implementation of the distributed cache. In this way, the cache mode parameters can be dynamically adjusted according to the needs of the product deployment scenario, so as to select the applicable cache mode. Among them, loading the target cache library can be achieved through dependency injection (such as Spring's @Bean) or dynamic loading (such as reflection or SPI mechanism).
[0033] The same device can use two or more different cache modes at the same time, that is, based on the business scenario, determine two or more different target cache types and target storage spaces. For example, an application uses both memory cache (such as Caffeine) to store frequently accessed data and distributed cache (such as Redis) to support high concurrent access and data sharing. Different cache modes can target different data sets or business logic to optimize performance and resource utilization.
[0034] In the configuration file of the application, different cache mode parameters are predefined according to business requirements, that is, two or more different cache mode parameters are set in the configuration file of the application according to two or more different target cache types. For example, two cache mode parameters can be set, namely cache.mode1 and cache.mode2, with the value of cache.mode1 being memory and the value of cache.mode2 being distributed, to enable two different cache modes.
[0035] When the application starts, different target cache libraries are dynamically loaded to the target device according to different cache mode parameters in the configuration file, that is, two or more different target cache libraries are loaded to the target device based on two or more different cache mode parameters. Different target cache libraries are integrated into the application, and the corresponding cache mode is used according to the business logic. For example, for data that needs to be accessed quickly, use memory cache; for data that needs to be shared across multiple nodes, use distributed cache.
[0036] By dynamically selecting and configuring different cache solutions based on configuration files at runtime without modifying the code, the application can easily adapt to different cache requirements, improving system flexibility and scalability.
[0037] In S3, refer to Figure 2 The flowchart of the method for building a unified interface is shown. Building a unified interface includes the following steps: S301: Setting a unified interface, and encapsulating multiple cache functions in the unified interface; S302: Acquire two or more cache library operation interfaces; S303: Building adapters for each cache library; S304: Use an adapter to map the unified interface to the operation interface of the corresponding cache library.
[0038] Specifically, according to business needs, determine the cache functions that are needed or may be used. For example, the cache function includes a cache mechanism and a cache operation API, where the cache mechanism is defined by the Builder Pattern, which is a design pattern that allows developers to create cache instances through a step-by-step construction process and configure various corresponding parameters to create the required cache mechanism. The cache mechanism includes at least one of clearing the cache, cache expiration time, maximum cache capacity, and invalidation callback; the cache operation API includes at least one of adding cache, querying cache, invalidating cache, updating cache, querying cache size, and querying whether the cache exists. Among them, clearing the cache refers to configuring whether to clear the cache at startup, and the code is Builder.initializeClear(true); the cache expiration time refers to configuring the expiration time of the cache, so that the cache is automatically cleared when the expiration time is reached, and the code is Builder.ttl(Duration.ofMillis(n)); the maximum cache capacity refers to the configuration capacity size limit, and the code is Builder.maxSize(n); the invalidation callback refers to triggering the callback function when the cache is invalid to notify the relevant components or modules to perform necessary processing or response, and the code is Builder.removeListener(aListener). The code for adding cache is put(key,value); the code for querying cache is get(key); the code for invalidating cache is clear(key), clearAll(key); the code for updating cache is update(key,value); the code for querying cache size is size(); the code for querying whether the cache exists is contains(key).
[0039] For two or more cache libraries, obtain the operation interface (also known as operation API) provided by each cache library, and create an adapter for each cache library. The adapter is responsible for interacting with the operation interface of the corresponding cache library, that is, each adapter encapsulates the operation interface of the corresponding cache library and provides the necessary methods to interact with the cache library. Define a unified interface (such as CacheService), and select at least two cache functions to encapsulate them into the unified interface according to actual needs. The mapping between the unified interface and multiple operation interfaces is achieved through the adapter, that is, each adapter converts the method call of the unified interface at the application layer into the operation interface call of the corresponding cache library, realizing the unification of operations of different cache libraries. This process ensures that the application can interact with different cache libraries through a unified interface without having to worry about the specific implementation details of the cache library.
[0040] In S4, the application layer initiates a request to the cache system through a unified interface. When calling, the application layer needs to pass necessary parameters, such as cache key and cache value. In response to the application layer's call to the unified interface, the target cache function is determined from a variety of cache functions by parsing the parameters passed by the application layer. For example, when the application layer needs to cache data, it calls the put method of the unified interface and provides the corresponding cache key and cache value. When the application layer needs to retrieve data from the cache, it calls the get method and provides the corresponding cache key. The application layer can also call the clear method to delete a specific cache item, or call clearAll to clear all cache items.
[0041] In S5, after integrating the required target cache library into the application by loading it to the target device, the application layer calls the target cache library through a unified interface and uses the function of the target cache library to perform the target cache function on the target storage space. When the target device loads two or more different target cache libraries, the user role that initiates the call through the application layer is identified or the call source is distinguished according to the data type, the target cache library and the target storage space are specified according to the user role or data type, and the specified target cache library is called to perform the target cache function on the specified target storage space. In this way, the application can transparently use different cache libraries, while the specific cache implementation and storage space are managed by the configuration file and adapter. This not only hides the specific cache implementation details, but also provides a flexible cache function selection mechanism.
[0042] Furthermore, the configuration of the specified cache mechanism can be dynamically modified through external configuration to achieve dynamic cache management, allowing developers to adjust the cache configuration without redeploying or suspending the use of the cache, achieving seamless updates. Figure 3 The flowchart of the configuration update method shown in the figure, the method for updating the cache mechanism configuration includes the following steps: S6: The cache mechanism is configured through a preset external configuration file, which uses the SpringBootYaml format; S7: monitors changes in external configuration files, and obtains new cache mechanism configuration when the external configuration files are updated; S8: Update the settings of the target cache library based on the new cache mechanism configuration.
[0043] In S6, three cache mechanisms, namely, cache clearing, cache expiration time, and cache maximum capacity, are configured through a preset external configuration file. The external configuration file adopts the SpringBoot YAML format. Based on this format, a Map structure is configured for the external configuration file. The Map structure includes Key and Value, where Key is the name of the cache mechanism and Value is the configuration parameter of the cache mechanism. Value includes initializeClear, ttl, and maxSize.
[0044] In S7, there are two ways to monitor whether the external configuration file has changed: first, scan the external configuration file regularly, and then determine whether the external configuration file has changed by comparing the results of two adjacent scans; second, after the external configuration file is modified, trigger the generation of an update request, and when the update request is received, determine that the external configuration file has been updated.
[0045] In S8, when the external configuration file is updated, the new cache mechanism configuration is read from the external configuration file, and then the settings of the target cache library are updated. The updating of the settings of the target cache library includes adjusting at least one of the cache cleaning strategy, resetting the cache expiration time, and resetting the maximum cache capacity.
[0046] The SPI mechanism can also be used to register specific cache libraries. The SPI mechanism provides a method for dynamically discovering and loading service providers (i.e., cache libraries, also known as cache implementations) at runtime, and can flexibly replace or add different cache library implementations without modifying the main application code. Specifically, two or more library files are created in a specified directory, and initialization names are assigned to the library files, wherein the specified directory is the META-INF / services / directory of the JAR file of the application or library. The implementation class information of each cache library currently required is registered in different library files, that is, the initialization name of the library file is modified to the fully qualified name of the operation interface of the cache library, and the file content of the library file is the fully qualified name of the specific class that implements the corresponding operation interface. When adding a new cache library, a new library file is created in the specified directory, and the implementation class information of the new cache library is registered in the new library file. The registration principle is the same as above and will not be repeated here. This method can support the expansion of multiple cache libraries, facilitate the addition of other new cache libraries in the future, and ensure that the access of new cache libraries will not affect the operation of the existing system.
[0047] The Metrics framework is integrated into the unified cache interface. The Metrics framework includes core classes, in which the required performance indicators are set, such as interface time consumption, access frequency, cache hit rate, response time, etc. During the execution of the target cache function, the Metrics framework automatically collects and records the corresponding performance data according to the performance indicators, and saves it to the monitoring database (such as ElasticSearch). The performance data is visualized through the Grafana panel for easy viewing by users.
[0048] In summary, this method reduces development complexity and maintenance costs by providing a unified interface and shielding the underlying implementation differences. Developers do not need to write multiple sets of code, and only need to adjust the configuration to adapt to different deployment scenarios. At the same time, by configuring dynamic switching of memory cache and distributed cache, the system can flexibly adapt to single-node and multi-node deployment requirements, improve the flexibility and scalability of the system, and support the introduction of new cache technologies in the future to ensure the expansion capabilities of the system in continuous evolution. In addition, the dynamic switching mechanism and runtime configuration adjustment capabilities reduce the complexity of operation and maintenance, reduce the technical requirements for operation and maintenance personnel, simplify the cache policy change process, and improve the system operation and maintenance efficiency. In terms of resource usage, this solution effectively reduces resource waste by flexibly switching cache modes, especially in small-scale scenarios, avoiding the additional hardware and operation and maintenance costs brought by the use of distributed cache.
[0049] Reference Figure 4 The present disclosure provides an adaptive cache system, comprising: A determination module 101 is used to determine a target cache type and a target storage space based on a business scenario; A loading module 102, used to load a target cache library to a target device based on a target cache type; A construction module 103 is used to construct a unified interface, which encapsulates multiple cache functions; A response module 104, configured to determine a target cache function from a plurality of cache functions in response to a call of the unified interface by the application layer; The execution module 105 is used to execute the target cache function on the target storage space by calling the target cache library.
[0050] The various variations and specific examples of the adaptive caching method provided above are also applicable to the adaptive caching system provided in the present disclosure. Through the above detailed description of the adaptive caching method, those skilled in the art can clearly understand the implementation method of the adaptive caching system. For the sake of brevity of the specification, it will not be described in detail here.
[0051] The computer device according to the embodiment of the present disclosure includes a memory and a processor. The memory is used to store non-temporary computer-readable instructions. Specifically, the memory may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc.
[0052] The processor may be a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities, and may control other components in the computer device to perform desired functions. In one embodiment of the present disclosure, the processor is used to run the computer-readable instructions stored in the memory, so that the computer device performs all or part of the steps of the adaptive caching method of each embodiment of the present disclosure.
[0053] Those skilled in the art should be able to understand that in order to solve the technical problem of how to obtain a good user experience, the present embodiment may also include well-known structures such as a communication bus and an interface, and these well-known structures should also be included in the protection scope of the present disclosure.
[0054] like Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure is shown, which is a schematic diagram of the structure of a computer device suitable for implementing the embodiment of the present disclosure. Figure 5 The computer device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0055] like Figure 5 As shown, the computer device may include a processor (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the computer device are also stored. The processor, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0056] Typically, the following devices can be connected to the I / O interface: input devices such as sensors or visual information acquisition devices; output devices such as display screens; storage devices such as tapes, hard disks, etc.; and communication devices. The communication device can allow the computer device to communicate with other devices (such as edge computing devices) wirelessly or by wire to exchange data. Figure 5A computer device having various devices is shown, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.
[0057] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processor, all or part of the steps of the adaptive caching method of an embodiment of the present disclosure are executed.
[0058] For detailed description of this embodiment, reference may be made to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.
[0059] According to the computer-readable storage medium of the embodiment of the present disclosure, non-transitory computer-readable instructions are stored thereon. When the non-transitory computer-readable instructions are executed by a processor, all or part of the steps of the adaptive cache method of each embodiment of the present disclosure are executed.
[0060] The above-mentioned computer-readable storage media include, but are not limited to: optical storage media (e.g., CD-ROM and DVD), magneto-optical storage media (e.g., MO), magnetic storage media (e.g., magnetic tape or mobile hard disk), media with built-in rewritable non-volatile memory (e.g., memory card) and media with built-in ROM (e.g., ROM box).
[0061] For detailed description of this embodiment, reference may be made to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.
[0062] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.
[0063] In the present disclosure, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. The block diagrams of the devices, devices, equipment, and systems involved in the present disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagram. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including", "comprising", "having", etc. are open words, referring to "including but not limited to", and can be used interchangeably with them. The words "or" and "and" used here refer to the words "and / or" and can be used interchangeably with them, unless the context clearly indicates otherwise. The words "such as" used here refer to the phrase "such as but not limited to", and can be used interchangeably with them.
[0064] Additionally, as used herein, "or" used in a list of items beginning with "at least one" indicates a separate list, so that, for example, a list of "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "exemplary" does not mean that the example described is preferred or better than other examples.
[0065] It should also be noted that in the system and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0066] Various changes, substitutions, and modifications of the techniques described herein may be made without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of the present disclosure is not limited to the specific aspects of the processes, machines, manufactures, compositions of events, means, methods, and actions described above. Currently existing or later to be developed processes, machines, manufactures, compositions of events, means, methods, or actions that perform substantially the same functions or achieve substantially the same results as the corresponding aspects described herein may be utilized. Thus, the appended claims include such processes, machines, manufactures, compositions of events, means, methods, or actions within their scope.
[0067] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0068] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. An adaptive caching method, characterized in that: include: Determine the target cache type and target storage space based on the business scenario; Based on the target cache type, loading the target cache library into the target device; Setting a unified interface, encapsulating multiple cache functions in the unified interface; Obtain the operation interfaces of two or more cache libraries; Build adapters for each cache library; Using the adapter to map the unified interface to the operation interface of the corresponding cache library; In response to the application layer calling the unified interface, determining a target cache function from a plurality of cache functions; The target cache function is performed on the target storage space by calling the target cache library.
2. The adaptive caching method according to claim 1, characterized in that: The step of loading a target cache library to a target device based on the target cache type includes: Setting cache mode parameters in a configuration file of the application according to the target cache type; Based on the cache mode parameters, a target cache library is loaded into the target device.
3. The adaptive caching method according to claim 1, characterized in that: The determining of the target cache type and the target storage space based on the business scenario includes: Based on the business scenario, determine two or more different target cache types and target storage spaces; The step of loading a target cache library to a target device based on the target cache type includes: Two or more different cache mode parameters are set in the configuration file of the application according to two or more different target cache types; Based on two or more different cache mode parameters, two or more different target cache libraries are loaded into the target device.
4. The adaptive caching method according to claim 1, characterized in that: The multiple cache functions include a cache mechanism and a cache operation API; wherein the cache mechanism includes at least one of clearing cache, cache expiration time, cache maximum capacity and invalidation callback; the cache operation API includes at least one of adding cache, querying cache, invalidating cache, updating cache, querying cache size and querying whether cache exists.
5. The adaptive caching method according to claim 4, characterized in that: Also includes: The cache mechanism is configured through a preset external configuration file, and the external configuration file adopts the SpringBootYaml format; Monitor changes in the external configuration file, and when the external configuration file is updated, obtain a new cache mechanism configuration; The settings of the target cache library are updated based on the new cache mechanism configuration.
6. The adaptive caching method according to claim 1, characterized in that: Create two or more library files in the specified directory; Register the implementation class information of two or more preset cache libraries into different library files; When adding a new cache library, create a new library file in the specified directory; Register the implementation class information of the new cache library into the new library file.
7. The adaptive caching method according to claim 1, characterized in that: Integrate the Metrics framework into the unified interface; Using the Metrics measurement framework to collect performance data when the target cache function is executed; The performance data is visually displayed.
8. A computer device, characterized in that: The computer device comprises: 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 so that the at least one processor can execute the adaptive caching method described in any one of claims 1-7.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the adaptive caching method described in any one of claims 1-7.
10. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
A cache middleware-based normalized processing method and apparatus
CN109271139A
Cache method and device based on Caffeine optimization
CN116955213A
Data processing method and device, equipment and storage medium
CN117807115A
Type server caching the proxy / stub generation
US20060259540A1