Cache management method and device based on distributed entity cache architecture

Through the cache management method based on distributed entity cache architecture, the lack of cache management in high concurrency in existing technologies has been solved, and the sharing and fine particle size control of cache data are realized, and system performance and user experience are improved.

CN119357235APending Publication Date: 2025-01-24ZHONGQI LIANXIN (BEIJING) TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411347937.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

The existing database cache mechanism has problems such as session limit, node memory limit, frequent cache clearance and coarse cache granularity in high concurrency scenarios, resulting in system performance degradation and poor user experience.

Method used

Adopt cache management methods based on distributed entity cache architecture, to generate cache key values ​​through physical ID, physical field fingerprint fingerprints, and application version numbers to achieve cache query and update automatic management, support distributed cache data sharing and fine particle size cache control Essence

Benefits of technology

It improves database processing efficiency, ensures the consistency of data from multiple data sources, reduces cache invalidation and reconstruction frequency, and improves system performance and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357235A_ABST
    Figure CN119357235A_ABST
Patent Text Reader

Abstract

The invention provides a cache management method and device based on a distributed entity cache architecture. The cache management method comprises a cache query method and a cache update method. The method comprises the following steps: initiating a cache query request; generating a cache key value based on the entity class ID, the entity class field fingerprint and the application version number; using the cache key value to query whether corresponding cache data exists in a cache database, and if yes, directly returning the cache data; if not, querying the database to return result data, performing serialization processing on the result data, setting a cache value and expiration time, and writing the result data into a cache database; initiating a cache updating request; generating a cache key value based on the entity class ID, the entity class field fingerprint and the application version number; and executing a cache updating strategy on cache processing in the cache database according to the cache key value, and returning an updating result. The invention provides a distributed entity cache architecture, which realizes automatic cache management of query and update operations, improves the database processing efficiency and ensures the consistency of data of multiple data sources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a cache management method and device based on a distributed entity cache architecture. Background Art

[0002] When multiple users or systems access the same service or resource at the same time, this situation is called "concurrency". In high-concurrency scenarios, the system may encounter a "performance bottleneck", which means that a part of the system, such as the database, network, central processing unit (CPU), etc., cannot handle more load, resulting in overall performance degradation, increased response time, or even system crash. Performance bottlenecks are often the weakest link that limits the system's processing capabilities.

[0003] Cache is a storage mechanism used to temporarily store frequently accessed data for quick access. This data is usually kept in memory, making it much faster to access than storage media such as hard disks. Cache can significantly reduce the number of accesses to the original data source, such as a database, improving the efficiency of data retrieval and the overall performance of the system.

[0004] Caches usually use random access memory (RAM) to store data, and the data access speed of memory is much faster than that of hard disks, even solid state disks (SSDs). The data stored in the database may be located on the hard disk, and each query may involve disk input / output (I / O) operations, which have a long response time. In contrast, the speed of reading data from memory is almost instantaneous, so using cache can greatly improve the data retrieval speed, especially in scenarios that need to handle high concurrent requests.

[0005] In modern software development, improving system response speed and the ability to process large amounts of data is one of the key considerations. Using a cache mechanism is a common way to solve these problems. Especially in high-concurrency scenarios during the peak period of business systems, frequently querying the same data from the database will cause a lot of resource waste and response delays, resulting in a decline in user experience.

[0006] Existing database caching mechanisms, such as MyBatis, implement multi-level caching based on the persistence layer framework. In order to optimize database access performance, MyBatis provides a first-level cache and a second-level cache mechanism. The first-level cache is enabled by default, while the second-level cache needs to be configured. The scope of the first-level cache is limited to a single SqlSession, that is, a database session, which can be regarded as a database transaction. In the same SqlSession, for the same Structured Query Language (SQL) statement and the same query parameters, the database will be queried and the results will be stored in the cache when it is executed for the first time; when the same query is executed for the second time, the data is read directly from the cache, thereby improving query efficiency. However, any update, deletion, or addition operation will cause all caches of the SqlSession to be cleared. At the same time, there are still the following technical defects:

