Search

CN-115827049-B - Configuration-based cache switching method, electronic equipment and storage medium

CN115827049BCN 115827049 BCN115827049 BCN 115827049BCN-115827049-B

Abstract

The embodiment of the invention discloses a configuration-based cache switching method which is applicable to a cache operation mode of spring notes or codes, and comprises a custom configuration file, a cache control module and a cache control module, wherein the configuration file comprises a cache definition type; and automatically loading the cache operation technical component into an item or packaging a cache operation inlet so that codes call the cache operation technical component through the cache operation inlet. According to the configuration-based cache free switching scheme provided by the embodiment of the invention, the limitation of a use scene is reduced and the development cost of cache switching is also reduced aiming at the cache operation mode of spring annotation. Aiming at the cache operation mode of the code, the embodiment of the invention can meet the cache switching requirement and reduce the time cost of cache switching development.

Inventors

  • LI MINGCHENG
  • LI JIAN
  • Cheng Zhuguo

Assignees

  • 银雁科技服务集团股份有限公司

Dates

Publication Date
20260512
Application Date
20221124

Claims (8)

  1. 1. The configuration-based cache switching method is characterized by being suitable for a cache operation mode of spring annotation, and comprises the following steps: the method comprises the steps of customizing a configuration file, wherein the configuration file comprises a cache definition type; Selecting a target cache manager according to the configuration file, thereby determining a cache operation technical component; automatically loading the cache operation technology component into an item; The target cache manager comprises a redis cache manager and a memory cache manager, and the target cache manager is selected according to the configuration file, and specifically comprises the following steps: Inheriting the AbstractCacheManager types of spring and rewriting getCache methods in the AbstractCacheManager types, wherein the getCache method in the AbstractCacheManager types is characterized in that a specific CacheManager is selected according to a self-defined configuration file, and specific caching operation is processed by the specific CacheManager; and selecting a target cache manager according to the getCache method of the configuration file and the rewriting.
  2. 2. The cache switching method as claimed in claim 1, wherein said target cache manager comprises a DB cache manager, and selecting the target cache manager according to said configuration file comprises: Inheriting the AbstractCacheManager types of spring and rewriting getCache methods in the AbstractCacheManager types, wherein the getCache method in the AbstractCacheManager types is characterized in that a specific CacheManager is selected according to a self-defined configuration file, and specific caching operation is processed by the specific CacheManager; Defining a cache implementation class of a database; And selecting a target cache manager according to the configuration file, the rewritten getCache method and the cache implementation class.
  3. 3. The cache switching method according to claim 1 or 2, wherein the cache operation technology component is automatically loaded in an item, specifically comprising: defining an automatic configuration class and configuring the automatic configuration class into a spring.manufacturers file; the cache manipulation technique component is automatically loaded in the item by means of an automatic registration mechanism of spring.
  4. 4. An electronic device comprising a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory being interconnected, wherein the memory is adapted to store a computer program comprising program instructions, the processor being configured to invoke the program instructions to perform the method steps of claim 3.
  5. 5. A computer readable storage medium storing a computer program comprising program instructions, characterized in that the program instructions when executed by a processor implement the method steps of claim 3.
  6. 6. The configuration-based cache switching method is characterized by being suitable for a cache operation mode of codes and comprising the following steps of: the method comprises the steps of customizing a configuration file, wherein the configuration file comprises a cache definition type; Selecting a target cache manager according to the configuration file, thereby determining a cache operation technical component; the target cache manager comprises a redis cache manager and a memory cache manager, and the target cache manager is selected according to the configuration file and specifically comprises the following steps: Inheriting the AbstractCacheManager types of spring and rewriting getCache methods in the AbstractCacheManager types, wherein the getCache method in the AbstractCacheManager types is characterized in that a specific CacheManager is selected according to a self-defined configuration file, and specific caching operation is processed by the specific CacheManager; and selecting a target cache manager according to the getCache method of the configuration file and the rewriting.
  7. 7. The method for switching cache as recited in claim 6, wherein encapsulating the cache operation entry specifically comprises: And uniformly packaging the cache operation classes and providing a uniform cache operation inlet.
  8. 8. An electronic device comprising a processor, an input device, an output device and a memory, the processor, the input device, the output device and the memory being interconnected, wherein the memory is adapted to store a computer program comprising program instructions, the processor being configured to invoke the program instructions to perform the method steps of claim 7.

