CN113779078A - Cache data acquisition method and device - Google Patents

Cache data acquisition method and device Download PDF

Info

Publication number
CN113779078A
CN113779078A CN202011287776.8A CN202011287776A CN113779078A CN 113779078 A CN113779078 A CN 113779078A CN 202011287776 A CN202011287776 A CN 202011287776A CN 113779078 A CN113779078 A CN 113779078A
Authority
CN
China
Prior art keywords
cache
data
remote
hybrid
local
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011287776.8A
Other languages
Chinese (zh)
Inventor
魏小霞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202011287776.8A priority Critical patent/CN113779078A/en
Publication of CN113779078A publication Critical patent/CN113779078A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/289Object oriented databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a method and a device for obtaining cache data, and relates to the technical field of computers. One embodiment of the method comprises: calling a data acquisition interface in the hybrid cache component, and determining the used cache type according to the parameters of the data acquisition interface; acquiring cache data by using a hybrid cache component, wherein the cache data is acquired from a local cache under the condition that the used cache type is the local cache; and in the case that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring cache data from the remote cache. The implementation mode can avoid the lengthy code logic judgment of handwriting, reduce the manual workload, freely select the required cache type, select to use or not use the local cache, and the mixed cache component can be called as a plug-in component, so that the universality is high.

Description