[0007] Session limitation: The validity of the first-level cache is limited to a single SqlSession scope, which means that even if the same query is executed multiple times in different sessions, the cached results cannot be shared, reducing the practicality of the cache.

[0008] Application scenario limitations: In actual applications, especially in user interactions or batch jobs, sessions may be short or different, which greatly reduces the benefits of the first-level cache.

[0009] Node memory limitation: The first-level cache is based on the memory of a single service node, which becomes an obvious shortcoming in microservices and distributed architectures. In this architecture, applications are usually deployed on multiple service instances, and the cache of each instance is independent of each other, making it impossible to share cached data.

[0010] Cache clearing: When any update, delete, or add operation occurs, the MyBatis first-level cache processing strategy is to simply clear the entire SqlSession cache. Although this strategy theoretically guarantees data consistency, it may lead to frequent cache invalidation and reconstruction in actual applications, which not only affects performance but also increases system load.

[0011] Cache granularity: MyBatis's caching mechanism usually caches the entire query result, and does not support finer-grained caching, such as caching at the level of a single entity or attribute. This coarse-grained caching strategy may lead to unnecessary data storage and update overhead. Summary of the invention

[0012] In view of this, an embodiment of the present invention provides a cache management method and device based on a distributed entity cache architecture to eliminate or improve one or more defects existing in the prior art.

[0013] On the one hand, the present invention provides a cache management method based on a distributed entity cache architecture, the cache management method comprising a cache query method and a cache update method;

[0014] The cache query method comprises the following steps:

[0015] Initiate a cache query request;

[0016] Generate cache key value based on entity class ID, entity class field fingerprint and application version number;

[0017] Use the cache key value to query whether there is corresponding cache data in the preset cache database, and if so, directly return the cache data;

[0018] If it does not exist, query the database, return the result data, serialize the result data, set the cache value and expiration time, and write it into the cache database;

[0019] The cache update method comprises the following steps:

[0020] Initiate a cache update request;

[0021] Generate cache key value based on entity class ID, entity class field fingerprint and application version number;

[0022] Execute a cache update strategy on the cache processing in the cache database according to the cache key value and return an update result.

[0023] In some embodiments of the present invention, a cache key is generated based on an entity class ID, an entity class field fingerprint, and an application version number, wherein the entity class ID is a unique identifier of an entity class object, and the method for generating the entity class field fingerprint comprises the following steps:

[0024] All field names of the entity class are encrypted using a message digest algorithm to generate a fingerprint string, and the fingerprint string is used as a part of the cache key value.

[0025] In some embodiments of the present invention, a preset structure data serialization method is used to serialize and deserialize entity class objects, including:

[0026] Using a protocol file to define an entity class object, and using a compiler to compile the protocol file into a code in a target language;

[0027] Serializing the entity class object, converting it into a byte array and storing it in the cache database;

[0028] When the corresponding cache data is queried from the cache database, the cache data is deserialized and converted from a byte array into an entity class object.

[0029] In some embodiments of the present invention, the cache database uses Redis, and writing to the cache includes:

[0030] The cache value and the expiration time are set respectively by using the SETNX and EX commands in the Redis to ensure the atomic operation of the cache setting.

[0031] In some embodiments of the present invention, executing a cache update strategy on the cache processing in the cache database according to the cache key value includes:

[0032] Use preset interceptors to intercept all update and delete requests;

[0033] When deleting cached data for the first time, deleting the corresponding cached data from the cache database;

[0034] An update operation of the database is executed, and after waiting for a preset delay time, the corresponding cache data is deleted from the cache database again.

[0035] In some embodiments of the present invention, the method is further provided with a cache preheating mechanism, including:

[0036] Pre-write cache preheating logic to load the data that needs to be preset into the cache database;

[0037] Create a listener class that uses preset annotations to listen for events that the application has started and is ready to handle requests;

