Data caching method and apparatus thereof, computer readable storage medium, and processor

By registering a caching interface in the target service and using a monitoring thread to synchronize data versions, the problems of high difficulty and low efficiency in data synchronization in distributed caching technology are solved, enabling fast transmission and response of structured data.

CN115630092BActive Publication Date: 2026-04-14中国邮政储蓄银行股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
中国邮政储蓄银行股份有限公司
Filing Date
2022-09-30
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing distributed caching technologies in relational databases suffer from problems such as high data synchronization difficulty, low access efficiency, and slow response speed, especially in client-server architectures where the conversion between structured data and key-value data is complex.

Method used

Register cacheable information in the target service through the client-side cache registration interface and data loading interface, and use these interfaces to request data resources from the cache server. Combined with the monitoring thread, implement data version comparison and synchronization to ensure the consistency of data between the client and the server.

Benefits of technology

It improves data transmission efficiency, solves the problem of low efficiency caused by complex access structures in distributed caching technology, and enables direct querying and fast response of structured data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115630092B_ABST
    Figure CN115630092B_ABST
Patent Text Reader

Abstract

The application discloses a data caching method and device, a computer readable storage medium and a processor. The method comprises the following steps: registering first to-be-cached information and a first data loading interface into a target service through a client caching registration interface, wherein the client caching registration interface and the first data loading interface are pre-generated caching operation information; requesting a first data resource corresponding to the first to-be-cached information from a caching server by using the first data loading interface; and caching the first data resource to a target client. The application solves the technical problem that the data transmission efficiency is not high due to the complex access structure of part of the distributed caching technology in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computers, and more specifically, to a data caching method and apparatus, a computer-readable storage medium, and a processor. Background Technology

[0002] Current mainstream distributed caching technologies, Memcache and Redis, both employ a two-tier client-server architecture. When caching data in relational databases, local deployment (127.0.0.1) presents challenges due to the lack of necessary data synchronization mechanisms between multiple server instances, leading to high data synchronization difficulties. Clustered deployment, accessed over a network, results in client-to-server access speeds largely limited by network bandwidth and latency, resulting in low access efficiency and slow response times.

[0003] Both Memcache and Redis use a key-value structure to store data, while relational databases store structured data. Therefore, when accessing data from a relational database, both Memcache and Redis need to convert between structured data and key-value data, resulting in complex storage and retrieval structures.

[0004] The information disclosed above in the background section is only intended to enhance the understanding of the background art of the art described herein. Therefore, the background art may contain certain information that does not constitute prior art known to those skilled in the art in this country. Summary of the Invention

[0005] This invention provides a data caching method and apparatus, a computer-readable storage medium, and a processor to at least solve the technical problem of low data transmission efficiency caused by the complex access structure of some distributed caching technologies in related technologies.

[0006] According to one aspect of the present invention, a data caching method is provided, comprising: responding to a data query request from a target client, registering first information to be cached and a first data loading interface to a target service through a client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information; requesting a first data resource corresponding to the first information to be cached from a cache server using the first data loading interface; and caching the first data resource to the target client.

[0007] Optionally, registering the first cached information and the first data loading interface to the target service through the client cache registration interface includes: calling the client cache interface and the first data loading interface from the cache operation information based on the data query request; and registering the first cached information and the first data loading interface to the target service using the client cache interface.

[0008] Optionally, requesting a first data resource corresponding to the first cached information from the cache server using the first data loading interface includes: sequentially calling the first data loading interface to request the first data resource from the cache server and obtaining a data request result; determining a second data resource and data request failure information in the data request result; reloading a third data resource corresponding to the data request failure information from the local database; and obtaining the first data resource based on the second data resource and the third data resource.

[0009] Optionally, after reloading the third data resource corresponding to the data request failure information from the local database, the method further includes: starting a first data cache monitoring thread, wherein the first data cache monitoring thread requests the first data version information of the first data resource from the target server at a first predetermined time interval, and compares the first data version information with the second data version information stored in itself. When the comparison result indicates that the first data version information and the second data version information are inconsistent, the first cache query request is initiated to the target server, and the first cache query request updates the changed data in the target server to the local cache.