Description

Configuration-based cache switching method, electronic equipment and storage medium Technical Field The present invention relates to the field of computer technologies, and in particular, to a configuration-based cache switching method, an electronic device, and a storage medium. Background There are two main ways to use caching in project applications: The first is that cache annotation @ Cacheable provided by spring; second, the cache is operated directly by code, such as operation redes cache REDISTEMPLATE. However, the two cache operation modes have the following advantages and disadvantages: The first method is to use the buffer annotation operation buffer, which has the advantages of convenient use, only needs to be added to the specific service method, and can assign different buffers for different service methods. The method has the defects that the annotation is loaded on the business method, the whole result of the business method can be cached, the caching can not be operated in the business method, and the use scene is limited. And if the project needs to be subjected to cache technology switching, the code needs to be changed, and then the service is reissued according to the processes of compiling, packaging, deploying and the like. The second method is to use codes to operate the buffer memory, which has the advantage of high degree of freedom, and can operate different buffer memories in one business method at the same time, thereby meeting more business scenes. This approach is also the most widely used method of cache operation. The method has the defects of high coupling degree, mixed operation and business of the cache, different API methods for operating different cache technologies and independent encoding of different cache technologies. Therefore, the project switching caching technology has higher cost, all codes need to be rewritten, and the service is reissued after the processes of testing, compiling, packing, deploying and the like are executed, so that the requirement change can not be met rapidly. Disclosure of Invention In view of the technical drawbacks mentioned in the background art, an object of an embodiment of the present invention is to provide a configuration-based cache switching method, an electronic device, and a storage medium. In order to achieve the above objective, in a first aspect, an embodiment of the present invention provides a configuration-based cache switching method, which is applicable to a caching operation mode of a spring annotation. The method comprises the following steps: the method comprises the steps of customizing a configuration file, wherein the configuration file comprises a cache definition type; Selecting a target cache manager according to the configuration file, thereby determining a cache operation technical component; And automatically loading the cache operation technology component into the project. As a specific implementation manner of the present application, the target cache manager includes a redis cache manager and a memory cache manager, and selecting the target cache manager according to the configuration file specifically includes: Inheriting AbstractCacheManager classes and rewriting getCache methods in AbstractCacheManager classes; and selecting a target cache manager according to the getCache method of the configuration file and the rewriting. Optionally, as another specific implementation manner of the present application, the target cache manager includes a DB cache manager, and the selecting the target cache manager according to the configuration file specifically includes: Inheriting AbstractCacheManager classes and rewriting getCache methods in AbstractCacheManager classes; Defining a cache implementation class of a database; And selecting a target cache manager according to the configuration file, the rewritten getCache method and the cache implementation class. Further, as a specific implementation manner of the present application, the cache operation technology component is automatically loaded in an item, which specifically includes: defining an automatic configuration class and configuring the automatic configuration class into a spring.manufacturers file; the cache operation component is automatically loaded in the item by means of an automatic registration mechanism of spring. In a second aspect, an embodiment of the present invention further provides an electronic device, including a processor, an input device, an output device, and a memory, where the processor, the input device, the output device, and the memory are connected to each other, and the memory is configured to store a computer program, where the computer program includes program instructions, and where the processor is configured to invoke the program instructions to perform the method steps according to the first aspect. In a third aspect, embodiments of the present invention provide a computer-readable storage medium storing a computer prog