[0038] When it is detected that the application has been started and is ready to process the request event, a cache preheating operation is performed when the system starts in an asynchronous manner.

[0039] On the other hand, the present invention provides a cache management device based on a distributed entity cache architecture, and when the device is executed, the steps of the cache management method based on a distributed entity cache architecture as mentioned above are implemented, and the device includes:

[0040] The application side is used to initiate cache query requests and / or cache update requests;

[0041] A cache query module is used to generate a cache key value based on the entity class ID, entity class field fingerprint and application version number; use the cache key value to query whether there is corresponding cache data in the preset cache database, and if so, directly return the cache data; if not, query the database, return the result data, and serialize the result data, set the cache value and expiration time, and then write it into the cache database;

[0042] A cache update module, used to generate a cache key value based on an entity class ID, an entity class field fingerprint and an application version number; execute a cache update strategy on the cache processing in the cache database according to the cache key value, and return an update result;

[0043] The storage module includes the cache database and the database, and is used to store corresponding data.

[0044] In some embodiments of the present invention, the device is implemented based on the MyBatis framework, and can directly write a structured query language and directly perform corresponding operations through the structured query language.

[0045] On the other hand, the present invention further provides a computer-readable storage medium having a computer program / instruction stored thereon, which implements the steps of any of the methods mentioned above when the computer program / instruction is executed by a processor.

[0046] On the other hand, the present invention further provides a computer program product, comprising a computer program / instruction, which implements the steps of any of the methods mentioned above when executed by a processor.

[0047] The present invention provides a cache management method and device based on a distributed entity cache architecture, including a cache query method and a cache update method: initiating a cache query request; generating a cache key value based on an entity class ID, an entity class field fingerprint, and an application version number; using the cache key value to query whether there is corresponding cache data in a cache database, and if so, directly returning the cache data; if not, querying the database to return result data, serializing the result data, setting the cache value and expiration time, and writing to the cache database; initiating a cache update request; generating a cache key value based on an entity class ID, an entity class field fingerprint, and an application version number; executing a cache update strategy on the cache processing in the cache database according to the cache key value, and returning the update result. The present invention provides a distributed entity cache architecture, realizing automatic cache management of query and update operations, improving database processing efficiency, and ensuring consistency of data from multiple data sources.

[0048] Additional advantages, purposes, and features of the present invention will be described in part in the following description, and will become apparent to those skilled in the art after studying the following, or may be learned from the practice of the present invention. The purposes and other advantages of the present invention may be achieved and obtained by the structures specifically indicated in the specification and the accompanying drawings.

[0049] Those skilled in the art will appreciate that the objectives and advantages that can be achieved with the present invention are not limited to the above specific description, and the above and other objectives that can be achieved by the present invention will be more clearly understood from the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of the present application, and do not constitute a limitation of the present invention. In the drawings:

[0051] Figure 1 The figure is a schematic diagram of the steps of a cache query method in one embodiment of the present invention.

[0052] Figure 2 The figure is a timing flow chart of a first cache query method in one embodiment of the present invention.

[0053] Figure 3 The present invention is a timing flow chart of a non-first cache query method in an embodiment of the present invention.

[0054] Figure 4 The figure is a schematic diagram of the steps of a cache updating method in one embodiment of the present invention.

[0055] Figure 5 The figure is a timing flow chart of a cache updating method in one embodiment of the present invention.

[0056] Figure 6 It is a schematic diagram of the structure of a cache management device in one embodiment of the present invention. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments and the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0058] It should also be noted that, in order to avoid obscuring the present invention due to unnecessary details, only structures and / or processing steps closely related to the solutions according to the present invention are shown in the accompanying drawings, while other details that are not closely related to the present invention are omitted.

[0059] It should be emphasized that the term “include / comprises” when used herein refers to the presence of features, elements, steps or components, but does not exclude the presence or addition of one or more other features, elements, steps or components.

[0060] It should also be noted that, unless otherwise specified, the term “connection” herein may refer not only to a direct connection but also to an indirect connection involving an intermediate.

[0061] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. In the accompanying drawings, the same reference numerals represent the same or similar components, or the same or similar steps.

[0062] In order to solve the problems existing in the existing database cache mechanism, that is, when any update, deletion or addition operation occurs, the entire SqlSession cache needs to be directly cleared, which leads to frequent cache invalidation and reconstruction, increases the system load, and solves the problems that different sessions cannot share cache results, are not suitable for user interaction and batch job scenarios, cannot realize cache data sharing, and have coarse cache storage and query granularity, the present invention provides a cache management method based on a distributed entity cache architecture, the method comprising a cache query method and a cache update method.

[0063] like Figure 1 As shown, the cache query method includes the following steps S101 to S104:

[0064] Step S101: Initiate a cache query request.

[0065] Step S102: Generate a cache key value based on the entity class ID, the entity class field fingerprint and the application version number.

[0066] Step S103: Use the cache key value to query whether there is corresponding cache data in the preset cache database. If so, directly return the cache data.

[0067] Step S104: If it does not exist, query the database, return the result data, serialize the result data, set the cache value and expiration time, and write it into the cache database.

[0068] In the cache query method, if there is no corresponding cache data in the cache database, that is, it is the first query, the corresponding data needs to be written into the cache database; if there is corresponding cache data in the cache database, that is, it is not the first query, the relevant cache data can be directly obtained from the cache database.

[0069] According to the above description, cache query methods can be divided into two types depending on whether it is the first query.

[0070] like Figure 2 , which is a timing flow chart of the first query situation, which includes a cache write process.

[0071] In step S101, the application initiates a cache query request, which is the first query.

[0072] In step S102, a cache key is generated according to a cache key generation strategy. The cache key generation strategy is a key part of the cache architecture design, which directly affects the cache hit rate, management, and data consistency. In the present invention, a cache key is generated based on the entity class ID, entity class field fingerprint, and application version number. Among them, the entity class ID is the unique identifier of the entity class object, ensuring that the cache can accurately correspond to a specific data record. An entity refers to a data model in an application, usually representing a record in a database, such as a user, an order, etc.

[0073] In some embodiments, all field names of the entity class are encrypted using the Message-Digest Algorithm 5 (MD5) algorithm to generate a fingerprint string, which is used as part of the cache key value. When the structure of the entity class changes, such as adding, deleting, or modifying a field, the cache key value associated with the data will automatically become invalid, and a new cache entry will be generated to avoid inconsistent cache data caused by changes in the entity class model, without manual intervention, thereby enhancing the robustness of the system. Among them, MD5 is a widely used hash algorithm, which is a type of Hash algorithm.

[0074] The version number of the application service configuration is also used as part of the cache key value. When the system is updated or maintained, it supports manual changes to the version number, which makes all caches within the system invalid quickly, simplifies cache management, and facilitates progressive deployment and testing.

[0075] In some embodiments, the final cache key value is generated according to the cache key value generation strategy. For example, the cache key value is "9e107d9d372bb6826bd81d3542a419d6:v1.0:123", where "9e107d9d372bb6826bd81d3542a419d6" represents the entity class field fingerprint, "v1.0" represents the system version, and "123" represents the entity class ID.

[0076] In step S103, the cache key value obtained in step S102 is used to query whether there is corresponding cache data in the cache database. Since it is the first query, the cache database does not have the required data, and the cache database returns a null value.

[0077] In some embodiments, the present invention uses Redis as a cache database. Redis is an open source, high-performance key-value database that is often used as a data cache solution. It supports a variety of data structures, such as strings, lists, sets, hashes, ordered sets, etc. Redis stores all data in memory and supports data persistence, and can save data in memory to the hard disk. It is widely used in application scenarios that require fast data access, such as real-time applications, session management of large-scale websites, etc.

[0078] Since the required data is not found in the cache database, the process jumps to step S104 to query the database (DataBase, DB) and return the data results. The returned data results are serialized and atomically written into the cache in the cache database.