[0010] Optionally, the method further includes: synchronizing data between the cache server and the relational database; wherein synchronizing data between the cache server and the relational database includes: registering the second information to be cached and the second data loading interface to the cache server through a server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are both pre-generated cache operation information; and loading the second information to be cached into the relational database using the second data loading interface to synchronize data between the cache server and the relational database.

[0011] Optionally, after synchronizing the data between the cache server and the relational database, the method further includes: starting a second data cache monitoring thread, wherein the second data cache monitoring thread requests the third data version information of the second data resource from the relational database at second predetermined intervals, and compares the third data version information with the fourth data version information stored therein. If the comparison result indicates that the third data version information and the fourth data version information are inconsistent, a second cache query request is initiated to the relational database, and the second cache query request updates the changed data in the relational database to the cache server.

[0012] Optionally, after synchronizing data between the cache server and the relational database, the method further includes: generating the cache operation information; wherein generating the cache operation information includes: obtaining the data cache configuration table of the relational database; the data cache configuration table is used to generate the cache operation information based on the parsing result, wherein the cache operation information includes at least: the client cache registration interface, the first data loading interface, the server cache registration interface, and the second data loading interface.

[0013] Optionally, the cache operation information may further include at least one of the following: cache operation interface header file, cache data list, cache data update interface code information, data compression / decompression interface, and cache query interface.

[0014] According to one aspect of the present invention, a data caching apparatus is also provided, comprising: a loading module, configured to, in response to a data query request from a target client, register first information to be cached and a first data loading interface to a target service through a client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information; a request module, configured to, using the first data loading interface, request a first data resource corresponding to the first information to be cached from a cache server; and a caching module, configured to, cache the first data resource to the target client.

[0015] Optionally, the loading module includes: a calling unit, configured to call the client caching interface and the first data loading interface from the cache operation information based on the data query request; and a first loading unit, configured to register the first cached information and the first data loading interface to the target service using the client caching interface.

[0016] Optionally, the request module includes: a first acquisition unit, configured to sequentially call the first data loading interface to request the first data resource from the cache server and obtain a data request result; a determination unit, configured to determine the second data resource and data request failure information in the data request result; a reloading unit, configured to reload the third data resource corresponding to the data request failure information from the local database; and a second acquisition unit, configured to acquire the first data resource based on the second data resource and the third data resource.

[0017] Optionally, the device further includes: a first startup unit, configured to start a first data cache monitoring thread after reloading the third data resource corresponding to the data request failure information from the local database, wherein the first data cache monitoring thread requests the first data version information of the first data resource from the target server at a first predetermined time interval, and compares the first data version information with the second data version information stored therein, and when the comparison result indicates that the first data version information and the second data version information are inconsistent, initiates a first cache query request to the target server, the first cache query request updating the changed data in the target server to the local cache.

[0018] Optionally, the apparatus further includes: a synchronization module for synchronizing data between the cache server and the relational database; wherein the synchronization module includes: a second loading unit for registering second cacheable information and a second data loading interface to the cache server through a server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are both pre-generated cache operation information; and a third loading unit for loading the second cacheable information into the relational database using the second data loading interface to synchronize data between the cache server and the relational database.

[0019] Optionally, the device further includes: a second startup unit, configured to start a second data cache monitoring thread after synchronizing data between the cache server and the relational database, wherein the second data cache monitoring thread requests the third data version information of the second data resource from the relational database at second predetermined intervals, and compares the third data version information with the fourth data version information stored therein; if the comparison result indicates that the third data version information and the fourth data version information are inconsistent, a second cache query request is initiated to the relational database, and the second cache query request updates the changed data in the relational database to the cache server.

[0020] Optionally, the apparatus further includes: a generation unit, configured to generate the cache operation information after synchronizing data between the cache server and the relational database; wherein the generation unit includes: an acquisition subunit, configured to acquire the data cache configuration table of the relational database; and a parsing subunit, configured to parse the data cache configuration table to generate the cache operation information based on the parsing result, wherein the cache operation information includes at least: the client cache registration interface, the first data loading interface, the server cache registration interface, and the second data loading interface.

[0021] Optionally, the cache operation information may further include at least one of the following: cache operation interface header file, cache data list, cache data update interface code information, data compression / decompression interface, and cache query interface.

[0022] According to one aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to perform any of the data caching methods described above.

[0023] According to one aspect of the present invention, a processor is also provided, the processor being configured to run a program, wherein the program, when running, executes any one of the data caching methods described above.

