CN113760967A - Data query method and device - Google Patents
Data query method and device Download PDFInfo
- Publication number
- CN113760967A CN113760967A CN202010832938.5A CN202010832938A CN113760967A CN 113760967 A CN113760967 A CN 113760967A CN 202010832938 A CN202010832938 A CN 202010832938A CN 113760967 A CN113760967 A CN 113760967A
- Authority
- CN
- China
- Prior art keywords
- data
- cache
- cache object
- target data
- query
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 49
- 238000004590 computer program Methods 0.000 claims description 9
- 238000012217 deletion Methods 0.000 claims description 7
- 230000037430 deletion Effects 0.000 claims description 7
- 238000010586 diagram Methods 0.000 description 15
- 230000008569 process Effects 0.000 description 11
- 230000000694 effects Effects 0.000 description 10
- 238000004891 communication Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 6
- 238000012545 processing Methods 0.000 description 5
- 230000003287 optical effect Effects 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 238000003491 array Methods 0.000 description 2
- 230000008901 benefit Effects 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
- G06F16/24534—Query rewriting; Transformation
- G06F16/24539—Query rewriting; Transformation using cached or materialised query results
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a data query method and a data query device, and relates to the technical field of computers. One embodiment of the method comprises: receiving a data query request, and judging whether target data corresponding to a data number exists in a cache object of a cache region according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; and placing the cache object comprising the target data in a cache region, and sending the target data to a sender of the data query request. The implementation mode reduces the data caching cost and the system overhead and improves the data query speed.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a data query method and a data query device.
Background
As the data volume increases and the requirement of the user on the response speed increases, the application scenarios of the non-relational database (such as the key-value storage database) are gradually increasing. The non-relational database caches the hot spot data (data with high query frequency) by constructing a cache region, and the storage space of the cache region is used for caching the hot spot data by updating the data in the cache region, so that the effect of quick query is achieved.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
in the existing updating process of data in a cache region, for the data needing to be deleted, directly releasing a cache object corresponding to the data; and a new cache object is applied and created from the database system aiming at the newly added data, so that the data cache cost and the system overhead are increased, and the data query speed is reduced.
Disclosure of Invention
In view of this, embodiments of the present invention provide a data query method and apparatus, which implement reuse of a cache object by constructing a cache object pool, thereby reducing data caching cost and system overhead, and increasing data query speed.
To achieve the above object, according to a first aspect of embodiments of the present invention, there is provided a data query method, including:
receiving a data query request, and judging whether target data corresponding to a data number exists in a cache object of a cache region according to the data number included in the data query request;
if the target data does not exist, inquiring target data corresponding to the data number from the database;
obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data;
and placing the cache object comprising the target data in a cache region, and sending the target data to a sender of the data query request.
Further, before the step of obtaining the cache object from the cache object pool, the method further includes: and judging whether a cache object exists in the cache object pool, if not, deleting data in the cache object in the cache region according to a replacement algorithm, and placing the cache object obtained after deletion in the cache object pool.
Further, still include: and setting an updating period, and updating the data in the cache region according to the updating period and the replacement algorithm.
Further, the permutation algorithm includes at least one of the following algorithms: least recently used permutation algorithm, least used permutation algorithm, and first-in-first-out permutation algorithm.
Further, still include: the total storage space of the cache object is consistent with the size of the available storage space of the cache region.
Further, when the target data corresponding to the data number exists in the cache object of the cache region, the method further includes: and sending the target data to a sender of the data query request, and updating the query state of the target data.
According to a second aspect of the embodiments of the present invention, there is provided a data query apparatus including:
the cache region query module is used for receiving the data query request and judging whether target data corresponding to the data number exists in a cache object of the cache region or not according to the data number included in the data query request;
the database query module is used for querying the target data corresponding to the data number from the database under the condition that the target data corresponding to the data number does not exist in the cache object of the cache region;
the cache object acquisition module is used for acquiring a cache object from a cache object pool and placing target data in the cache object, wherein the cache object has an address space for storing data;
and the data sending module is used for placing the cache object comprising the target data in the cache region and sending the target data to a sender of the data query request.
Further, still include: a judging module, before the step of obtaining the cache object from the cache object pool, for: and judging whether a cache object exists in the cache object pool, if not, deleting data in the cache object in the cache region according to a replacement algorithm, and placing the cache object obtained after deletion in the cache object pool.
According to a third aspect of embodiments of the present invention, there is provided an electronic apparatus, including:
one or more processors;
a storage device for storing one or more programs,
when executed by one or more processors, cause the one or more processors to implement any of the data query methods described above.
According to a fourth aspect of embodiments of the present invention, there is provided a computer-readable medium on which a computer program is stored, the program, when executed by a processor, implementing any one of the data query methods described above.
One embodiment of the above invention has the following advantages or benefits: the data query request is received, and whether the target data corresponding to the data number exists in the cache object of the cache region is judged according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; the technical means of placing the cache object comprising the target data in the cache region and sending the target data to the sender of the data query request overcome the technical problems of increasing data cache cost and system overhead and reducing data query speed caused by continuous release and creation of the cache object in the existing updating process of the data in the cache region, and further achieve the technical effects of reducing the data cache cost and the system overhead and improving the data query speed.
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 of a main flow of a data query method according to a first embodiment of the present invention;
fig. 2 is a schematic diagram of a main flow of a data query method according to a second embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of a data query device provided in an embodiment of the present invention;
FIG. 4 is a schematic diagram of the main framework of a data query system corresponding to the apparatus of FIG. 3;
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 in implementing a terminal device or server of 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 of a main flow of a data query method according to a first embodiment of the present invention; as shown in fig. 1, the data query method provided by the embodiment of the present invention mainly includes:
step S101, receiving a data query request, and judging whether target data corresponding to a data number exists in a cache object of a cache region according to the data number included in the data query request.
Specifically, the data query in the embodiment of the present invention mainly relates to a non-relational database, and the cache area therein is particularly suitable for scenes such as data query, short connection, news content, and commodity content query. The data number and the data detail (target data) are in a one-to-one correspondence relationship, and if the data number is key, the corresponding target data is value. For the received data query request, whether target data corresponding to the data number exists is firstly queried from the cache region, and the data query efficiency is improved.
The cache object is one of storage spaces which are applied and created by the cache region from the database system and is used for storing the newly added data in the cache region.
And step S102, if the target data does not exist, inquiring the target data corresponding to the data number from the database.
And under the condition that the target data corresponding to the data number is not inquired in the cache region, inquiring from the database according to the data number. The database stores the full data, and the cache data in the cache region is only hot data (i.e. data with high query frequency) in the database.
Specifically, according to the embodiment of the present invention, after the step of querying the target data corresponding to the data number from the database, the method further includes: determining that a cache object exists in the cache object pool.
According to the embodiment of the invention, a cache object pool comprising a plurality of cache objects is also constructed outside the cache region, and the cache objects are provided with address spaces for storing data. It should be noted that the cache object is only placed in the cache object pool when the data is not stored, and the cache object needs to be placed in the cache region after the data is stored in the cache object.
Further, if no cache object exists in the cache object pool, the data query method further includes: and deleting the data in the cache objects of the cache region according to a replacement algorithm, and placing the cache objects obtained after deletion in a cache object pool, namely, the data is not stored in the address space of the cache objects in the cache object pool.
Through the arrangement, when no cache object exists in the cache object pool, namely if the cache object is required to cache data in the cache region, a storage space needs to be applied and created, the non-hot data in the cache region is deleted by adopting a replacement algorithm, namely after the cache object is released, the storage space does not need to be applied and created to the database system, the cache object which is just released can be directly and repeatedly used, and the effects of reducing the data caching cost and the system overhead are achieved.
Preferably, according to an embodiment of the present invention, the permutation algorithm comprises at least one of the following algorithms: least recently used permutation algorithm, least used permutation algorithm, and first-in-first-out permutation algorithm.
As can be seen from the above description, the purpose of the replacement algorithm in the present application is to identify non-hot data in the cache region, i.e. to determine the query frequency of the data in the cache region. It should be noted that the above permutation algorithm is only an example and is not a limitation to the embodiment of the present invention.
Least Recently Used replacement algorithm (LRU) which considers data that was Recently Used/queried as hot data and is likely to be Used again the next time, while data that was rarely Used the next time is likely to be unused the next time.
Least Frequently Used permutation algorithms (LFU) consider the data with the lowest frequency of use (query frequency) over a certain period of time to be non-hotspot data.
A First-In First-Out permutation algorithm (FIFO) that considers the data that was First used/queried with a greater probability of not being used again than the data that was just used.
It should be noted that the above permutation algorithm is only an example and is not a limitation to the embodiment of the present invention.
Step S103, obtaining a cache object from the cache object pool, and placing the target data into the cache object, wherein the cache object has an address space for storing data.
Through the setting, an empty cache object (the data is not stored in the empty cache object) is directly obtained from the cache object pool, and the target data is placed in the empty cache object. The method and the device realize the repeated use of the cache object, reduce the data caching cost and the system overhead, and are beneficial to improving the data query speed.
Specifically, according to the embodiment of the present invention, for the same type of data, a plurality of fields (or arrays and other forms) in the cache object respectively correspond to corresponding data details, and the process of placing the target data in the cache object may be: and splitting the target data and writing the split target data into the corresponding fields according to the data types corresponding to the fields in the cache object, namely finishing data assembly.
Further, according to an embodiment of the present invention, the data query method further includes: and setting an updating period, and updating the data in the cache region according to the updating period and the replacement algorithm.
Through the arrangement, the cache region deletes the non-hot data in the cache region at regular time to release the cache object, release the storage space in the cache region and improve the data query efficiency.
Preferably, according to an embodiment of the present invention, the data query method further includes: the total storage space of the cache object is consistent with the size of the available storage space of the cache region.
It should be noted that the cache object is applied and created from the cache region to the database system, and the purpose of constructing the cache object pool is to place an empty cache object, so as to implement reuse of the cache object and reduce the data caching cost. Therefore, the total storage space of the cache object indicates the available storage space of the cache region, and the currently available storage space of the cache region can be determined by whether the cache object exists in the cache object pool or not or the storage space of the cache object in the cache object pool.
And step S104, placing the cache object comprising the target data in a cache region, and sending the target data to a sender of the data query request.
Through the arrangement, the probability that the target data is queried again next time is high, and therefore the target data is placed in the cache region, and the data query speed is improved.
Further, according to the embodiment of the present invention, if the target data corresponding to the data number exists in the cache object in the cache region, the data query method further includes: and sending the target data to a sender of the data query request, and updating the query state of the target data.
Through the arrangement, the query state of the target data is updated, the query frequency corresponding to the target data is determined, and reference is provided for subsequent updating of the data in the cache region.
According to the technical scheme of the embodiment of the invention, the data query request is received, and whether the target data corresponding to the data number exists in the cache object of the cache region is judged according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; the technical means of placing the cache object comprising the target data in the cache region and sending the target data to the sender of the data query request overcome the technical problems of increasing data cache cost and system overhead and reducing data query speed caused by continuous release and creation of the cache object in the existing updating process of the data in the cache region, and further achieve the technical effects of reducing the data cache cost and the system overhead and improving the data query speed.
Fig. 2 is a schematic diagram of a main flow of a data query method according to a second embodiment of the present invention; an application scenario of the embodiment of the present invention is query of merchant information, and as shown in fig. 2, the data query method provided by the embodiment of the present invention mainly includes:
step S201, receiving a data query request, where the data query request includes a data number.
The merchant management system receives a data query request sent by a user through a service system, wherein the request comprises a merchant ID (namely a data number), the merchant ID is a key in a database of the merchant management system, and the corresponding merchant detail information (namely target data) is a value.
Step S202, judging whether the cache object of the cache region has the target data corresponding to the data number. If yes, namely the cache area has target data corresponding to the data number, executing step S208; if not, that is, the cache area does not have the target data corresponding to the data number, step S203 is executed.
The data corresponding to the hot merchants are stored in the cache region, the data corresponding to all the merchants are stored in the database, and after the data query request is received, the data are preferentially queried from the cache objects in the cache region, so that the query efficiency is improved.
In step S203, the target data corresponding to the data number is searched from the database.
Step S204, judging whether a cache object exists in the cache object pool or not, wherein the cache object has an address space for storing data. If yes, namely, the cache object exists in the cache object pool, then step S206 is executed; if not, that is, the cache object does not exist in the cache object pool, go to step S205.
Specifically, after the target data is queried from the database, the data is sent to the cache region, which is beneficial to directly querying the target data in the cache region when the target data is queried subsequently. Through the arrangement, the data query rate is improved.
Step S205, according to the replacement algorithm, deleting the data in the cache object of the cache region, and placing the cache object obtained through deletion into the cache object pool. Then, step S204 is performed.
Through the arrangement, when no cache object exists in the cache object pool, namely if the cache object is required to cache data in the cache region, a storage space needs to be applied and created, the non-hot data in the cache region is deleted by adopting a replacement algorithm, namely after the cache object is released, the storage space does not need to be applied and created to the database system, the cache object which is just released can be directly and repeatedly used, and the effects of reducing the data caching cost and the system overhead are achieved.
According to an embodiment of the invention, the permutation algorithm comprises at least one of the following algorithms: least recently used permutation algorithm, least used permutation algorithm, and first-in-first-out permutation algorithm.
Step S206, obtaining the cache object from the cache object pool, and placing the target data into the cache object.
Specifically, according to the embodiment of the present invention, data is not stored in the address space of the cache object in the cache object pool, for the same type of data, a plurality of fields (or arrays and other forms) in the cache object respectively correspond to corresponding data details, and the process of placing the target data in the cache object may be: and splitting the target data and writing the split target data into the corresponding fields according to the data types corresponding to the fields in the cache object, namely finishing data assembly. For example, the name of the merchant, the address of the merchant, the evaluation of the merchant, etc. are assembled into different fields of the cache object respectively.
Preferably, according to an embodiment of the present invention, the data query method further includes: the total storage space of the cache object is consistent with the size of the available storage space of the cache region.
It should be noted that the cache object is one of the storage spaces applied and created from the cache region to the database system, and the purpose of constructing the cache object pool is to place an empty cache object, so as to implement reuse of the cache object, reduce the data caching cost, and indicate the available storage space of the cache region. Therefore, the total storage space of the cache object indicates the available storage space of the cache region, and the currently available storage space of the cache region can be determined by whether the cache object exists in the cache object pool or not or the storage space of the cache object in the cache object pool.
Further, according to an embodiment of the present invention, the data query method further includes: and setting an updating period, and updating the data in the cache region according to the updating period and the replacement algorithm.
Through the arrangement, the cache region deletes the non-hot data in the cache region at regular time to release the cache object, release the storage space in the cache region and improve the data query efficiency.
Step S207, the cache object including the target data is placed in the cache region, and the target data is sent to the sender of the data query request.
Through the arrangement, the probability that the target data is queried again next time is high, and therefore the target data is placed in the cache region, and the data query speed is improved.
Step S208, the target data is sent to the sending terminal of the data query request, and the query state of the target data is updated.
Through the arrangement, the query state of the target data is updated, the query frequency corresponding to the target data is determined, and reference is provided for subsequent updating of the data in the cache region.
According to the technical scheme of the embodiment of the invention, the data query request is received, and whether the target data corresponding to the data number exists in the cache object of the cache region is judged according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; the technical means of placing the cache object comprising the target data in the cache region and sending the target data to the sender of the data query request overcome the technical problems of increasing data cache cost and system overhead and reducing data query speed caused by continuous release and creation of the cache object in the existing updating process of the data in the cache region, and further achieve the technical effects of reducing the data cache cost and the system overhead and improving the data query speed.
FIG. 3 is a schematic diagram of the main modules of a data query device provided in an embodiment of the present invention; as shown in fig. 3, the data query apparatus 300 according to the embodiment of the present invention mainly includes:
the cache region querying module 301 is configured to receive a data querying request, and determine whether target data corresponding to a data number exists in a cache object in a cache region according to the data number included in the data querying request.
Specifically, the data query in the embodiment of the present invention mainly relates to a non-relational database, and the cache area therein is particularly suitable for scenes such as data query, short connection, news content, and commodity content query. The data number and the data detail (target data) are in a one-to-one correspondence relationship, and if the data number is key, the corresponding target data is value. For the received data query request, whether target data corresponding to the data number exists is firstly queried from the cache region, and the data query efficiency is improved.
The cache object is one of storage spaces which are applied and created by the cache region from the database system and is used for storing the newly added data in the cache region.
The database query module 302 is configured to query the database for the target data corresponding to the data number when the target data corresponding to the data number does not exist in the cache object in the cache region.
And under the condition that the target data corresponding to the data number is not inquired in the cache region, inquiring from the database according to the data number. The database stores the full data, and the cache data in the cache region is only the hot data in the database.
Specifically, according to the embodiment of the present invention, the data querying device 300 further includes a cache object determining module, and after the step of querying the target data corresponding to the data number from the database, the cache object determining module is configured to: determining that a cache object exists in the cache object pool.
According to the embodiment of the invention, a cache object pool comprising a plurality of cache objects is also constructed outside the cache region, and the cache objects are provided with address spaces for storing data. It should be noted that the cache object is only placed in the cache object pool when the data is not stored, and the cache object needs to be placed in the cache region after the data is stored in the cache object.
Further, if there is no cache object in the cache object pool, the cache object determining module is further configured to: and deleting the data in the cache objects of the cache region according to a replacement algorithm, and placing the cache objects obtained after deletion in a cache object pool, namely, the data is not stored in the address space of the cache objects in the cache object pool.
Through the arrangement, when no cache object exists in the cache object pool, namely if the cache object is required to cache data in the cache region, a storage space needs to be applied and created, the non-hot data in the cache region is deleted by adopting a replacement algorithm, namely after the cache object is released, the storage space does not need to be applied and created to the database system, the cache object which is just released can be directly and repeatedly used, and the effects of reducing the data caching cost and the system overhead are achieved.
Preferably, according to an embodiment of the present invention, the permutation algorithm comprises at least one of the following algorithms: least recently used permutation algorithm, least used permutation algorithm, and first-in-first-out permutation algorithm.
As can be seen from the above description, the purpose of the replacement algorithm in the present application is to identify non-hot data in the cache region, i.e. to determine the query frequency of the data in the cache region. It should be noted that the above permutation algorithm is only an example and is not a limitation to the embodiment of the present invention.
A cache object obtaining module 303, configured to obtain a cache object from the cache object pool, and place the target data in the cache object, where the cache object has an address space for storing data.
Through the setting, an empty cache object (the data is not stored in the empty cache object) is directly obtained from the cache object pool, and the target data is placed in the empty cache object. The method and the device realize the repeated use of the cache object, reduce the data caching cost and the system overhead, and are beneficial to improving the data query speed.
Further, according to the embodiment of the present invention, the data query apparatus 300 further includes a data update module, configured to: and setting an updating period, and updating the data in the cache region according to the updating period and the replacement algorithm.
Through the arrangement, the cache region deletes the non-hot data in the cache region at regular time to release the cache object, release the storage space in the cache region and improve the data query efficiency.
Preferably, according to the embodiment of the present invention, the total storage space of the cache object is consistent with the size of the available storage space of the cache region.
It should be noted that the cache object is applied and created from the cache region to the database system, and the purpose of constructing the cache object pool is to place an empty cache object, so as to implement reuse of the cache object and reduce the data caching cost. Therefore, the total storage space of the cache object indicates the available storage space of the cache region, and the currently available storage space of the cache region can be determined by whether the cache object exists in the cache object pool or not or the storage space of the cache object in the cache object pool.
And the data sending module 304 is configured to place the cache object including the target data in the cache region, and send the target data to a sender of the data query request.
Through the arrangement, the probability that the target data is queried again next time is high, and therefore the target data is placed in the cache region, and the data query speed is improved.
Further, according to the embodiment of the present invention, if the target data corresponding to the data number exists in the cache object in the cache region, the data sending module 304 is further configured to: and sending the target data to a sender of the data query request, and updating the query state of the target data.
Through the arrangement, the query state of the target data is updated, the query frequency corresponding to the target data is determined, and reference is provided for subsequent updating of the data in the cache region.
FIG. 4 is a schematic diagram of the main framework of a data query system corresponding to the apparatus of FIG. 3; as shown in fig. 4, the service system is a sender of a data query request, where a data number in the data query request is a query number (id), and the data number corresponds to target data time detail (detail) data; a JVM (Java Virtual Machine) cache pool, i.e., a cache area; the memory object pool is a cache object pool; a data source is a database that stores the full amount of data.
After receiving a data query request including a query number sent by a service system, a data query system firstly queries whether detail data (target data) corresponding to the query number exists in a JVM cache pool, and if the detail data exists, the data query system directly sends the detail data to the service system; if the target data does not exist, the detailed data corresponding to the query number is queried from the data source, then a memory object is obtained from the memory object pool to assemble the target data, the memory object comprising the target data is placed in the JVM cache pool, and then the target data is sent to the service system. If the memory object does not exist in the memory object pool, deleting data from the JVM cache pool according to the LRU algorithm, placing the released memory object in the memory object pool, then executing the operation of assembling the target data, placing the memory object comprising the target data in the JVM cache pool, and then sending the memory object to the service system.
According to the technical scheme of the embodiment of the invention, the data query request is received, and whether the target data corresponding to the data number exists in the cache object of the cache region is judged according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; the technical means of placing the cache object comprising the target data in the cache region and sending the target data to the sender of the data query request overcome the technical problems of increasing data cache cost and system overhead and reducing data query speed caused by continuous release and creation of the cache object in the existing updating process of the data in the cache region, and further achieve the technical effects of reducing the data cache cost and the system overhead and improving the data query speed.
Fig. 5 illustrates an exemplary system architecture 500 of a data query method or data query apparatus to which embodiments of the 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 (this architecture is merely an example, and the components included in a particular architecture may be adapted according to application specific circumstances). 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 data query request, and feed back a processing result (for example, target data — just an example) to the terminal device.
It should be noted that the data query method provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the data query apparatus 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, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device 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 invention.
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 computer program performs the above-described functions defined in the system of the present invention when 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 invention, 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 the present invention, 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 invention. 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 region query module, a database query module, a cache object acquisition module and a data sending module. The names of these modules do not form a limitation on the modules themselves in some cases, for example, the cache area query module may also be described as "a module for receiving a data query request and determining whether target data corresponding to a data number exists in a cache object in a cache area according to the data number included in the data query request".
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: receiving a data query request, and judging whether target data corresponding to a data number exists in a cache object of a cache region according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; and placing the cache object comprising the target data in a cache region, and sending the target data to a sender of the data query request.
According to the technical scheme of the embodiment of the invention, the data query request is received, and whether the target data corresponding to the data number exists in the cache object of the cache region is judged according to the data number included in the data query request; if the target data does not exist, inquiring target data corresponding to the data number from the database; obtaining a cache object from a cache object pool, and placing target data in the cache object, wherein the cache object has an address space for storing data; the technical means of placing the cache object comprising the target data in the cache region and sending the target data to the sender of the data query request overcome the technical problems of increasing data cache cost and system overhead and reducing data query speed caused by continuous release and creation of the cache object in the existing updating process of the data in the cache region, and further achieve the technical effects of reducing the data cache cost and the system overhead and improving the data query speed.
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 querying data, comprising:
receiving a data query request, and judging whether target data corresponding to a data number exists in a cache object of a cache region according to the data number included in the data query request;
if the target data does not exist, inquiring target data corresponding to the data number from a database;
obtaining a cache object from a cache object pool, and placing the target data in the cache object, wherein the cache object has an address space for storing data;
and placing the cache object comprising the target data in the cache region, and sending the target data to a sender of the data query request.
2. The data query method of claim 1, prior to the step of obtaining the cache object from the cache object pool, further comprising: and judging whether a cache object exists in the cache object pool, if not, deleting data in the cache object in the cache region according to a replacement algorithm, and placing the cache object obtained after the deletion in the cache object pool.
3. The data query method of claim 1, further comprising:
and setting an updating period, and updating the data in the cache region according to the updating period and the replacement algorithm.
4. A data query method as claimed in claim 2 or 3, wherein the permutation algorithm comprises at least one of the following algorithms: least recently used permutation algorithm, least used permutation algorithm, and first-in-first-out permutation algorithm.
5. The data query method of claim 1, further comprising:
the total storage space of the cache object is consistent with the size of the available storage space of the cache region.
6. The data query method according to claim 1, when target data corresponding to the data number exists in the cache object in the cache region, further comprising: and sending the target data to a sender of the data query request, and updating the query state of the target data.
7. A data query apparatus, comprising:
the cache region query module is used for receiving a data query request and judging whether target data corresponding to the data number exists in a cache object of a cache region or not according to the data number included in the data query request;
the database query module is used for querying the target data corresponding to the data number from a database under the condition that the target data corresponding to the data number does not exist in the cache object of the cache region;
the cache object obtaining module is used for obtaining a cache object from a cache object pool and placing the target data in the cache object, wherein the cache object has an address space for storing data;
and the data sending module is used for placing the cache object comprising the target data in the cache region and sending the target data to a sender of the data query request.
8. The data query apparatus of claim 7, further comprising: a determining module, configured to, before the step of obtaining the cache object from the cache object pool: and judging whether a cache object exists in the cache object pool, if not, deleting data in the cache object in the cache region according to a replacement algorithm, and placing the cache object obtained after the deletion in the cache object pool.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one 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.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010832938.5A CN113760967A (en) | 2020-08-18 | 2020-08-18 | Data query method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010832938.5A CN113760967A (en) | 2020-08-18 | 2020-08-18 | Data query method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113760967A true CN113760967A (en) | 2021-12-07 |
Family
ID=78785597
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010832938.5A Pending CN113760967A (en) | 2020-08-18 | 2020-08-18 | Data query method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113760967A (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101110074A (en) * | 2007-01-30 | 2008-01-23 | 浪潮乐金信息系统有限公司 | Data speedup query method based on file system caching |
CN101765096A (en) * | 2008-12-26 | 2010-06-30 | 中兴通讯股份有限公司 | Method, device and system for querying order relations |
CN109885589A (en) * | 2017-12-06 | 2019-06-14 | 腾讯科技(深圳)有限公司 | Data query method, apparatus, computer equipment and storage medium |
CN110633296A (en) * | 2018-05-31 | 2019-12-31 | 北京京东尚科信息技术有限公司 | Data query method, device, medium and electronic equipment |
-
2020
- 2020-08-18 CN CN202010832938.5A patent/CN113760967A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101110074A (en) * | 2007-01-30 | 2008-01-23 | 浪潮乐金信息系统有限公司 | Data speedup query method based on file system caching |
CN101765096A (en) * | 2008-12-26 | 2010-06-30 | 中兴通讯股份有限公司 | Method, device and system for querying order relations |
CN109885589A (en) * | 2017-12-06 | 2019-06-14 | 腾讯科技(深圳)有限公司 | Data query method, apparatus, computer equipment and storage medium |
CN110633296A (en) * | 2018-05-31 | 2019-12-31 | 北京京东尚科信息技术有限公司 | Data query method, device, medium and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110019211A (en) | The methods, devices and systems of association index | |
CN108984553B (en) | Caching method and device | |
CN110837409A (en) | Method and system for executing task regularly | |
CN110909022A (en) | Data query method and device | |
CN107844488B (en) | Data query method and device | |
CN111339057A (en) | Method, apparatus and computer readable storage medium for reducing back-to-source requests | |
CN110648216A (en) | Wind control method and device | |
CN112445988A (en) | Data loading method and device | |
CN112783887A (en) | Data processing method and device based on data warehouse | |
CN113220981A (en) | Method and device for optimizing cache | |
CN109213815B (en) | Method, device, server terminal and readable medium for controlling execution times | |
CN113360528A (en) | Data query method and device based on multi-level cache | |
CN112699116A (en) | Data processing method and system | |
CN109144991B (en) | Method and device for dynamic sub-metering, electronic equipment and computer-storable medium | |
CN112395337A (en) | Data export method and device | |
CN112711572B (en) | Online capacity expansion method and device suitable for database and table division | |
CN113138943B (en) | Method and device for processing request | |
CN113127416B (en) | Data query method and device | |
CN113760967A (en) | Data query method and device | |
CN112988857B (en) | Service data processing method and device | |
CN110019671B (en) | Method and system for processing real-time message | |
CN113704242A (en) | Data processing method and device | |
CN113722193A (en) | Method and device for detecting page abnormity | |
CN113760965B (en) | Data query method and device | |
CN112783914A (en) | Statement optimization 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 |