Cache data acquisition method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for obtaining cache data.
Background
In the current system with smaller flow, when data is requested, the data is firstly inquired from relational databases such as Oracle, Microsoft SQL Server, MySQL and the like, the data is generally commonly used for basic configuration, the data is important and has higher correctness requirement, and if the allowable part of the data is lost, the data can be inquired from non-relational databases such as MongoDb, HBase and the like; in a system with large flow, when data is requested, the data is firstly obtained from a remote cache (such as Redis and the like), the data cannot be obtained and then returned from a database query, if TP999(TP999 is the minimum time consumption required for meeting a network request of nine-hundred-nineteen per thousand) and TP99(TP99 is the minimum time consumption required for meeting a network request of nine-nineteen per cent) are ensured, a local cache (such as Guavacache, EHcache and the like) is generally used, and for a developer, if the developer wants to use the local cache and the remote cache at the same time, the local cache and the remote cache need to be respectively called manually, and then code logic judgment is carried out, and the code is long.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
there is a lengthy code logic judgment, and in a cache scenario where a local cache and a remote cache are used simultaneously or only the remote cache is used, a developer is required to write a large amount of functional codes, a required cache type cannot be freely selected, and the cache type cannot be used as a general tool.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for obtaining cache data, which can avoid redundant code logic judgment in handwriting, reduce manual workload, freely select a required cache type, and optionally use or not use a local cache, and a hybrid cache component can be called as a plug-in component, so that the universality is high.
To achieve the above object, according to an aspect of the embodiments of the present invention, a method for obtaining cache data is provided.
A cache data acquisition method comprises the following steps: calling a data acquisition interface in the hybrid cache component, and determining the cache type to be used according to the parameters of the data acquisition interface; obtaining cache data by using the hybrid cache component, wherein the cache data is obtained from a local cache under the condition that the used cache type is the local cache; and under the condition that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache.
Optionally, the hybrid cache component is implemented by a hybrid cache class, the data obtaining interface is a method defined in the hybrid cache class for obtaining data from a hybrid cache, and the hybrid cache includes the local cache and the remote cache.
Optionally, the obtaining of the cache data from the local cache includes: judging whether the current local cache instance obtained through the data acquisition interface is empty or not; if not, acquiring the cache data based on the current local cache instance; and if the cache data is empty, creating a default local cache instance through the mixed cache class, and acquiring the cache data based on the default local cache instance.
Optionally, when the used cache type is a local cache, if the cache data does not exist in the local cache, a remote cache method provided by the hybrid cache component is called through a reflection mechanism, and the cache data is obtained from the remote cache and written into the local cache, so as to obtain the cache data from the local cache.
Optionally, the parameters of the data acquisition interface include a class name, a method name, and a parameter array of the remote cache; the invoking, by the reflection mechanism, a remote caching method provided by the hybrid cache component to obtain the cache data from the remote cache includes: and reflecting and calling a remote cache method in the remote cache object to obtain cache data from the remote cache.
Optionally, the parameter of the data obtaining interface includes a first parameter, a value of the first parameter indicates whether to use the local cache, and when the value of the first parameter is true, the used cache type is the local cache; and when the value of the first parameter is false, the used cache type is remote cache.
According to another aspect of the embodiments of the present invention, an apparatus for obtaining cache data is provided.
An apparatus for obtaining cache data, comprising: the cache type determining module is used for calling a data acquisition interface in the hybrid cache component and determining the used cache type according to the parameters of the data acquisition interface; a cache data obtaining module, configured to obtain cache data by using the hybrid cache component, where the cache data is obtained from a local cache when the used cache type is the local cache; and under the condition that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache.
Optionally, the hybrid cache component is implemented by a hybrid cache class, the data obtaining interface is a method defined in the hybrid cache class for obtaining data from a hybrid cache, and the hybrid cache includes the local cache and the remote cache.
Optionally, the cache data obtaining module is further configured to: judging whether the current local cache instance obtained through the data acquisition interface is empty or not; if not, acquiring the cache data based on the current local cache instance; and if the cache data is empty, creating a default local cache instance through the mixed cache class, and acquiring the cache data based on the default local cache instance.
Optionally, the cache data obtaining module is further configured to: and under the condition that the used cache type is a local cache, if the cache data does not exist in the local cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache and writing the cache data into the local cache so as to acquire the cache data from the local cache.
Optionally, the parameters of the data acquisition interface include a class name, a method name, and a parameter array of the remote cache; the cache data obtaining module is further configured to: and reflecting and calling a remote cache method in the remote cache object to obtain cache data from the remote cache.
Optionally, the parameter of the data obtaining interface includes a first parameter, a value of the first parameter indicates whether to use the local cache, and when the value of the first parameter is true, the used cache type is the local cache; and when the value of the first parameter is false, the used cache type is remote cache.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; the memory is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the cache data acquisition method provided by the embodiment of the invention.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, the program, when executed by a processor, implementing the method for obtaining cache data according to an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: calling a data acquisition interface in the hybrid cache component, and determining the used cache type according to the parameters of the data acquisition interface; acquiring cache data by using a hybrid cache component, wherein the cache data is acquired from a local cache under the condition that the used cache type is the local cache; and in the case that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring cache data from the remote cache. The method has the advantages that the lengthy code logic judgment of handwriting can be avoided, the manual workload is reduced, the required cache type can be freely selected, local cache can be selectively used or not used, the mixed cache component can be used as a plug-in component to be called, and the universality is high.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
fig. 1 is a schematic diagram illustrating the main steps of a cache data obtaining method according to an embodiment of the present invention;
FIG. 2 is a flow diagram illustrating a cache data retrieval process according to one embodiment of the invention;
FIG. 3 is a schematic workflow diagram of a hybrid cache component according to one embodiment of the invention;
FIG. 4 is a schematic diagram of the main modules of an apparatus for obtaining cache data according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 6 is a schematic block diagram of a computer system suitable for use with a server implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram illustrating main steps of a cache data obtaining method according to an embodiment of the present invention.
As shown in fig. 1, the method for obtaining cache data according to an embodiment of the present invention mainly includes the following steps S101 to S102.
Step S101: calling a data acquisition interface in the hybrid cache component, and determining the used cache type according to the parameters of the data acquisition interface;
step S102: acquiring cache data by using a hybrid cache component, wherein the cache data is acquired from a local cache under the condition that the used cache type is the local cache; and in the case that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring cache data from the remote cache.
The hybrid cache component of the embodiment of the invention can be realized by a hybrid cache class, and the data acquisition interface is a method for acquiring data from the hybrid cache defined in the hybrid cache class.
The hybrid cache includes a local cache and a remote cache.
In one embodiment, retrieving cached data from a local cache comprises: judging whether the current local cache instance obtained through the data acquisition interface is empty or not; if not, obtaining cache data based on the current local cache instance; and if the cache is empty, creating a default local cache instance through the mixed cache class, and acquiring cache data based on the default local cache instance.
And judging whether the current local cache instance is empty or not, namely judging whether the current local cache exists or not. If the current local cache instance is not empty, the current local cache is present, and the local cache can be directly used; if the current local cache instance is empty, it means that the current local cache does not exist, a default local cache needs to be created by the hybrid cache component, that is, a default local cache instance is created by the hybrid cache class, and then the default local cache is used.
In one embodiment, in the case that the used cache type is a local cache, if cache data does not exist in the local cache, a remote cache method provided by the hybrid cache component is called through a reflection mechanism, and cache data is obtained from the remote cache and written into the local cache so as to obtain the cache data from the local cache.
In one embodiment, the parameters of the data acquisition interface may include a class name, a method name, and an array of parameters for remote caching.
The method for obtaining cache data from a remote cache by calling a remote cache method provided by a hybrid cache component through a reflection mechanism may specifically include: and reflecting the class name, the method name and the parameter array of the remote cache to obtain a remote cache object, and reflecting and calling a remote cache method in the remote cache object to obtain cache data from the remote cache.
In one embodiment, the parameter of the data obtaining interface may include a first parameter, a value of the first parameter indicates whether to use a local cache, and when the value of the first parameter is true, the type of the cache used is the local cache; and when the value of the first parameter is false, the used cache type is remote cache.
The following first describes the hybrid cache component of an embodiment of the present invention.
The hybrid cache component of one embodiment of the invention may be implemented by the hybrid cache class MixtureCache.
In the mixed cache class MixtureCache of the embodiment of the present invention, a method for acquiring data from a mixed cache is defined, and the defined method is an interface for acquiring data of a mixed cache component, or is referred to as a data acquisition interface. The method comprises the following specific steps:
public<T>T get(Object key,Boolean useLocalCache,Cache localCache,String remoteClassName,String remoteMethodName,Object[]remoteArgs);
the meaning of the parameters of the data acquisition interface is specifically as follows:
key: a key representing a local cache;
localCache: representing a local cache object, by implementing a local cache class of a cache interface com. Local cache objects of the Guavacache or other local cache classes;
remoteClassName: representing a remote cache class name.
userllocalcache: indicating whether a local cache is used.
remoteMethodName: representing the remote caching method name.
remoteArgs: representing an array of remote caching parameters.
In the embodiment of the present invention, the local cache is a local cache class that implements a com. The remote cache may be a custom remote cache class or an open source remote cache class (e.g., Redis). The remote cache class includes a remote cache method by which cache data can be obtained from a remote cache. After the remote cache object corresponding to the remote cache class is obtained by reflecting the class name, the method name and the parameter array of the remote cache, the remote cache method can also be called as a remote cache method in the remote cache object.
The data acquisition from the hybrid cache is realized as follows: the type of cache used may be determined based on a value of a first parameter (i.e., userlockalcache) indicating whether to use the local cache.
If the value of the first parameter userllocalcache is equal to true, which indicates that a local cache is used, the local cache localCache is used to obtain cache data first, if the local cache localCache does not exist, a default local cache is created, the default local cache is realized based on the guava cache, and then the default local cache is used. If the cache data in the local cache does not exist, the remote cache object is obtained by reflecting the remote cache class name, the method name and the parameter array, the remote cache method in the remote cache object is called in a reflection mode, so that the cache data are obtained from the remote cache, and then the cache data are written into the local cache.
If the value of the first parameter userllocalcache variable is false, which indicates that the local cache is not used, the remote cache object is obtained by reflecting the remote cache class name, the method name and the parameter array, and the remote cache method in the remote cache object is called in a reflection mode, so that cache data is obtained from the remote cache.
Reflection means that in a running state, for any class, all attributes and methods of the class can be known, for any object, any method and attribute of the class can be called, and the function of dynamically acquiring information and dynamically calling the object method is called reflection.
An exemplary core code implementation for reading data in a hybrid cache of embodiments of the present invention is as follows:
Figure BDA0002782936450000081
the method for acquiring data from the remote cache (namely, the getcache method) in the embodiment of the invention is specifically realized as follows: and obtaining a Class object corresponding to the remote cache Class name character string by using a static method for name (remote cache Class name) in the Class, wherein the Class object stores type information related to the remote cache Class, and the Class object obtains a remote cache instance by a newInstance () method in the Class object. The Class is the basis of java reflection mechanism, and related information about a Class can be obtained through the Class. Class has a well-known static approach (i.e., static approach): forName, the method may obtain a Class object associated with the Class based on the Class name specified by the string parameter, and if the Class is not already loaded, the method loads the Class into the JVM. Objects of Class, i.e. Class objects, are used to provide or obtain type information of an object at runtime.
If the remote caching parameter array is empty, a getDeclardMethod (remote caching Method name) Method is used for acquiring a specified declared Method (namely a declared Method of a remote caching Class) of a Class or an interface represented by the Class object, the Method object ensures that a reflection can call a non-Public Method through a setACCESS (true) Method, and finally a Method (namely a remote caching Method) in the current Method object is called to acquire remote caching data. The Method represents a member Method of a Class represented by a Class object, a Method of the object can be dynamically called through the Method, the Method provides information about a single Method (and how to access the Method) on the Class or the interface, and the reflected Method can be a Class Method or an example Method (including an abstract Method). The getDeclardMethod Method returns a Method object with specified parameters that reflect the specified declared Method for the Class or interface represented by the Class object.
If the remote caching parameter array is not empty, the parameter array is processed to obtain a Class object array for identifying the form parameter type of the Method, a specified declared Method (namely a declared Method of a remote caching Class) of a Class or an interface represented by the Class object is obtained through a getDecleardMethod (remote caching Method name, Class object array), the Method object ensures that reflection can call a non-Public Method through a setACCESS (true) Method, and finally a Method (namely a remote caching Method) in the current Method object is called to obtain remote caching data.
The use process of the hybrid cache component of the embodiment of the invention comprises the following steps: firstly, because the hybrid cache component is packed into a jar packet, the user needs to introduce the jar packet; secondly, selecting a local cache and generating a local cache object, wherein the local cache class needs to realize a com.google.common.cache.cache interface (from guava-xx.jar), and can also use a local cache Guava cache in a mixed cache component; then, selecting a remote cache which can be a self-defined remote cache class or an open-source remote cache class; finally, the mixed cache is injected, using the methods in the mixed cache component.
Exemplary code used by the hybrid cache component is as follows:
Figure BDA0002782936450000091
Figure BDA0002782936450000101
fig. 2 is a schematic diagram illustrating a cache data obtaining process according to an embodiment of the present invention.
As shown in fig. 2, the cache data obtaining process according to an embodiment of the present invention includes:
step S201: a server-side system receives a calling request of a user side;
step S202: and the server-side system calls a data acquisition interface in the hybrid cache component according to the calling request.
The server-side system can select and use the parameters of the data acquisition interface in the hybrid cache component according to the requirement.
Step S203: and the server-side system acquires the cache data from the hybrid cache by using the hybrid cache component.
The hybrid cache component can automatically judge which cache type is used by the server system according to the parameters of the data acquisition interface, specifically, automatically judge the used cache type according to the value of a userlocal cache variable in the parameters of the data acquisition interface, and acquire cache data from the selected type of cache.
FIG. 3 is a schematic workflow diagram of a hybrid cache component according to one embodiment of the invention.
As shown in fig. 3, the work flow of the hybrid cache component according to an embodiment of the present invention includes:
step S301: judging whether to use local cache or not according to the parameters of the data acquisition interface; if yes, go to step S302; otherwise, executing step S306;
step S302: judging whether the local cache instance is empty or not; if the status is empty, step S303 is executed; if not, go to step S304;
step S303: creating a default local cache instance, and then executing the step S304;
a default local cache instance such as guava cache.
Step S304: obtaining data from a local cache;
step S305: judging whether the data obtained from the local cache is empty or not; if the data is empty, executing step S306; if not, the flow is ended.
Step S306: obtaining data back to the source from the remote cache;
step S307: judging whether the situation is that the local cache is used and the data acquired from the local cache is empty; if yes, go to step S308; otherwise, the flow ends.
Step S308: and writing the data acquired from the remote cache into the local cache, and then ending the process.
According to the flow for acquiring the cache data by using the hybrid cache component, the local cache and the remote cache can be used in a hybrid manner, the two cache types can be freely selected, the remote cache is acquired by using a reflection manner, and the remote cache method is called, so that the remote cache is flexibly embedded, the data reading method is beaten into a jar packet to form a complete component, the hybrid cache component can be called as a plug-in component, the universality is high, a developer does not need to write a large number of functional codes, and the workload is saved.
Fig. 4 is a schematic diagram of main blocks of a cache data obtaining apparatus according to an embodiment of the present invention.
As shown in fig. 4, an apparatus 400 for obtaining cache data according to an embodiment of the present invention mainly includes: a cache type determining module 401 and a cache data obtaining module 402.
The cache type determining module 401 is configured to invoke a data obtaining interface in the hybrid cache component, and determine a cache type to be used according to a parameter of the data obtaining interface.
A cache data obtaining module 402, configured to obtain cache data by using a hybrid cache component, where the cache data is obtained from a local cache if a used cache type is the local cache; and in the case that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring cache data from the remote cache.
The hybrid cache component can be implemented by a hybrid cache class, and the data acquisition interface is a method for acquiring data from the hybrid cache defined in the hybrid cache class, wherein the hybrid cache comprises a local cache and a remote cache.
The cache data obtaining module 402 may specifically be configured to: judging whether the current local cache instance obtained through the data acquisition interface is empty or not; if not, obtaining cache data based on the current local cache instance; and if the cache is empty, creating a default local cache instance through the mixed cache class, and acquiring cache data based on the default local cache instance.
The cache data obtaining module 402 may further be configured to: and under the condition that the used cache type is a local cache, if cache data does not exist in the local cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache and writing the cache data into the local cache so as to acquire the cache data from the local cache.
The parameters of the data acquisition interface may include a class name, a method name, and a parameter array of the remote cache.
The cache data obtaining module 402 is further specifically configured to: and reflecting the class name, the method name and the parameter array of the remote cache to obtain a remote cache object, and reflecting and calling a remote cache method in the remote cache object to obtain cache data from the remote cache.
The parameter of the data acquisition interface may include a first parameter, a value of the first parameter indicates whether to use a local cache, and when the value of the first parameter is true, the type of the used cache is the local cache; and when the value of the first parameter is false, the used cache type is remote cache.
In addition, the detailed implementation of the apparatus for acquiring cache data in the embodiment of the present invention has been described in detail in the above method for acquiring cache data, and therefore, the repeated content is not described again.
Fig. 5 shows an exemplary system architecture 500 to which the cache data obtaining method or the cache data obtaining apparatus according to the embodiment of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 501, 502, 503. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for obtaining the cached data provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the obtaining device for the cached data is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing a server according to embodiments of the present application. The server shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present application are executed when the computer program is executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises a cache type determining module and a cache data obtaining module. The names of these modules do not form a limitation on the modules themselves in some cases, for example, the cache type determination module may also be described as "a module for calling a data acquisition interface in the hybrid cache component, and determining the cache type to be used through parameters of the data acquisition interface".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: calling a data acquisition interface in the hybrid cache component, and determining the cache type to be used according to the parameters of the data acquisition interface; obtaining cache data by using the hybrid cache component, wherein the cache data is obtained from a local cache under the condition that the used cache type is the local cache; and under the condition that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache.
According to the technical scheme of the embodiment of the invention, a data acquisition interface in the hybrid cache component is called, and the used cache type is determined according to the parameters of the data acquisition interface; acquiring cache data by using a hybrid cache component, wherein the cache data is acquired from a local cache under the condition that the used cache type is the local cache; and in the case that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring cache data from the remote cache. The method has the advantages that the lengthy code logic judgment of handwriting can be avoided, the manual workload is reduced, the required cache type can be freely selected, local cache can be selectively used or not used, the mixed cache component can be used as a plug-in component to be called, and the universality is high.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method for obtaining cache data is characterized by comprising the following steps:
calling a data acquisition interface in the hybrid cache component, and determining the cache type to be used according to the parameters of the data acquisition interface;
obtaining cache data by using the hybrid cache component, wherein the cache data is obtained from a local cache under the condition that the used cache type is the local cache; and under the condition that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache.
2. The method of claim 1, wherein the hybrid cache component is implemented by a hybrid cache class, and wherein the data fetch interface is a method defined in the hybrid cache class for fetching data from a hybrid cache, wherein the hybrid cache comprises the local cache and the remote cache.
3. The method of claim 2, wherein the retrieving cache data from the local cache comprises:
judging whether the current local cache instance obtained through the data acquisition interface is empty or not; if not, acquiring the cache data based on the current local cache instance; and if the cache data is empty, creating a default local cache instance through the mixed cache class, and acquiring the cache data based on the default local cache instance.
4. The method according to claim 1, wherein in a case where the cache type used is a local cache, if the cache data does not exist in the local cache, a remote cache method provided by the hybrid cache component is invoked through a reflection mechanism, and the cache data is obtained from the remote cache and written into the local cache to obtain the cache data from the local cache.
5. The method according to claim 1 or 4, wherein the parameters of the data acquisition interface comprise a class name, a method name, a parameter array of a remote cache;
the invoking, by the reflection mechanism, a remote caching method provided by the hybrid cache component to obtain the cache data from the remote cache includes:
and reflecting and calling a remote cache method in the remote cache object to obtain cache data from the remote cache.
6. The method of claim 1, wherein the parameters of the data acquisition interface include a first parameter, a value of the first parameter indicates whether to use the local cache, and when the value of the first parameter is true, the type of the cache used is a local cache; and when the value of the first parameter is false, the used cache type is remote cache.
7. An apparatus for obtaining cache data, comprising:
the cache type determining module is used for calling a data acquisition interface in the hybrid cache component and determining the used cache type according to the parameters of the data acquisition interface;
a cache data obtaining module, configured to obtain cache data by using the hybrid cache component, where the cache data is obtained from a local cache when the used cache type is the local cache; and under the condition that the used cache type is a remote cache, calling a remote cache method provided by the hybrid cache component through a reflection mechanism, and acquiring the cache data from the remote cache.
8. The apparatus of claim 7, wherein the hybrid cache component is implemented by a hybrid cache class, and wherein the data fetch interface is a method defined in the hybrid cache class for fetching data from a hybrid cache, the hybrid cache comprising the local cache and the remote cache.
9. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method recited in any of claims 1-6.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN202011287776.8A 2020-11-17 2020-11-17 Cache data acquisition method and device Pending CN113779078A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011287776.8A CN113779078A (en) 2020-11-17 2020-11-17 Cache data acquisition method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011287776.8A CN113779078A (en) 2020-11-17 2020-11-17 Cache data acquisition method and device