[0024] In this embodiment of the invention, in response to a data query request from a target client, a first piece of information to be cached and a first data loading interface are registered with the target service through a client cache registration interface. The client cache registration interface and the first data loading interface are pre-generated cache operation information. The first data loading interface is used to request a first data resource corresponding to the first piece of information to be cached from the cache server. The first data resource is then cached on the target client. The data caching method provided by this embodiment of the invention achieves the goal of registering the data loading interface, including the information to be cached, with the target service when the service starts, then obtaining the data resource corresponding to the information to be cached and loading it onto the client. This achieves the objective of directly querying the structured data cached on the local client after receiving a data query request, thereby improving data transmission efficiency and solving the technical problem of low data transmission efficiency caused by the complex access structure of some distributed caching technologies in related technologies. Attached Figure Description

[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:

[0026] Figure 1 This is a flowchart of a data caching method according to an embodiment of the present invention;

[0027] Figure 2 This is a schematic diagram illustrating the correspondence between the table structure and the structure definitions in the generated structured header file according to an embodiment of the present invention;

[0028] Figure 3 This is a schematic diagram of the server-side cache loading and dynamic maintenance mechanism according to an embodiment of the present invention;

[0029] Figure 4 This is a schematic diagram of the client cache loading and dynamic maintenance mechanism according to an embodiment of the present invention;

[0030] Figure 5 This is a schematic diagram of the automatic generation mechanism of cache operation code according to an embodiment of the present invention;

[0031] Figure 6 This is a schematic diagram of a data caching device according to an embodiment of the present invention. Detailed Implementation

[0032] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0034] Example 1

[0035] According to an embodiment of the present invention, an embodiment of a data caching method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0036] Figure 1 This is a flowchart of a data caching method according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:

[0037] Step S102: In response to the data query request from the target client, the first information to be cached and the first data loading interface are registered to the target service through the client cache registration interface. The client cache registration interface and the first data loading interface are pre-generated cache operation information.

[0038] Optionally, in the above steps, the first information to be cached and the first data loading interface are registered in the target service through the client cache registration interface.

[0039] It should be noted that the first data loading interface is to register the table name to be cached and its data loading interface with the target service.

[0040] Step S104: Use the first data loading interface to request the first data resource corresponding to the first information to be cached from the cache server;

[0041] Optionally, in the above steps, the data resource (i.e. the first data resource) corresponding to the first information to be cached is requested from the cache server based on the first data loading interface.

[0042] Step S106: Cache the first data resource to the target client.

[0043] As can be seen from the above, in this embodiment of the invention, the first information to be cached and the first data loading interface are first registered with the target service through the client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information; then, the first data loading interface can be used to request the first data resource corresponding to the first information to be cached from the cache server; finally, the first data resource can be cached to the target client. Through the data caching method provided by this embodiment of the invention, the goal of registering the data loading interface, including the information to be cached, with the target service when the target service starts, then obtaining the data resource corresponding to the information to be cached and loading it to the client, and directly returning the structured data cached locally on the client after receiving a data query request, is achieved. This improves data transmission efficiency and solves the technical problem of low data transmission efficiency caused by the complex access structure of some distributed caching technologies in related technologies.

[0044] As an optional embodiment, registering the first information to be cached and the first data loading interface to the target service through the client cache registration interface includes: calling the client cache interface and the first data loading interface from the cache operation information based on the data query request; and registering the first information to be cached and the first data loading interface to the target service using the client cache interface.

[0045] It should be noted that the methods for waking up the client cache interface and the first data loading interface from the cache operation information include, but are not limited to: waking up based on data query requests and waking up automatically when the service starts.

[0046] It should be noted that the client-side caching interface mainly includes the client-side cache loading interface.

[0047] In the above optional embodiments, a structured table header file can first be automatically generated. For example, Figure 2 This is a schematic diagram illustrating the correspondence between the table structure and the structure definitions in the generated structured header file according to an embodiment of the present invention, such as... Figure 2 As shown in the diagram, the correspondence between the table structure of the tb_aps table and the structure definitions in the generated structured header file can be obtained from the diagram. Next, the cache operation interface header file can be automatically generated; then, the cache data list, cache registration interface, cache data loading interface, and cache data update interface code files can be automatically generated; finally, the cache operation code file for each table that needs to be cached can be automatically generated, including the cache loading interface, cache query interface, and data compression and decompression interface for each table.

[0048] As an optional embodiment, requesting a first data resource corresponding to the first cached information from the cache server using the first data loading interface includes: sequentially calling the first data loading interface to request the first data resource from the cache server and obtaining a data request result; determining the second data resource and data request failure information in the data request result; reloading the third data resource corresponding to the data request failure information from the local database; and obtaining the first data resource based on the second data resource and the third data resource.

[0049] In the above optional embodiments, the server-side cache loading and dynamic maintenance mechanism ensures near real-time synchronization between the server-side cached data and the data in the relational database. The specific steps of the cache server (PlatManager) during startup are as follows:

[0050] 1) Call the automatically generated cache registration interface to register the database table names that need to be cached and their data loading interfaces to the cache server PlatManager service.

[0051] 2) Call the data loading interface to load table data from the database into the data cache area.

[0052] 3) After the cached data is loaded, the PlatManager service starts a cache monitoring thread to monitor updates to the database and refresh the cached data.

[0053] As an optional embodiment, after reloading the third data resource corresponding to the data request failure information from the local database, the method further includes: starting a first data cache monitoring thread, wherein the first data cache monitoring thread requests the first data version information of the first data resource from the target server at a first predetermined time interval, and compares the first data version information with the second data version information stored in itself. When the comparison result indicates that the first data version information and the second data version information are inconsistent, a first cache query request is initiated to the target server, and the first cache query request updates the changed data in the target server to the local database.

[0054] It should be noted that the local database is cached on the local client.

[0055] Figure 3 This is a schematic diagram of the server-side cache loading and dynamic maintenance mechanism according to an embodiment of the present invention, as shown below. Figure 3As shown, the cache server can be deployed as a single instance or multiple instances. Data synchronization between different instances, as well as with the database, is achieved through dynamic maintenance of the server-side cached data. This dynamic maintenance is accomplished through data version information and a cache monitoring thread. The cache monitoring thread periodically queries the data version information stored in the database. If a change in the data version information is detected, it calls the cache loading interface of the table whose data has changed, registered in PlatManager, to complete the synchronization of the cached data with the database.

[0056] Users can maintain data version information by directly modifying it in the database, but this method is not elegant. PlatManager provides a cache refresh command. After receiving the command, the cache monitoring thread will maintain the data version information and refresh the cache. Other PlatManager instances will detect changes in the data version information and synchronize the cached data in a timely manner.

[0057] As an optional embodiment, the method further includes: synchronizing data between the cache server and the relational database; wherein synchronizing data between the cache server and the relational database includes: registering the second information to be cached and the second data loading interface to the cache server through the server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are both pre-generated cache operation information; and loading the second information to be cached into the relational database using the second data loading interface to synchronize data between the cache server and the relational database.

[0058] It should be noted that the second information to be cached includes, but is not limited to, the version information of the second content to be cached.

[0059] In the above optional embodiments, the client-side cache loading and dynamic maintenance mechanism ensures near real-time synchronization between client-side cached data and server-side cached data. The cache client is provided to the cache requester in the form of a set of automatically generated cache interfaces. The detailed steps of the requester service during startup are as follows:

[0060] 1) Call the client cache registration interface to register the table name to be cached and its data loading interface to the target service.

[0061] 2) Call the data loading interface registered with the target service in sequence, request data from the cache server (PlatManager) service, load it locally, and register failed loading requests in the local failure list.

[0062] 3) Traverse the failure list, use the local database as the data source, and reload the cached data.

[0063] 4) After the local cache is loaded, start the cache monitoring thread.

[0064] As an optional embodiment, after synchronizing data between the cache server and the relational database, the method further includes: starting a second data cache monitoring thread, wherein the second data cache monitoring thread requests the third data version information of the second data resource from the relational database at second predetermined intervals, and compares the third data version information with the fourth data version information stored therein. When the comparison result indicates that the third data version information and the fourth data version information are inconsistent, a second cache query request is initiated to the relational database, and the second cache query request updates the changed data in the relational database to the cache server.

[0065] Figure 4 This is a schematic diagram of the client cache loading and dynamic maintenance mechanism according to an embodiment of the present invention, as shown below. Figure 4 As shown, the dynamic maintenance of client-side cached data is also achieved through a cache monitoring thread. The cache monitoring thread periodically requests data version information from the PlatManager and checks it against its own stored data version information. If a data version change is detected, a cache query is initiated from the server, and the changed data is retrieved and updated in the local data cache, thus completing the synchronization between the client-side cache and the server-side cache.

[0066] As an optional embodiment, after synchronizing data between the cache server and the relational database, the method further includes: generating cache operation information; wherein, generating cache operation information includes: obtaining the data cache configuration table of the relational database; the data cache configuration table is used to generate cache operation information based on the parsing result, wherein the cache operation information includes at least: a client cache registration interface, a first data loading interface, a server cache registration interface, and a second data loading interface.

[0067] In the above optional embodiments, automatic code generation for cache operations is controlled through the data cache configuration table tb_pmctl_cache_info, the structure of which is described in detail in Table 1 below.

[0068] Table 1

[0069]

[0070] Furthermore, the primary keys are table_name and seq_no.

[0071] As an optional embodiment, the cache operation information may also include at least one of the following: cache operation interface header file, cache data list, cache data update interface code information, data compression / decompression interface, and cache query interface.

[0072] Figure 5 This is a schematic diagram of the automatic generation mechanism for cache operation code according to an embodiment of the present invention, such as... Figure 5 As shown, the automatic cache operation code generation mechanism is the core mechanism of this invention. The cache structured query mechanism is implemented based on this automatic cache operation code generation mechanism. The cache structured query can generate multiple structured query interfaces according to configuration, supports queries by primary key and non-primary key, can return multiple data entries simultaneously, and supports data sorting.

[0073] Furthermore, the cached structured query interface can return the retrieved cached data to a structure variable (one record) or an array of structure variables (multiple records) defined through the table structure header file. This stores the structured data from the relational database table into structure member variables with the same name, thereby realizing structured querying of distributed cached data.

[0074] It's important to explain that Memcache is a distributed high-speed caching system. Memcached runs as a daemon (listener) on one or more servers. Redis (Remote Dictionary Server) is an open-source, network-enabled, in-memory or persistent log-structured key-value database written in ANSI C. Memcache's workflow is as follows: First, it checks if the requested data is in memcached. If it is, it returns the data directly without further database operations. If the data is not in memcached, it queries the database, retrieves the data, returns it to the client, and simultaneously caches a copy in memcached (the memcached client is not responsible for this; it needs to be explicitly implemented in the program). Each time the database is updated, the data in memcached is also updated to ensure consistency. When the memory allocated to memcached is exhausted, an LRU (Least Recently Used) policy combined with an expiration policy is used. Expired data is replaced first, followed by the least recently used data. Redis is a high-performance key-value database. The emergence of Redis largely compensates for the shortcomings of key / value stores like Memcached, and in some situations, it can serve as a good supplement to relational databases. Redis supports master-slave synchronization. Data can be synchronized from the master server to any number of slave servers.

[0075] As can be seen from the above, all cache queries in this embodiment of the invention operate on the client-side local cache. Simultaneously, a dynamic maintenance mechanism on the client ensures the consistency of cached data between the client and the server, and a dynamic maintenance mechanism on the server ensures the consistency of data between the server and the database. This effectively solves the problem of the inability to simultaneously achieve data synchronization and response speed in Memcache and Redis distributed caching technologies. Furthermore, the method provided in this embodiment of the invention differs from the mainstream distributed caching technology's two-layer client-server cache structure, and its three-layer data synchronization mode of structured query API-client cache-server cache. Corresponding to the three-layer data synchronization mode, it employs a data consistency guarantee mechanism based on table data versions for distributed cache client and server, server and server, and server and database; an automatic code generation mechanism for database operations and cache operations based on configuration and database table structure parsing; and a structured query function for cached data implemented based on the automatic code generation mechanism.

[0076] Example 2

[0077] According to one aspect of the present invention, a data caching device is also provided. Figure 6 This is a schematic diagram of a data caching device according to an embodiment of the present invention, such as... Figure 6 As shown, it includes: a loading module 61, a request module 63, and a caching module 65. The following is a detailed description of this data caching device.

[0078] The loading module 61 registers the first cacheable information and the first data loading interface to the target service through the client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information;

[0079] Request module 63 is used to request the first data resource corresponding to the first information to be cached from the cache server using the first data loading interface;

[0080] Cache module 65 is used to cache the first data resource to the target client.

[0081] As can be seen from the above, in this embodiment of the invention, firstly, the loading module 61 can respond to the data query request from the target client by registering the first information to be cached and the first data loading interface to the target service through the client cache registration interface. The client cache registration interface and the first data loading interface are pre-generated cache operation information. Next, the request module 63 can use the first data loading interface to request the first data resource corresponding to the first information to be cached from the cache server. Finally, the cache module 65 can cache the first data resource to the target client. Through the data caching device provided by this embodiment of the invention, the goal is to register the data loading interface, such as the information to be cached, to the target service when the target service starts, then obtain the data resource corresponding to the information to be cached and load it to the client, and directly return the structured data cached locally on the client after receiving a data query request. This achieves the technical effect of improving data transmission efficiency and solves the technical problem of low data transmission efficiency caused by the complex access structure of some distributed caching technologies in related technologies.

[0082] Optionally, the loading module includes: a calling unit, used to call the client caching interface and the first data loading interface from the cache operation information based on the data query request; and a first loading unit, used to register the first information to be cached and the first data loading interface to the target service using the client caching interface.

[0083] Optionally, the request module includes: a first acquisition unit, configured to sequentially call a first data loading interface to request a first data resource from a cache server and obtain a data request result; a determination unit, configured to determine a second data resource and data request failure information in the data request result; a reloading unit, configured to reload a third data resource corresponding to the data request failure information from a local database; and a second acquisition unit, configured to acquire the first data resource based on the second data resource and the third data resource.

[0084] Optionally, the device further includes: a first startup unit, configured to start a first data cache monitoring thread after reloading the third data resource corresponding to the data request failure information from the local database, wherein the first data cache monitoring thread requests the first data version information of the first data resource from the target server at a first predetermined time interval, and compares the first data version information with the second data version information stored therein, and when the comparison result indicates that the first data version information and the second data version information are inconsistent, initiates a first cache query request to the target server, and the first cache query request updates the changed data in the target server to the local database.

[0085] Optionally, the device further includes: a synchronization module for synchronizing data between the cache server and the relational database; wherein the synchronization module includes: a second loading unit for registering the second information to be cached and the second data loading interface to the cache server through the server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are also pre-generated cache operation information; and a third loading unit for loading the second information to be cached into the relational database using the second data loading interface to synchronize data between the cache server and the relational database.

[0086] Optionally, the device further includes: a second startup unit, used to start a second data cache monitoring thread after synchronizing data between the cache server and the relational database, wherein the second data cache monitoring thread requests the third data version information of the second data resource from the relational database at second predetermined intervals, and compares the third data version information with the fourth data version information stored therein. When the comparison result indicates that the third data version information and the fourth data version information are inconsistent, a second cache query request is initiated to the relational database, and the second cache query request updates the changed data in the relational database to the cache server.

[0087] Optionally, the apparatus further includes: a generation unit, used to generate cache operation information after synchronizing data between the cache server and the relational database; wherein the generation unit includes: an acquisition subunit, used to acquire the data cache configuration table of the relational database; and a parsing subunit, used to parse the data cache configuration table to generate cache operation information based on the parsing result, wherein the cache operation information includes at least: a client cache registration interface, a first data loading interface, a server cache registration interface, and a second data loading interface.

[0088] Optionally, the cache operation information may also include at least one of the following: cache operation interface header file, cache data list, cache data update interface code information, data compression / decompression interface, and cache query interface.

[0089] Example 3

[0090] According to one aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, a data caching method is used to control any one of the executions of the device on which the computer-readable storage medium is located.

[0091] Example 4

[0092] According to one aspect of the present invention, a processor is also provided, the processor being used to run a program, wherein, during program execution, any one of the data caching methods is performed.

[0093] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0094] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.

