Method and device for realizing cluster cache synchronization processing based on database under xinxin environment, processor and readable storage medium thereof
By using a database as a cache middleware layer in a domestic IT innovation environment and customizing cache version stamps and configuration classes, cache synchronization was achieved, solving the cache synchronization problem when enterprise applications migrate to an architecture without Redis, and ensuring cache consistency and system stability in a high-concurrency environment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-03
- Publication Date
- 2026-04-07
AI Technical Summary
In the context of domestic IT innovation, when enterprise applications migrate to an architecture without Redis, existing technologies need to delete or replace the cache, which leads to increased database pressure, request latency, and project migration risks, affecting high availability and user experience.
A database is used as a caching middleware layer. Custom cache version stamps and configuration classes, as well as custom cache implementation and management classes, are used. Cache synchronization is achieved by comparing the version stamps in memory and the database, avoiding the need to modify business code.
It enables seamless replacement of Redis in a domestic IT innovation environment, reduces database pressure, ensures cache synchronization in high-concurrency environments, and supports smooth migration of enterprise applications.
Smart Images

Figure CN116414869B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software technology, and more particularly to the field of information technology innovation environment technology. Specifically, it refers to a method, apparatus, processor, and computer-readable storage medium for implementing cluster cache synchronization processing based on a database under an information technology innovation environment. Background Technology
[0002] In the rapidly developing internet era, the surge in massive network requests has made reducing request latency and increasing system throughput a key focus in the industry, while ensuring high service availability and a superior user experience. Caching technology effectively reduces the load on the business side, making it one of the most effective techniques for solving this problem. The Spring Cache framework, released in Spring 3.1, encapsulates and abstracts the use of caching.
[0003] With the accelerated implementation of domestic IT innovation practices in recent years and the continuous release of domestic IT innovation demands, enterprises are increasingly migrating their applications to the domestic IT innovation environment. Therefore, the need to synchronize cached data in a cluster without Redis is even stronger.
[0004] How to ensure the reliable operation of business applications without intrusion, and how to guarantee the smooth migration of numerous business applications running on the original architecture to the domestically developed (IT) architecture, ensuring stable operation in the IT environment, achieving good operation of business systems after migration, and improving the smoothness of IT acceptance testing? At the same time, how to ensure that applications in the IT environment can meet the performance requirements of high concurrency requests and continuous business growth, achieving good operation—these are all urgent problems that need to be solved.
[0005] If your project already uses Spring Cache + Redis for caching, and you need to migrate to a domestic IT environment or can no longer use Redis...
[0006] In this situation, there are currently only two options for migrating the business system:
[0007] (1) Remove the cache by deleting all annotations in Spring Cache.
[0008] (2) Replace Spring Cache with other caching implementations.
[0009] Removing caching from the project will increase database pressure and request latency, severely impacting service availability and user experience.
[0010] Without using Spring Cache, the project would have to modify its business logic to meet the requirements, which would increase the workload of project migration. Modifying the business logic would also bring risks to project deployment, affecting the progress of the project's migration to the domestic IT environment and causing great inconvenience to the enterprise. Summary of the Invention
[0011] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method, apparatus, processor and computer-readable storage medium for cluster cache synchronization processing based on database in the context of information technology innovation, which solves the cache synchronization problem in high-concurrency environments such as multi-node deployment or multi-threaded execution.
[0012] To achieve the above objectives, the present invention provides a method, apparatus, processor, and computer-readable storage medium for cluster cache synchronization processing based on a database in a domestic IT innovation environment, as follows:
[0013] The main feature of this method for implementing cluster cache synchronization based on a database in the context of domestic IT innovation is that the method includes the following steps:
[0014] (1) Use a database as a cache intermediate layer and initialize the cache table structure in the application's database;
[0015] (2) Customize the cache version stamp;
[0016] (3) Custom cache configuration switch class and cache attribute configuration class;
[0017] (4) Custom cache implementation classes inherit from ConcurrentMapCache cache implementation classes and override the parent class methods;
[0018] (5) Custom cache implementation management class inherits from ConcurrentMapCacheManager cache management class and overrides createConcurrentMapCache method.
[0019] Preferably, step (2) specifically includes:
[0020] Generate a UUID from the application configuration cache information, use it as a version stamp for the cache, and then perform custom processing on it.
[0021] Preferably, step (3) specifically includes:
[0022] Customize your cache configuration switch class as follows: Inherit from CachingConfigurerSupport and override the cacheManager() method;
[0023] Customize your cache property configuration class as follows: Use the @ConfigurationProperties annotation to customize the cache property configuration class, and configure the cache name, cache size, and expiration time.
[0024] Preferably, step (4) specifically involves customizing the cache implementation class in the following manner:
[0025] In query scenarios, the cache is retrieved from memory based on the cache key;
[0026] If the cache does not exist in memory, the business data is queried. After the business data is queried, the record of this cache key is queried in the cache table. If the cache record does not exist in the cache table, a version stamp is generated and inserted into the cache table. If the cache record exists in the cache table, the cache version stamp is queried. Finally, the business data, cache key and version stamp are stored in memory.
[0027] If the cached data exists in memory, first query the data in the cache table, and compare the version stamp cached in memory with the version stamp in the database. If the version stamps are the same, directly return the data in memory. If the version stamps are different, query the business data and return it. At the same time, store the business data, the version stamp cached in the database, and the cache key in memory.
[0028] Preferably, step (4) rewrites the parent class method in the following manner:
[0029] In the modification scenario, first delete the data in the memory cache, then delete the data in the cache table, and finally modify the business data; and override the parent class lookup(), get(), put(), putIfAbsent() or evict() methods;
[0030] Among them, lookup() is the lookup cache method, get() is the get cache method, put() is the put cache method, putIfAbsent() is the atomic execution of the put cache operation, and evict() is the evict cache method.
[0031] The main feature of this device for cluster cache synchronization processing based on a database in the context of domestic IT innovation is that the device includes:
[0032] A processor is configured to execute computer-executable instructions;
[0033] The memory stores one or more computer-executable instructions, which, when executed by the processor, implement the various steps of the method for cluster cache synchronization processing based on a database in the context of information technology innovation described above.
[0034] The processor for implementing cluster cache synchronization processing based on a database in the context of domestic IT innovation is characterized by being configured to execute computer-executable instructions. When these computer-executable instructions are executed by the processor, they implement the various steps of the method for implementing cluster cache synchronization processing based on a database in the context of domestic IT innovation.
[0035] The main feature of this computer-readable storage medium is that it stores a computer program that can be executed by a processor to implement the various steps of the method for cluster cache synchronization processing based on a database in the context of information technology innovation.
[0036] This invention employs a method, apparatus, processor, and computer-readable storage medium for cluster cache synchronization based on a database in a domestic IT innovation environment. By using the database as a cache intermediate layer, a custom cache implementation of the ConcurrentMapCache class is used. The value and key in the @Cacheable annotation generate the primary key of the cache according to rules, and a version stamp of the corresponding cache key is also generated. The version stamp of the cache stored in memory is compared with the version stamp of the same key in the database. Based on the comparison result, the corresponding data is updated. In query scenarios, if the version stamps are the same, the cache in memory is used; if the version stamps are different, the cached data in memory is discarded, and the business data is retrieved from the database again, updating the memory cache along with the version stamp cached in the database. In data modification scenarios, the cache version stamp is regenerated to update the cached data in memory, and the version stamp cached in the database is also updated. This solves the cache synchronization problem in high-concurrency environments such as multi-node deployment or multi-threaded execution, enabling enterprise applications to seamlessly replace Redis with Spring Cache without modifying business code. Under the national policy of vigorously promoting the development and localization of the domestic IT innovation industry, this invention supports the smooth migration of enterprise applications to domestic IT innovation environments. Attached Figure Description
[0037] Figure 1 This is a flowchart of the method for implementing cluster cache synchronization processing based on a database in the context of information technology innovation. Detailed Implementation
[0038] To more clearly describe the technical content of the present invention, the following description is provided in conjunction with specific embodiments.
[0039] Before describing the embodiments of the present invention in detail, it should be noted that, in the following, the terms “comprising,” “including,” or any other variations are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed or inherent to such process, method, article, or apparatus.
[0040] Please see Figure 1 As shown, this method for implementing cluster cache synchronization based on a database in a domestic IT innovation environment includes the following steps:
[0041] (1) Use a database as a cache intermediate layer and initialize the cache table structure in the application's database;
[0042] (2) Customize the cache version stamp;
[0043] (3) Custom cache configuration switch class and cache attribute configuration class;
[0044] (4) Custom cache implementation classes inherit from ConcurrentMapCache cache implementation classes and override the parent class methods;
[0045] (5) Custom cache implementation management class inherits from ConcurrentMapCacheManager cache management class and overrides createConcurrentMapCache method.
[0046] In a preferred embodiment of the present invention, step (2) specifically comprises:
[0047] Generate a UUID from the application configuration cache information, use it as a version stamp for the cache, and then perform custom processing on it.
[0048] In a preferred embodiment of the present invention, step (3) specifically comprises:
[0049] Customize your cache configuration switch class as follows: Inherit from CachingConfigurerSupport and override the cacheManager() method;
[0050] Customize your cache property configuration class as follows: Use the @ConfigurationProperties annotation to customize the cache property configuration class, and configure the cache name, cache size, and expiration time.
[0051] In a preferred embodiment of the present invention, step (4) specifically involves customizing the cache implementation class as follows:
[0052] In query scenarios, the cache is retrieved from memory based on the cache key;
[0053] If the cache does not exist in memory, the business data is queried. After the business data is queried, the record of this cache key is queried in the cache table. If the cache record does not exist in the cache table, a version stamp is generated and inserted into the cache table. If the cache record exists in the cache table, the cache version stamp is queried. Finally, the business data, cache key and version stamp are stored in memory.
[0054] If the cached data exists in memory, first query the data in the cache table, and compare the version stamp cached in memory with the version stamp in the database. If the version stamps are the same, directly return the data in memory. If the version stamps are different, query the business data and return it. At the same time, store the business data, the version stamp cached in the database, and the cache key in memory.
[0055] In a preferred embodiment of the present invention, step (4) is rewritten as follows:
[0056] In the modification scenario, first delete the data in the memory cache, then delete the data in the cache table, and finally modify the business data; and override the parent class lookup(), get(), put(), putIfAbsent() or evict() methods;
[0057] Among them, lookup() is the lookup cache method, get() is the get cache method, put() is the put cache method, putIfAbsent() is the atomic execution of the put cache operation, and evict() is the evict cache method.
[0058] In practical applications, the specific implementation steps of this technical solution are as follows:
[0059] I. Using a database as a caching middleware layer
[0060] A database is used as a caching middleware layer, and the cache table structure is initialized in the application's database.
[0061] The cache table initialization statement is as follows:
[0062] CREATE TABLE CLUSTER_DATA_CACHE (
[0064] PID varchar(32) NOT NULL COMMENT 'Primary Key',
[0065] CACHE_NAME varchar(255) NOT NULL,
[0066] CACHE_KEY varchar(255) NOT NULL,
[0067] VERSION_NUM varchar(60) NOT NULL ,
[0068] CREATE_TIME datetime(0) NOT NULL,
[0069] UPDATE_TIME datetime(0) NOT NULL,
[0070] EXPIRED_TIME datetime(0) NOT NULL,
[0071] PRIMARY KEY (PID) );
[0073] Where PID is the database primary key, CACHE_NAME is the cache name, CACHE_KEY is the cache key, VERSION_NUM is the cache version stamp, CREATE_TIME is the cache creation time, UPDATE_TIME is the cache modification time, and EXPIRED_TIME is the cache expiration time.
[0074] II. Custom Cache Version Stamp
[0075] The version stamp is generated by randomly generating a UUID.
[0076] The specific code is as follows:
[0077] public static String getUUID() {
[0078] ThreadLocalRandom random = ThreadLocalRandom.current();
[0079] long lsb = random.nextLong();
[0080] long msb = random.nextLong();
[0081] byte[] buf = new byte
[32] ;
[0082] formatUnsignedLong(lsb, buf, 20, 12);
[0083] formatUnsignedLong(lsb>>>48, buf, 16, 4);
[0084] formatUnsignedLong(msb, buf, 12, 4);
[0085] formatUnsignedLong(msb>>>>16, buf, 8, 4);
[0086] formatUnsignedLong(msb>>>32, buf, 0, 8);
[0087] return new String(buf, StandardCharsets.UTF_8);
[0088] }
[0089] III. Custom Cache Switch Configuration Class
[0090] The custom cache switch configuration class is the switch for selecting a specific cache mode. This method returns a Bean object of our custom CacheManager.
[0091] The specific switch configuration is as follows:
[0092]
[0093] Open the application's application.properties or application.yaml configuration file and add the caching configuration switch information;
[0094] The specific code implementation is as follows:
[0095] @Bean
[0096] @Override
[0097] @ConditionalOnMissingBean
[0098] public CacheManager cacheManager(){
[0099] ClusterOnceRequestChecker checker = newClusterOnceRequestChecker();
[0100] return new ClusterDataCacheManager(checker,dataModelDao,config);
[0101] }
[0102] IV. Custom Cache Attribute Configuration Class
[0103] Use the @ConfigurationProperties annotation to customize the cache property configuration class, which supports configuring some cache property information, such as cache name, cache capacity, and expiration time.
[0104] The specific configuration is as follows:
[0105]
[0106] The specific implementation of clearing expired cache is as follows:
[0107] @SuppressWarnings("rawtypes")
[0108] private void clearDaemonThread() {
[0109] executorService = Executors.newSingleThreadScheduledExecutor(runnable ->{
[0110] Thread thread = new Thread(runnable, "Thread:" +this.getName() + "-cache-clear-daemon");
[0111] thread.setDaemon(true);
[0112] return thread;
[0113] });
[0114] / / Triggered once at intervals; if the capacity is full, an expiration process is performed.
[0115] executorService.scheduleAtFixedRate(() ->{
[0116] / / Only clean up expired records in the database, add an exclusive lock on the key to ensure that only one thread executes.
[0117] if (((ConcurrentLinkedHashMap) super.getNativeCache()).weightedSize()>= this.capacity) {
[0118] try {
[0119] dataModelDao.clearExpiredRecord();
[0120] } catch (Exception e) {
[0121] log.warn("cache-clear-daemon");
[0122] }
[0123] }
[0124] , 1, clusterCacheConfig.getClearDaemonDelayTime(), TimeUnit.SECONDS);
[0125] }
[0126] The specific implementation of the cache expiration time is as follows:
[0127] private DataModel create(String cacheKey, String version) {
[0128] Date date = new Date();
[0129] LocalDateTime expiredTime = null;
[0130] if (clusterCacheConfig.getCacheExpiredTime().containsKey(this.getName())) {
[0131] expiredTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()
[0132] .plusSeconds(clusterCacheConfig.getExpiredTimeByCache(this.getName()));
[0133] }
[0134] DataModel dataModel = new DataModel(this.getName(), cacheKey,version, date, date,
[0135] null == expiredTime ? null : Date.from(expiredTime.atZone(ZoneId.systemDefault()).toInstant()));
[0136] return dataModel;
[0137] }
[0138] V. Custom Cache Implementation Class
[0139] The cache implementation class is the most core class, mainly involving two scenarios.
[0140] In the query usage scenario: First, query the cache from memory based on the cache key. (1) If there is no cache in memory, it means that the cache is not cached for the first time at this node. Then, query the business data. After querying the business data, query the record of this cache key in the cache table. If there is no cache record in the cache table, generate a version stamp and insert it into the cache table. If there is a cache record in the cache table, query the cache version stamp. Finally, store the business data, cache key and version stamp in memory. (2) If there is cache data in memory, first query the data in the cache table. Compare the version stamp in memory with the version stamp in the database. If the version stamp is the same, return the data in memory directly without querying the database. If the version stamp is different, query the business data and return it. At the same time, store the business data, the version stamp cached in the database and the cache key in memory.
[0141] In the modification scenario: first delete the data in the memory cache, then delete the data in the cache table, and finally modify the business data.
[0142] The main methods involved are lookup(), get(), put(), putIfAbsent(), and evict().
[0143] @Override
[0144] protected Object lookup(Object key) {
[0145] Object storeValue = checkCacheVersion(key);
[0146] return null == storeValue ? null : ((CacheModel) storeValue).getCache();
[0147] }
[0148] @SuppressWarnings("unchecked")
[0149] @Override
[0150] public <t>T get(Object key, Callable <t>valueLoader) {
[0151] Object storeValue = checkCacheVersion(key);
[0152] if (storeValue == null) {
[0153] / / Here, null indicates two possibilities: 1. The local cache has no value; 2. The cache has expired and has been cleared, requiring reloading.
[0154] CacheModel threadLocalObject = RequestCacheContext
[0155] .getCacheModel(this.checker.buildOnceCheckKey(this.getName(), key));
[0156] CacheModel fromStoreValue = (CacheModel) fromStoreValue(super.getNativeCache().computeIfAbsent(key, k ->{
[0157] try {
[0158] T call = valueLoader.call();
[0159] CacheModel cacheModel = new CacheModel();
[0160] cacheModel.setCacheKey(StringUtils.isEmpty(key)?"":String.valueOf(key));
[0161] cacheModel.setCache(call);
[0162] if (null == threadLocalObject) {
[0163] / / No value found locally, needs to be queried from the database.
[0164] DataModel newestCache = dataModelDao.query(this.getName(), cacheModel.getCacheKey());
[0165] if (null != newestCache) {
[0166] if (null != newestCache.getExpiredTime()
[0167] &&newestCache.getExpiredTime().before(new Date())) {
[0168] / / Expired
[0169] dataModelDao.update(expiredProcess(cacheModel));
[0170] } else {
[0171] cacheModel.setVersion(newestCache.getVersionNum());
[0172] cacheModel.setExpiredDate(newestCache.getExpiredTime());
[0173] }
[0174] cacheModel.setId(newestCache.getPid());
[0175] } else {
[0176] / / There is no record in the database, create a new record
[0177] DataModel dataModel = expiredProcess(cacheModel);
[0178] cacheModel.setId(dataModel.getPid());
[0179] dataModelDao.insert(dataModel);
[0180] }
[0181] } else {
[0182] if (threadLocalObject.isExpired()) { / / Check if it has expired, update the database.
[0183] dataModelDao.update(expiredProcess(cacheModel));
[0184] } else {
[0185] / / Local version is inconsistent, update the version
[0186] cacheModel.setVersion(threadLocalObject.getVersion());
[0187] cacheModel.setExpiredDate(threadLocalObject.getExpiredDate());
[0188] cacheModel.setId(threadLocalObject.getId());
[0189] }
[0190] }
[0191] return toStoreValue(cacheModel);
[0192] } catch (Exception ex) {
[0193] throw new ValueRetrievalException(key,valueLoader, ex);
[0194] }
[0195] }));
[0196] return (T) fromStoreValue.getCache();
[0197] } else {
[0198] CacheModel fromStoreValue = (CacheModel)super.fromStoreValue(storeValue);
[0199] return (T) fromStoreValue.getCache();
[0200] }
[0201] }
[0202] @Override
[0203] public void put(Object key, Object value) {
[0204] super.put(key, checkAndput(key, value));
[0205] }
[0206] @Override
[0207] public ValueWrapper putIfAbsent(Object key, Object value) {
[0208] return super.putIfAbsent(key, checkAndput(key, value));
[0209] }
[0210] @Override
[0211] public void evict(Object key) {
[0212] Object cacheModel = super.lookup(key);
[0213] if (null != cacheModel) {
[0214] dataModelDao.delete(((CacheModel) cacheModel).getId());
[0215] super.evict(key);
[0216] } else {
[0217] / / Only local modifications are made without caching; the cache version needs to be updated based on cacheName and cacheKey.
[0218] dataModelDao.deleteByKey(getName(), key.toString());
[0219] }
[0220] }
[0221] private Object checkCacheVersion(Object key) {
[0222] Object storeValue = super.lookup(key);
[0223] if (storeValue != null) {
[0224] Object value = fromStoreValue(storeValue);
[0225] / / One request, check version information. Each key can be checked at most once.
[0226] if (this.checker.check(this.getName(), key)) {
[0227] / / If the version is incorrect, clear the local cache.
[0228] CacheModel threadLocalObject = RequestCacheContext
[0229] .getCacheModel(this.checker.buildOnceCheckKey(this.getName(),
[0230] StringUtils.isEmpty(key)?"":key));
[0231] if (checkVersion(value, threadLocalObject)) {
[0232] super.evict(key); / / If the key has expired, the version is inconsistent, or the database record has been deleted, clear the local cache and recreate the cache.
[0233] return null;
[0234] }
[0235] }
[0236] }
[0237] return storeValue;
[0238] }
[0239] The entire caching logic involves database operations. The cache update module uses an in-memory ConcurrentHashMap, and database operations are performed using JdbcTemplate. The application can use it without adding any additional dependencies. The specific code is as follows:
[0240] / / Update cache
[0241] public String update(DataModel model, List <object>params) {
[0242] StringJoiner sj = new StringJoiner(" ");
[0243] sj.add("UPDATE CLUSTER_DATA_CACHE SET");
[0244] if (null != model.getExpiredTime()) {
[0245] sj.add("EXPIRED_TIME = ?,");
[0246] params.add(model.getExpiredTime());
[0247] } else if (null != model.getVersionNum()) {
[0248] sj.add("VERSION_NUM = ?,");
[0249] params.add(model.getVersionNum());
[0250] }
[0251] sj.add("UPDATE_TIME = ?");
[0252] params.add(new Date());
[0253] sj.add("WHERE CACHE_NAME = ? AND CACHE_KEY = ?");
[0254] params.add(model.getCacheName());
[0255] params.add(model.getCacheKey());
[0256] return sj.toString();
[0257] };
[0258] / / Insert cache
[0259] public String insert(DataModel model) {
[0260] return "INSERT INTO CLUSTER_DATA_CACHE VALUES(?,?,?,?,?,?,?)";
[0261] }
[0262] / / Delete cache
[0263] public String delete(){
[0264] return "DELETE FROM CLUSTER_DATA_CACHE WHERE PID = ?";
[0265] };
[0266] / / Delete cache
[0267] public String deleteByKey(){
[0268] return "DELETE FROM CLUSTER_DATA_CACHE WHERE CACHE_NAME = ?AND CACHE_KEY = ?";
[0269] };
[0270] / / Delete expired cache
[0271] public String expired(){
[0272] return "DELETE FROM CLUSTER_DATA_CACHE WHERE EXPIRED_TIME<=?";
[0273] }
[0274] 6. Custom cache management class
[0275] Inherit from the ConcurrentMapCacheManager cache management class and override the createConcurrentMapCache method.
[0276] The specific implementation is as follows:
[0277] @Override
[0278] protected Cache createConcurrentMapCache(String name) {
[0279] ConcurrentLinkedHashMap<Object, CacheModel>store =
[0280] new ConcurrentLinkedHashMap.Builder<Object, CacheModel>().maximumWeightedCapacity(clusterCacheConfig.getCacheCapacity()).weigher(Weighers.singleton()).build();
[0281] ClusterDataCache clusterDataCache = new ClusterDataCache(name,checker,store,dataModelDao, clusterCacheConfig);
[0282] return clusterDataCache;
[0283] }
[0284] The capacity configuration of each cache is specifically effective here.
[0285] The device for realizing cluster cache synchronization processing based on a database in the Xingcheng environment, wherein the device comprises:
[0286] a processor configured to execute computer executable instructions;
[0287] a memory storing one or more computer executable instructions, which, when executed by the processor, implement each step of the method for realizing cluster cache synchronization processing based on a database in the Xingcheng environment.
[0288] The processor for realizing cluster cache synchronization processing based on a database in the Xingcheng environment, wherein the processor is configured to execute computer executable instructions, and the computer executable instructions, when executed by the processor, implement each step of the method for realizing cluster cache synchronization processing based on a database in the Xingcheng environment.
[0289] The computer readable storage medium, wherein a computer program is stored thereon, and the computer program can be executed by the processor to implement each step of the method for realizing cluster cache synchronization processing based on a database in the Xingcheng environment.
[0290] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.
[0291] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution device.
[0292] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0293] The storage media mentioned above can be read-only memory, disk, or optical disk, etc.
[0294] In the description of this specification, references to terms such as "an embodiment," "some embodiments," "example," "specific example," or "embodiment," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0295] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
[0296] This invention employs a method, apparatus, processor, and computer-readable storage medium for cluster cache synchronization based on a database in a domestic IT innovation environment. By using the database as a cache intermediary layer, a custom cache implementation class, `ConcurrentMapCache`, is used. A primary key for the cache is generated according to rules based on the value and key in the `@Cacheable` annotation, and a version stamp is also generated for the corresponding cache key. The version stamp stored in memory is compared with the version stamps of the same key in the database. Based on the comparison result, the corresponding data is updated. In query scenarios, if the version stamps are the same, the cache in memory is used; if the version stamps are different, the cached data in memory is discarded, and the business data is retrieved from the database again, updating the memory cache along with the version stamp cached in the database. In data modification scenarios, the cache version stamp is regenerated to update the cached data in memory, and the version stamp cached in the database is also updated. This solves the cache synchronization problem in high-concurrency environments such as multi-node deployment or multi-threaded execution, enabling enterprise applications to seamlessly replace Redis with Spring Cache without modifying business code. Under the national policy of vigorously promoting the development and localization of the domestic IT innovation industry, this invention supports the smooth migration of enterprise applications to domestic IT innovation environments.
[0297] In this specification, the invention has been described with reference to specific embodiments thereof. However, it will be apparent that various modifications and variations can be made without departing from the spirit and scope of the invention. Therefore, the specification and drawings should be considered illustrative rather than restrictive.< / object> < / t> < / t>
Claims
1. A method for implementing cluster cache synchronization processing based on a database in a domestically developed information technology environment, characterized in that, The method includes the following steps: (1) Use a database as a cache intermediate layer and initialize the cache table structure in the application's database; (2) Customize the cache version stamp; (3) Custom cache configuration switch class and cache attribute configuration class; (4) Custom cache implementation classes inherit from ConcurrentMapCache cache implementation classes and override the parent class methods; (5) A custom cache management class inherits from the ConcurrentMapCacheManager cache management class and overrides the createConcurrentMapCache method; Step (4) specifically involves customizing the cache implementation class as follows: In query scenarios, the cache is retrieved from memory based on the cache key; If the cache does not exist in memory, the business data is queried. After the business data is queried, the record of this cache key is queried in the cache table. If the cache record does not exist in the cache table, a version stamp is generated and inserted into the cache table. If the cache record exists in the cache table, the cache version stamp is queried. Finally, the business data, cache key and version stamp are stored in memory. If the cached data exists in memory, first query the data in the cache table, and compare the version stamp cached in memory with the version stamp in the database. If the version stamps are the same, directly return the data in memory. If the version stamps are different, query the business data and return it. At the same time, store the business data, the version stamp cached in the database, and the cache key in memory.
2. The method for cluster cache synchronization processing based on a database in a domestically developed information technology environment according to claim 1, characterized in that, The specific steps (2) are as follows: Generate a UUID from the application configuration cache information, use it as a version stamp for the cache, and then perform custom processing on it.
3. The method for cluster cache synchronization processing based on a database in a domestically developed information technology environment according to claim 1, characterized in that, The specific steps (3) are as follows: Customize your cache configuration switch class as follows: Inherit from CachingConfigurerSupport and override the cacheManager() method; Customize your cache property configuration class as follows: Use the @ConfigurationProperties annotation to customize the cache property configuration class, and configure the cache name, cache size, and expiration time.
4. The method for cluster cache synchronization processing based on a database in a domestically developed information technology environment according to claim 1, characterized in that, Step (4) involves overriding the parent class method as follows: In the modification scenario, first delete the data in the memory cache, then delete the data in the cache table, and finally modify the business data; and override the parent class lookup(), get(), put(), putIfAbsent() or evict() methods; Among them, lookup() is the lookup cache method, get() is the get cache method, put() is the put cache method, putIfAbsent() is the atomic execution of the put cache operation, and evict() is the evict cache method.
5. A device for implementing cluster cache synchronization processing based on a database in a domestically developed information technology environment, characterized in that, The device includes: A processor is configured to execute computer-executable instructions; The memory stores one or more computer-executable instructions, which, when executed by the processor, implement the steps of the method for cluster cache synchronization processing based on a database under the information technology innovation environment as described in any one of claims 1 to 4.
6. A processor for implementing cluster cache synchronization processing based on a database in a domestically developed information technology environment, characterized in that, The processor is configured to execute computer-executable instructions, which, when executed by the processor, implement the steps of the method for cluster cache synchronization processing based on a database in the context of domestic IT innovation, as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, It stores a computer program that can be executed by a processor to implement the various steps of the method for cluster cache synchronization processing based on a database in the context of information technology innovation as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Cache data synchronization method and device, equipment and medium
CN111046106A
Extensible cache access method, system and device and storage medium
CN114860212A