Publications (1)

Publication Number Publication Date
CN113779078A true CN113779078A (en) 2021-12-10

Family

ID=78835308

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011287776.8A Pending CN113779078A (en) 2020-11-17 2020-11-17 Cache data acquisition method and device

Country Status (1)

Country Link
CN (1) CN113779078A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103713982A (en) * 2014-01-26 2014-04-09 飞狐信息技术(天津)有限公司 Method and device for monitoring return result of remote service
CN107608759A (en) * 2017-08-31 2018-01-19 深圳市丰巢科技有限公司 Local cache the Visual Implementation method, medium and equipment based on JVM internal memories
CN108920179A (en) * 2017-04-12 2018-11-30 中国移动通信集团福建有限公司 Java reflects implementation method, device and system
CN111694865A (en) * 2020-06-02 2020-09-22 中国工商银行股份有限公司 Four-layer structure data acquisition method and device based on distributed system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103713982A (en) * 2014-01-26 2014-04-09 飞狐信息技术(天津)有限公司 Method and device for monitoring return result of remote service
CN108920179A (en) * 2017-04-12 2018-11-30 中国移动通信集团福建有限公司 Java reflects implementation method, device and system
CN107608759A (en) * 2017-08-31 2018-01-19 深圳市丰巢科技有限公司 Local cache the Visual Implementation method, medium and equipment based on JVM internal memories
CN111694865A (en) * 2020-06-02 2020-09-22 中国工商银行股份有限公司 Four-layer structure data acquisition method and device based on distributed system