[0095] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0096] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0097] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0098] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0099] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0100] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0101] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A data caching method, characterized in that, include: The first cacheable information and the first data loading interface are registered to the target service through the client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information; The first data loading interface is used to request the first data resource corresponding to the first information to be cached from the cache server. Cache the first data resource to the target client; The step of requesting the first data resource corresponding to the first cached information from the cache server using the first data loading interface includes: The first data loading interface is called sequentially to request the first data resource from the cache server, and the data request result is obtained. The second data resource and data request failure information in the data request result are determined; Reload the third data resource corresponding to the data request failure information from the local database; The first data resource is obtained based on the second data resource and the third data resource; The method further includes: synchronizing data between the cache server and the relational database, wherein synchronizing data between the cache server and the relational database includes: The second cacheable information and the second data loading interface are registered to the cache server through the server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are both pre-generated cache operation information; The second data loading interface is used to load the second information to be cached into the relational database in order to synchronize the data between the cache server and the relational database; After synchronizing the cache server with the relational database, the method further includes: generating the cache operation information; The generation of the cache operation information includes: Obtain the data cache configuration table of the relational database; The data cache configuration table is parsed to generate cache operation information based on the parsing result. The cache operation information includes at least the client cache registration interface, the first data loading interface, the server cache registration interface, and the second data loading interface.

2. The data caching method according to claim 1, characterized in that, The first information to be cached and the first data loading interface are registered with the target service through the client-side cache registration interface, including: Based on the data query request, the client cache interface and the first data loading interface are invoked from the cache operation information; The first information to be cached and the first data loading interface are registered with the target service using the client caching interface.

3. The data caching method according to claim 1, characterized in that, After reloading the third data resource corresponding to the data request failure information from the local database, the method further includes: A first data cache monitoring thread is started. The first data cache monitoring thread requests the first data version information of the first data resource from the target server at a first predetermined time interval, and compares the first data version information with the second data version information stored in itself. When the comparison result indicates that the first data version information and the second data version information are inconsistent, a first cache query request is initiated to the target server. The first cache query request updates the changed data in the target server to the local cache.

4. The data caching method according to claim 3, characterized in that, After synchronizing data between the cache server and the relational database, the method further includes: A second data cache monitoring thread is started. Every second predetermined time interval, the second data cache monitoring thread requests the third data version information of the second data resource from the relational database and compares the third data version information with the fourth data version information stored in itself. When the comparison result indicates that the third data version information and the fourth data version information are inconsistent, a second cache query request is initiated to the relational database. The second cache query request updates the changed data in the relational database to the cache server.

5. The data caching method according to claim 1, characterized in that, The cache operation information also includes at least one of the following: cache operation interface header file, cache data list, cache data update interface code information, data compression / decompression interface, and cache query interface.

6. A data caching device, characterized in that, include: The loading module is used to respond to the data query request of the target client by registering the first information to be cached and the first data loading interface to the target service through the client cache registration interface, wherein the client cache registration interface and the first data loading interface are pre-generated cache operation information; The request module is used to request a first data resource corresponding to the first information to be cached from the cache server using the first data loading interface; A caching module is used to cache the first data resource to the target client; The request module includes: The first acquisition unit is used to sequentially call the first data loading interface to request the first data resource from the cache server and obtain the data request result. The determining unit is used to determine the second data resource and the data request failure information in the data request result; The reloading unit is used to reload the third data resource corresponding to the data request failure information from the local database. The second acquisition unit is used to acquire the first data resource based on the second data resource and the third data resource; The device further includes: A synchronization module is used to synchronize data between the cache server and the relational database. The synchronization module includes: The second loading unit is used to register the second cacheable information and the second data loading interface to the cache server through the server-side cache registration interface, wherein the server-side cache registration interface and the second data loading interface are also pre-generated cache operation information; The third loading unit is used to load the second information to be cached into the relational database using the second data loading interface, so as to synchronize the data between the cache server and the relational database; The device further includes: a generation unit, used to generate the cache operation information after synchronizing the data between the cache server and the relational database; The generation unit includes: The acquisition subunit is used to acquire the data cache configuration table of the relational database; The parsing subunit is used to parse the data cache configuration table to generate the cache operation information based on the parsing result. The cache operation information includes at least the client cache registration interface, the first data loading interface, the server cache registration interface, and the second data loading interface.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the data caching method according to any one of claims 1 to 5.

8. A processor, characterized in that, The processor is used to run a program, wherein the program executes the data caching method according to any one of claims 1 to 5 when it runs.

Citation Information

Patent Citations

  • Method and system for updating client cache

    CN111475180A

  • Cache data synchronization method and device, equipment and storage medium

    CN114328618A