[0079] In some embodiments, based on the cache database using Redis, the SETNX and EX methods in Redis are used to write to the cache to ensure the atomic operation of the cache setting. Among them, the SETNX command is used to set the cache value if and only if it does not exist, and the SETEX command is used to set the cache value expiration time. For example, the expiration time is set to one week.

[0080] It should be noted that SETNX is selected in the present invention because no cache overwrite update operation is designed in the present invention, and all cache update strategies are to directly delete the cache. The cache update strategy is further explained below.

[0081] like Figure 3 As shown, it is a timing flow chart of a non-first query situation, which only includes steps S101 to S103. Among them, the specific settings of steps S101 to S103 are consistent with the first query method, so they are not repeated here.

[0082] In the case of non-first query, after the required cache data is queried in step S103, it is returned to the application after deserialization. The purpose of deserialization is to convert the serialized data stored in the cache database back to the original object format. This is because when writing to the cache, the object is usually serialized into a byte stream to save space and improve transmission efficiency. After deserialization, the data can be used normally in the application, which is convenient for subsequent operations or display.

[0083] In some embodiments, a preset structured data serialization method is used, such as a Protocol Buffers (Proto Buff) component, to serialize and deserialize entity class objects, including: using a protocol file, such as .proto, to define entity class objects, and compiling the protocol file into a target language (such as Java, Python, etc.) code through a compiler; serializing the entity class objects, converting them into byte arrays and storing them in a cache database; when querying the corresponding cache data from the cache database, deserializing the cache data and converting them from byte arrays to entity class objects. Compared with the traditional Json serialization method, Proto Buff has faster performance and efficiency because it uses a compact binary format, which reduces the size of the data packet, which means that less bandwidth and space are required during network transmission and storage, resulting in a more efficient processing speed. And Proto Buff is a strongly typed serialization rule. When the fields of the entity class are added and deleted, its field marking function can support seamless addition and discarding of fields. Combined with the entity fingerprint, each cache instance can accurately correspond to the version of its data structure.

[0084] like Figure 4 As shown, the cache update method includes the following steps S201 to S203:

[0085] Step S201: Initiate a cache update request.

[0086] Step S202: Generate a cache key value based on the entity class ID, the entity class field fingerprint and the application version number.

[0087] Step S203: Execute a cache update strategy on the cache processing in the cache database according to the cache key value, and return an update result.

[0088] like Figure 5 As shown, it is a timing flow chart of the cache update method.

[0089] In step S201, the application initiates a cache update (deletion) request.

[0090] In step S202, consistent with step S102, a cache key is generated according to a cache key generation strategy, where the cache key generation strategy generates a cache key based on an entity class ID, an entity class field fingerprint, and an application version number.

[0091] In step S203, a cache update strategy is executed on the cache processing in the cache database according to the cache key value, and an update result is returned.

[0092] Since the cache is configured, it is necessary to consider the data consistency of multiple data sources to ensure that the data in the cache database is updated synchronously with the database. That is, when the data is modified, it is necessary to ensure that the data in the two is the same in any case, and there will be no data inconsistency.

[0093] In some embodiments, the cache update strategy includes a forced refresh strategy and a delayed refresh strategy. The forced refresh strategy is to force refresh the cache for all update (deletion) operations through a preset interceptor. Exemplarily, the preset interceptor adopts a MyBatis interceptor, including the following steps: when deleting cached data for the first time, before the database is updated, the corresponding cached data is deleted from the cache database; execute the database update operation, and after waiting for a preset delay time, delete the corresponding cached data from the cache database again.

[0094] The delayed double deletion strategy is adopted in the present invention to take into account the problem of data inconsistency in a short period of time: there is a time window between the database operation and the cache database operation. During this time window, if the data in the cache database is deleted, but the data in the database has not been updated, then the user may read the old data and write it into the cache database, and the subsequent database will update the data. At this time, the data in the cache database and the database will have data inconsistency problems. The delayed double deletion can be used to effectively prevent the above phenomenon from happening by delaying for a certain period of time before cleaning the data in the cache.

[0095] Regarding the setting of the delay time, the average response time of the database is mostly within 100ms, and the delay time should at least cover this time to ensure that most database operations are completed before the second cache deletion. Exemplarily, the delay time is set to 100ms.

[0096] In some embodiments, the present invention further provides a cache preheating mechanism, including:

[0097] Pre-write cache preheating logic to load the preset data into the storage database; create a listener class, use preset annotations, such as @EventListener annotation, listen for the application has started and is ready to process request events (ApplicationReadyEvent); when the application has started and is ready to process request events are listened, perform cache preheating operations when the system starts in an asynchronous way. When asynchronous execution is required, add @Async annotation to the class or method.

[0098] In some embodiments, the present invention also has an expiration strategy. In step S104, it is mentioned to set an expiration time. Exemplarily, the expiration time can be set to one week. This strategy is mainly used to disperse the database load caused by the simultaneous failure of a large number of caches, that is, to generate a cache avalanche, resulting in a large number of requests concentrated at the database level, which brings performance pressure to the database.

[0099] The method of the present invention is further described below in conjunction with a specific embodiment.

[0100] Assuming that there is a complex list query that needs to query a large number of data columns, the query needs to consume more resources in the database, especially when it involves multiple table combinations or complex screening logic. The cache management method provided by the present invention is used:

[0101] The first query uses the covering index:

[0102] Execute a simplified SQL query that selects only necessary identifiers, such as primary key IDs, which is done quickly through covering indexes, reducing database I / O operations.

[0103] Use entity cache to improve data access speed:

[0104] According to the ID list obtained in the previous step, the corresponding complete entity data is retrieved from the entity cache. If the entity already exists in the cache database, it is returned directly without accessing the database again.

[0105] Entity caching provides an efficient data access strategy for dealing with complex database queries and high access loads. By breaking down database queries into simple lookups using covering indexes and data retrieval using cache, it not only improves the efficiency of data access, but also significantly reduces the pressure on the database.

[0106] In contrast to the cache management method based on the distributed entity cache architecture, the present invention also provides a cache management device based on the distributed entity cache architecture, which, when executed, can implement the steps of the cache management method based on the distributed entity cache architecture, such as Figure 6 As shown, the device comprises:

[0107] The application side is used to initiate cache query requests and / or cache update requests.

[0108] The cache query module is used to generate cache key values ​​based on entity class ID, entity class field fingerprint and application version number; use the cache key value to query whether there is corresponding cache data in the preset cache database. If so, return the cache data directly; if not, query the database, return the result data, and serialize the result data, set the cache value and expiration time, and then write it to the cache database.

[0109] The cache update module is used to generate a cache key value based on the entity class ID, entity class field fingerprint and application version number; execute a cache update strategy on the cache processing in the cache database according to the cache key value, and return the update result.

[0110] The storage module includes a cache database and a database, which is used to store corresponding data.

[0111] In some embodiments, the device of the present invention is implemented based on the MyBatis framework, and can directly write structured query language (SQL), and directly perform corresponding operations through the structured query language. MyBatis is a Java persistence layer framework that simplifies the interaction with the database, and it supports custom SQL, stored procedures, and advanced mapping.

[0112] Corresponding to the above method, the present invention also provides an electronic device, which includes a computer device, the computer device includes a processor and a memory, the memory stores computer instructions, the processor is used to execute the computer instructions stored in the memory, and when the computer instructions are executed by the processor, the electronic device implements the steps of the method described above.

[0113] The embodiment of the present invention also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the aforementioned edge computing server deployment method are implemented. The computer-readable storage medium can be a tangible storage medium, such as a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a floppy disk, a hard disk, a removable storage disk, a CD-ROM, or any other form of storage medium known in the technical field.

[0114] It should be understood by those skilled in the art that the exemplary components, systems and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software or a combination of the two. Whether it is performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link via a data signal carried in a carrier.

[0115] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.

[0116] In the present invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with features of other embodiments or replace features of other embodiments.

[0117] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A cache management method based on a distributed entity cache architecture, characterized in that: The cache management method includes a cache query method and a cache update method; The cache query method comprises the following steps: Initiate a cache query request; Generate cache key value based on entity class ID, entity class field fingerprint and application version number; Use the cache key value to query whether there is corresponding cache data in the preset cache database, and if so, directly return the cache data; If it does not exist, query the database, return the result data, serialize the result data, set the cache value and expiration time, and write it into the cache database; The cache update method comprises the following steps: Initiate a cache update request; Generate cache key value based on entity class ID, entity class field fingerprint and application version number; Execute a cache update strategy on the cache processing in the cache database according to the cache key value and return an update result.

2. The cache management method based on the distributed entity cache architecture according to claim 1, characterized in that: Generate a cache key value based on an entity class ID, an entity class field fingerprint, and an application version number, wherein the entity class ID is a unique identifier of an entity class object, and the method for generating the entity class field fingerprint comprises the following steps: All field names of the entity class are encrypted using a message digest algorithm to generate a fingerprint string, and the fingerprint string is used as a part of the cache key value.

3. The cache management method based on the distributed entity cache architecture according to claim 1, characterized in that: Use the preset structure data serialization method to serialize and deserialize entity class objects, including: Using a protocol file to define an entity class object, and using a compiler to compile the protocol file into a code in a target language; Serializing the entity class object, converting it into a byte array and storing it in the cache database; When the corresponding cache data is queried from the cache database, the cache data is deserialized and converted from a byte array into an entity class object.

4. The cache management method based on the distributed entity cache architecture according to claim 1, characterized in that: The cache database uses Redis, and writing to the cache includes: The cache value and the expiration time are set respectively by using the SETNX and EX commands in the Redis to ensure the atomic operation of the cache setting.

5. The cache management method based on the distributed entity cache architecture according to claim 1, characterized in that: Executing a cache update strategy on the cache processing in the cache database according to the cache key value includes: Use preset interceptors to intercept all update and delete requests; When deleting cached data for the first time, deleting the corresponding cached data from the cache database; An update operation of the database is executed, and after waiting for a preset delay time, the corresponding cache data is deleted from the cache database again.

6. The cache management method based on the distributed entity cache architecture according to claim 1, characterized in that: The method is also provided with a cache preheating mechanism, including: Pre-write cache preheating logic to load the data that needs to be preset into the cache database; Create a listener class that uses preset annotations to listen for events that the application has started and is ready to handle requests; When it is detected that the application has been started and is ready to process the request event, a cache preheating operation is performed when the system starts in an asynchronous manner.

7. A cache management device based on a distributed entity cache architecture, characterized in that: When the device is executed, the steps of the cache management method based on the distributed entity cache architecture according to any one of claims 1 to 6 are implemented, and the device includes: The application side is used to initiate cache query requests and / or cache update requests; A cache query module is used to generate a cache key value based on the entity class ID, entity class field fingerprint and application version number; use the cache key value to query whether there is corresponding cache data in the preset cache database, and if so, directly return the cache data; if not, query the database, return the result data, and serialize the result data, set the cache value and expiration time, and then write it into the cache database; A cache update module, used to generate a cache key value based on an entity class ID, an entity class field fingerprint and an application version number; execute a cache update strategy on the cache processing in the cache database according to the cache key value, and return an update result; The storage module includes the cache database and the database, and is used to store corresponding data.

8. The cache management device based on the distributed entity cache architecture according to claim 7, characterized in that: The device is implemented based on the MyBatis framework, and can directly write a structured query language and directly perform corresponding operations through the structured query language.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Multi-cache and type fingerprint dynamic execution method for verification of flexible drive electric energy meter

    CN120066617A

  • Multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter verification

    CN120066617B