Similar Documents

Publication Publication Date Title
CN110019080B (en) Data access method and device
CN111400061A (en) Data processing method and system
CN110473036B (en) Method and device for generating order number
CN110706093A (en) Accounting processing method and device
CN110109983B (en) Method and device for operating Redis database
CN110909022A (en) Data query method and device
CN113626223A (en) Interface calling method and device
CN113076153A (en) Interface calling method and device
CN110764796A (en) Method and device for updating cache
CN112783887A (en) Data processing method and device based on data warehouse
CN113448570A (en) Data processing method and device, electronic equipment and storage medium
US12001458B2 (en) Multi-cloud object store access
CN113672671A (en) Method and device for realizing data processing
CN112948138A (en) Method and device for processing message
CN116226189A (en) Cache data query method, device, electronic equipment and computer readable medium
CN114625458A (en) Page data processing method and device, electronic equipment and storage medium
CN114489674A (en) Data verification method and device of dynamic data model
CN113779078A (en) Cache data acquisition method and device
CN111460273B (en) Information pushing method and device
CN109213815B (en) Method, device, server terminal and readable medium for controlling execution times
CN113434572A (en) Data query method, query system, device, storage medium and program product
CN113312053A (en) Data processing method and device
CN113127416A (en) Data query method and device
CN112699116A (en) Data processing method and system
CN110727739B (en) Data storage method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination