Cache data query method and device, electronic equipment and readable storage medium

Through the combination of hash functions and bit arrays, the problem of low cache data query efficiency is solved, and rapid positioning and efficient query of massive task results are achieved, thereby improving cache query efficiency and space utilization.

CN120804160APending Publication Date: 2025-10-17CHINA MOBILE INFORMATION TECHNOLOGY CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510932627.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-07
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

The cache data query method in the prior art has low query efficiency when processing large-scale tasks.

Method used

A hash function is used to calculate the task identifier. The combination of bit array and cache database is used to find the target element through the hash value and extract the result. The number of hash functions and bit array density are adjusted to optimize the query process.

Benefits of technology

It achieves rapid positioning of massive task results, improves the efficiency and accuracy of cache queries, optimizes cache space utilization, and reduces system resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120804160A_ABST
    Figure CN120804160A_ABST
Patent Text Reader

Abstract

The invention discloses a cache data query method and device, electronic equipment and a readable storage medium, relates to the technical field of information technologies, and aims to solve the problem of relatively low cache data query efficiency. The method comprises the steps of obtaining a task identifier of a to-be-queried task; calculating the task identifier by using a hash function to obtain a hash value; searching elements in a bit array based on the hash value to obtain a target element; and under the condition that the value of the target element represents that the result of the to-be-queried task is in a cached state, extracting the result of the to-be-queried task from a cache database. According to the embodiment of the invention, the cache data query efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of information technology (IT), and in particular to a cache data query method and device, an electronic device and a readable storage medium. BACKGROUND

[0002] The cache data query method in the prior art is usually to construct a cache key according to a business parameter and query in a cache database based on the cache key. A smart middle platform is a hub platform integrating data capabilities, artificial intelligence (AI) algorithm capabilities and business service capabilities, and is used to support the rapid development and operation of various intelligent businesses of an enterprise.

[0003] Since the number of tasks processed by the smart middle platform is large, the query efficiency of the cache data query method commonly used in the prior art will be significantly reduced when processing large-scale tasks. SUMMARY

[0004] Embodiments of the present application provide a cache data query method and device, an electronic device and a readable storage medium to solve the problem of low cache data query efficiency.

[0005] In a first aspect, the embodiments of the present application provide a cache data query method, comprising:

[0006] obtaining a task identifier of a to-be-queried task;

[0007] calculating the task identifier using a hash function to obtain a hash value;

[0008] finding an element in a bit array based on the hash value to obtain a target element;

[0009] in a case where a value of the target element represents that a result of the to-be-queried task is in a cached state, extracting the result of the to-be-queried task from a cache database.

[0010] Optionally, the number of hash functions is a plurality, and different hash functions are used to determine different target elements.

[0011] The extracting the result of the to-be-queried task from the cache database in the case where the value of the target element represents that the result of the to-be-queried task is in the cached state, comprises:

[0012] extracting the result of the to-be-queried task from the cache database in a case where values of all the target elements represent that the result of the to-be-queried task is in the cached state.

[0013] Optionally, before the calculating the task identifier by using the hash function to obtain a hash value, the method further comprises:

[0014] adjusting the number of hash functions based on the density of the bit array, the density being determined based on a ratio of a target number to a size of the bit array, the target number being a number of elements in the bit array having a first value, the first value being used to represent that a result of a task corresponding to the element is in a cached state;

[0015] resetting the bit array according to a preset policy, and setting values of all elements in the bit array to a second value, the second value being used to represent that the result of the task corresponding to the element is in an uncached state.

[0016] Optionally, the adjusting the number of hash functions based on the density of the bit array comprises:

[0017] in a case where the density is greater than a first preset value, increasing the number of hash functions;

[0018] in a case where the density is less than a second preset value, decreasing the number of hash functions.

[0019] Optionally, after the finding the target element based on the hash value in the elements of the bit array, the method further comprises:

[0020] in a case where the value of the target element represents that the result of the task to be queried is in the uncached state, obtaining the result of the task to be queried;

[0021] storing the result of the task to be queried into the cache database;

[0022] adjusting the value of the target element, so that the value of the target element represents that the result of the task to be queried is in the cached state.

[0023] Optionally, the obtaining the result of the task to be queried comprises:

[0024] calculating the task to be queried to obtain the result of the task to be queried;

[0025] or, initiating a query request to a database, and determining the result of the task to be queried based on a query result returned by the database based on the query request.

[0026] Optionally, before the obtaining the task identifier of the task to be queried, the method further comprises:

[0027] receiving a task request sent by a request end, the task request carrying task information of a target task;

[0028] Split the target task into a plurality of the to-be-queried tasks based on the task information.

[0029] In a second aspect, the embodiment of the present application further provides a cache data query device, comprising:

[0030] The first obtaining module is configured to obtain a task identifier of a to-be-queried task.

[0031] The computing module is configured to calculate the task identifier using a hash function to obtain a hash value.

[0032] The searching module is configured to search an element in the bit array based on the hash value to obtain a target element.

[0033] The extracting module is configured to extract a result of the to-be-queried task from the cache database in a case where a value of the target element represents that the result of the to-be-queried task is in a cached state.

[0034] In a third aspect, the embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a program stored in the memory and capable of running on the processor.

[0035] The processor is configured to read the program in the memory to implement the steps in the cache data query method according to the first aspect.

[0036] In a fourth aspect, the embodiment of the present application further provides a readable storage medium for storing a program, which is executed by a processor to implement the steps in the cache data query method according to the first aspect.

[0037] In the embodiment of the present application, first, a task identifier of a to-be-queried task is obtained; then, a hash function is used to calculate the task identifier to obtain a hash value; an element in a bit array is searched based on the hash value to obtain a target element; finally, in a case where a value of the target element represents that a result of the to-be-queried task is in a cached state, the result of the to-be-queried task is extracted from a cache database. The embodiment provides an efficient cache query mechanism, and through the combination of the bit array and the hash function, the fast positioning of a mass of task results can be implemented, and the efficiency of cache query is improved. BRIEF DESCRIPTION OF DRAWINGS

[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.

[0039] Figure 1is a flow chart of the cache data query method provided by the embodiment of the application;

[0040] Figure 2 is a schematic diagram of the cache data query system provided by the embodiment of the application;

[0041] Figure 3 is a structural diagram of the cache data query device provided by the embodiment of the application;

[0042] Figure 4 is a structural diagram of the electronic device provided by the embodiment of the application. DETAILED DESCRIPTION

[0043] The technical solutions in the embodiments of the application will be clearly and completely described below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are some but not all of the embodiments of the application. Based on the embodiments in the application, all other embodiments obtained by a person of ordinary skill in the art without creative effort should fall within the protection scope of the application.

[0044] In the embodiments of the application, the term "and / or" describes the association relationship of associated objects, and indicates that there can be three relationships, for example, A and / or B can indicate that A exists alone, A and B exist together, and B exists alone. The character " / " generally indicates that the associated objects before and after it are in an "or" relationship. In the embodiments of the application, the term "multiple" refers to two or more than two, and other quantifiers are similar. In the specification and claims of the application, the terms "first", "second", and the like are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged under appropriate circumstances, so that the embodiments of the application can be implemented in an order other than that illustrated or described herein, and the objects distinguished by "first", "second" are usually of a kind, and the number of objects is not limited, for example, the first object can be one or more.

[0045] First, some terms involved in the application are introduced:

[0046] Bit Array: A data structure used to save space and efficiently represent Boolean values (0 / 1), used to efficiently store and manipulate bit-level data. As a specific bit array, the bit array is a one-dimensional array composed of binary bits, and each element can only be 0 or 1.

[0047] Hash Function: A function that converts inputs of arbitrary length (such as strings, files, and numbers) into fixed-length output values (called hash values or hash values). This process can also be called Hashing.

[0048] Based on this, the embodiment of the application provides a cache data query method and device, an electronic device and a readable storage medium, aiming to improve the query efficiency of cache data. As shown in the figure, the cache data query method specifically includes the following steps: Figure 1

[0049] Step 101, obtaining the task identifier of the to-be-queried task.

[0050] It should be understood that the task identifier is unique and can uniquely determine the to-be-queried task and its result. Specifically, the specific format of the task identifier is not limited here. As an optional implementation, the task identifier is determined based on at least one of the following: the name of the to-be-queried task, the number of the to-be-queried task, and the parameter combination of the to-be-queried task.

[0051] In some embodiments, after the task identifier is extracted from the to-be-queried task, the task identifier needs to be preprocessed to meet the input requirements of the hash function. Specifically, the preprocessing of the task identifier includes format conversion and deduplication processing, etc.

[0052] Optionally, in some embodiments, before step 101, the method further includes:

[0053] receiving a task request sent by a request end, the task request carrying task information of a target task;

[0054] Based on the task information, the target task is split into a plurality of to-be-queried tasks.

[0055] The method provided by the embodiment of the application can be executed by a server. As a specific embodiment, the server includes a task control module, which is used to receive a task request sent by a request end.

[0056] In specific implementation, a user sends a task request through a request end. Specifically, the user can choose to initiate a task request through a client (such as a mobile application (Application, APP) or a web version platform). For scenarios that need to be integrated into a third-party system or an automated process, the user can also initiate a task request through an application programming interface (Application Programming Interface, API) interface.

[0057] It should be understood that the task information includes a task type and / or a task parameter. After receiving the task request, the server will verify the task information. Specifically, by verifying the task parameter, it is ensured that the parameter is complete, legal and in line with the business rules.

[0058] ​As an optional implementation, the task request also carries authentication information. In this implementation, the server first verifies the authentication information to ensure that the task request comes from a legal user or an authorized system before verifying the task information. Specifically, the specific manner of verifying the authentication information is not limited here. For example, the verification manner can be a username and password verification, an OAuth2.0 authorization manner, or an API key verification, and the like.

[0059] In some embodiments, the server parses the task request, extracts key information and requirements based on the task information, determines the complexity of the target task and the type of data required to be processed according to the task type, splits the target task into multiple sub-tasks based on the complexity of the target task and the type of data, and each sub-task contains a data segment and a logic processing unit required for execution, and each sub-task is a to-be-queried task.

[0060] Specifically, the server determines whether the target task can be decomposed into multiple sub-tasks according to the complexity of the target task and the amount of data required to be processed, considers the logical structure of the target task, the data dependency relationship, and the possibility of parallel processing. In the case where it is determined that the target task can be split, a task decomposition strategy is formulated to confirm that the decomposed sub-tasks can be executed independently, and the execution results can be combined to obtain the final task result. Specifically, the task decomposition strategy includes the granularity of decomposition, the division manner of sub-tasks, the dependency relationship between sub-tasks, and the like.

[0061] In some embodiments, when the target task is split into multiple to-be-queried tasks based on the task information, the task identifier of each to-be-queried task can be generated based on the task decomposition related logic.

[0062] Compared with the case of caching the related data of the task and the service based on the entire task, in this embodiment, a task is split into multiple sub-tasks, and each sub-task is queried as a to-be-queried task. Through the above manner, the cache granularity is reduced, and it can be better applied to a business environment such as a smart middle platform with high complexity and large differentiation.

[0063] Step 102, calculating the task identifier using a hash function to obtain a hash value.

[0064] In this embodiment, the task identifier is calculated using a hash function to obtain a hash value. The hash value is a numerical value or a binary string, which is used to locate the cache position of the result of the to-be-queried task in the bit array. Specifically, the number of hash functions is not limited here, and each hash function can calculate a hash value.

[0065] Optionally, in some embodiments, the number of hash functions is multiple, and the number of hash functions is determined based on the size of the bit array, and different hash functions are used to determine different target elements.

[0066] In this embodiment, the number of hash functions is multiple, and multiple different hash values can be calculated by using multiple different hash functions. The number of hash functions is determined based on the size of the bit array, and generally, the number of hash functions is positively correlated with the size of the bit array.

[0067] It should be understood that the size of the bit array is determined in advance based on business requirements and the size of the cached data, and the size of the bit array should be large enough to accommodate all possible cache item identifiers, while also considering the efficiency of memory usage. In specific implementation, the server or cache system needs to allocate sufficient memory space for the bit array, and ensure that the allocated memory space is continuous to improve access efficiency.

[0068] In specific implementation, the number of hash functions and the parameters of the hash functions are determined during initialization, and appropriate parameters such as seed values and coefficients are set for each hash function to ensure the diversity and independence of the hash functions. The hash functions should have good distribution and collision resistance to ensure that task identifiers can be uniformly mapped to the bit array.

[0069] In this embodiment, on the one hand, using multiple hash functions can reduce the probability of multiple task identifiers calculating the same hash value, thereby reducing hash collision, which improves the lookup and insertion efficiency of the data structure. On the other hand, multiple hash functions can effectively disperse data and map a task identifier to multiple hash values, greatly reducing the false positive rate.

[0070] Step 103, based on the hash value, find the element in the bit array, and get the target element.

[0071] In this embodiment, the bit array is checked based on the hash value to obtain the element corresponding to the hash value in the bit array, which is the target element, used to record whether the result of the queried task is cached. As a specific implementation, the value of the target element includes two cases, in the first case, the value of the target element is a first value (for example, 1), and the first value is used to represent that the result of the task represented by the element is in a cached state, in the second case, the value of the target element is a second value (for example, 0), and the second value is used to represent that the result of the task represented by the element is in an uncached state.

[0072] It should be understood that in the embodiment where the number of hash functions is multiple, the number of calculated hash values is also multiple, and one target element can be found based on each hash value. In this embodiment, the number of target elements is multiple.

[0073] In step 104, if the value of the target element represents that the result of the to-be-queried task is in the cached state, the result of the to-be-queried task is extracted from the cache database.

[0074] It should be understood that the cache database is used to temporarily store the subtask execution result, so as to facilitate the efficient execution of subsequent tasks. In the case where the value of the target element represents that the result of the to-be-queried task is in the cached state, the result of the to-be-queried task can be directly extracted from the cache database, without the need to repeatedly execute the to-be-queried task, thereby realizing the rapid reuse of the task and improving the processing efficiency of the task.

[0075] Optionally, in the case where the number of hash functions is multiple, the step 104 comprises:

[0076] In the case where the value of all the target elements represents that the result of the to-be-queried task is in the cached state, the result of the to-be-queried task is extracted from the cache database.

[0077] In the embodiment where the number of hash functions is multiple, multiple target elements can be queried. In this embodiment, when the values of all the queried target elements represent that the result of the to-be-queried task is in the cached state, it is considered that the result of the to-be-queried task is cached, and the result of the to-be-queried task is extracted from the cache database, otherwise it is considered that the result of the to-be-queried task is not cached. Through the above manner, the accuracy of the query result can be improved, and the false storage and false judgment can be avoided.

[0078] Optionally, in some embodiments, after the step 103, the method further comprises:

[0079] In the case where the value of the target element represents that the result of the to-be-queried task is in the uncached state, the result of the to-be-queried task is obtained;

[0080] The result of the to-be-queried task is stored in the cache database;

[0081] The value of the target element is adjusted, so that the value of the target element represents that the result of the to-be-queried task is in the cached state.

[0082] It should be understood that in the case where the result of the to-be-queried task is not cached, the result of the to-be-queried task cannot be obtained from the cache database. At this time, according to the requirement of the to-be-queried task, it is determined whether the result of the to-be-queried task is directly calculated or obtained from the database.

[0083] Optionally, in some embodiments, the obtaining the result of the to-be-queried task comprises:

[0084] computing the to-be-queried task to obtain the result of the to-be-queried task.

[0085] In the case where the to-be-queried task involves complex data processing or algorithm computation, the result of the to-be-queried task is obtained by computing directly on the server. Specifically, for a task that needs to be computed, a corresponding algorithm or logic processing unit is called to perform computation. In a specific implementation, whether to perform computation directly on the server can be determined based on the amount of data to be processed and the computation algorithm to be used.

[0086] Optionally, in some embodiments, the obtaining the result of the to-be-queried task comprises:

[0087] After obtaining the result of the to-be-queried task by computation or query, a query request is initiated to the database, and the result of the to-be-queried task is determined based on a query result returned by the database based on the query request. The database is configured to store the subtask computation result persistently.

[0088] In a specific implementation, if the required data is not queried in the cache database, and based on the data source required for defining the task and the data dependency relationship identified when the subtasks are divided, it can be determined whether a query request needs to be initiated to the database.

[0089] In the case where the to-be-queried task depends on data stored in the database, after a query request is initiated to the database and the query result is obtained, the result of the to-be-queried task is determined based on the query result. Whether the query result is further processed to obtain the result of the to-be-queried task mainly depends on the business logic of the to-be-queried task. Specifically, for a task that needs to query the database, a structured query language (SQL) or other query command is constructed, a request is initiated to the database, and a query result is obtained.

[0090] It should be understood that after the query result or the result of the to-be-queried task is obtained, the query result or the result of the to-be-queried task can be verified to determine the correctness and integrity of the result. In some embodiments, the result is a string of data, and the MD5 check value of the data is calculated to ensure the integrity of the data and the consistency with the original data.

[0091] It should be understood that the results of the query task can be stored in the cache database according to a preset cache strategy. For example, an appropriate cache strategy is selected based on business needs and data characteristics, such as Least Recently Used (LRU) or Least Frequently Used (LFU).

[0092] Specifically, the cache storage location and format can be an in-memory hash table, Redis cache, etc. Specifically, if an in-memory hash table is used, the hash value of the result is calculated according to the hash function and the result is stored in the corresponding hash bucket. If an external cache system such as Redis is used, the result is written to the cache through the corresponding client library.

[0093] After storage is complete, the value of the corresponding target element is adjusted so that the value of the target element indicates that the result of the task to be queried is in a cached state. For example, the value of the target element is changed from 0 to 1 to indicate that the result of the task to be queried is cached. In the case of multiple hash functions, multiple corresponding target elements can be obtained. In this embodiment, the values ​​of all target elements need to be adjusted.

[0094] In this embodiment, the task to be queried is a subtask split from the target task. By storing the results of the task to be queried separately, it is convenient to reuse the subtasks, which can effectively improve data processing efficiency and optimize cache space utilization, thereby reducing resource consumption of application services and controlling system operating costs.

[0095] Optionally, in some embodiments, before calculating the task identifier using a hash function to obtain a hash value, the method further includes:

[0096] adjusting the number of hash functions based on a density of the bit array, the density being determined based on a ratio of a target number to a size of the bit array, the target number being the number of elements in the bit array having a first value, the first value being used to indicate that a result of a task corresponding to the element is in a cached state;

[0097] The bit array is reset according to a preset strategy, and the values ​​of all elements in the bit array are set to a second value, where the second value is used to indicate that the result of the task corresponding to the element is in an uncached state.

[0098] It should be understood that the timing of resetting the bit array according to the preset strategy can be adjusted and set according to actual conditions, but in order to make the hash value calculated by using the hash function for the task identifier accurate, it is necessary to complete the operation of resetting the bit array before performing the hash value calculation.

[0099] As an optional implementation, the bit array is reset according to a preset strategy, including:

[0100] The bit array is reset when the server is updated or restarted. By setting the emptying operation of the bit array to be synchronized with the update timing of the server, the consistency of the cache data can be ensured.

[0101] As another optional implementation, the bit array is reset according to a preset strategy, including:

[0102] The bit array is reset according to a preset period. The preset period can be daily, weekly, monthly, etc. By a timing task or a trigger, the expired or invalid cache item identifiers in the bit array are cleaned up periodically according to the preset period, so that the timeliness of the cache data can be ensured.

[0103] As another optional implementation, the bit array is reset according to a preset strategy, including:

[0104] The bit array is reset when the load of the server is lower than a preset value. In this embodiment, the load of the server is detected, and the bit array is emptied when the load of the server is lower than the preset value, so that the influence of the emptying operation on the server performance in a high load state can be avoided.

[0105] It should be understood that the hash function can be reset each time the bit array is emptied, so that the number of hash functions is more reasonable. Alternatively, in some embodiments, the number of hash functions is adjusted based on the density of the bit array, including:

[0106] When the density is greater than a first preset value, the number of hash functions is increased;

[0107] When the density is less than a second preset value, the number of hash functions is reduced.

[0108] Specifically, assuming that the size of the bit array is m, the number of elements (i.e. set bits) with the first value is n, and the density of the bit array is p = n / m. According to the density p and a preset false positive rate threshold value e, the number of hash functions k can be dynamically adjusted. As a specific embodiment, when p is greater than a first preset value p_max, the value of k is increased, and when p is less than a second preset value p_min, the value of k is reduced.

[0109] In this embodiment, the number of hash functions is dynamically adjusted based on the current density of the bit array (i.e., the proportion of set bits). When the density is too high, increasing the number of hash functions can reduce the false positive rate, while when the density is too low, reducing the number of hash functions can save space. This method allows the cache system to more flexibly adapt to different application scenarios and data characteristics, further improving cache efficiency and space utilization. This approach also enables the cache system to better handle time-sensitive data and increase the proportion of fresh data in the cache.

[0110] In an embodiment of the present application, a task identifier for the task to be queried is obtained; a hash function is used to calculate the task identifier to obtain a hash value; an element in a bit array is searched based on the hash value to obtain a target element; and if the value of the target element indicates that the result of the task to be queried is in a cached state, the result of the task to be queried is extracted from the cache database. This embodiment provides an efficient cache query mechanism that, through the combination of a bit array and a hash function, can quickly locate the results of a large number of quantum tasks, thereby improving the efficiency of cache queries.

[0111] See Figure 2 , an embodiment of the present invention also provides a cache query system, which includes a client and a server, and the server includes a task control module, a bit array, a hash function module and a cache database. The request end is used to send a task request to the server. In a specific implementation, the request end is a mid-stage task or service call and initiator. The task control module is used to identify and disassemble the target task according to the requested task type after receiving the request, obtain the task to be queried, and call the bit array and hash function module according to the task to be queried to complete the corresponding logical execution. During the task execution process, the cache database also needs to be read and written according to the data interaction results. The bit array is used to record and control the mapping relationship between the task and the cache. The hash function module is used to call the hash function, calculate the hash value, and control the calculation process of the mapping relationship between the bit array and the task.

[0112] See Figure 3 , an embodiment of the present invention further provides a cache data query device 300. Figure 3 The structure diagram of the cache data query device 300 provided in the embodiment of the present invention. Figure 1 The cache data query method shown is similar, so the implementation of the cache data query device 300 can refer to the implementation of the method, and the repeated parts are not repeated.

[0113] like Figure 3 As shown, the cache data query device 300 includes:

[0114] The first obtaining module 301 is configured to obtain a task identifier of a task to be queried.

[0115] The computing module 302 is configured to compute the task identifier by using a hash function to obtain a hash value.

[0116] The searching module 303 is configured to search an element in a bit array based on the hash value to obtain a target element.

[0117] The extracting module 304 is configured to extract a result of the task to be queried from a cache database in a case where a value of the target element represents that the result of the task to be queried is in a cached state.

[0118] Optionally, the number of hash functions is a plurality, and different hash functions are used to determine different target elements.

[0119] The extracting module 304 is specifically configured to:

[0120] extract the result of the task to be queried from the cache database in a case where values of all target elements represent that the result of the task to be queried is in a cached state.

[0121] Optionally, the cache data query apparatus 300 further includes:

[0122] The first adjusting module is configured to adjust the number of hash functions based on a density of the bit array, where the density is determined based on a ratio of a target number to a size of the bit array, the target number is a number of elements in the bit array whose values are a first value, and the first value is used to represent that a result of a task corresponding to the element is in a cached state.

[0123] The resetting module is configured to reset the bit array according to a preset strategy, and set values of all elements in the bit array to a second value, where the second value is used to represent that a result of a task corresponding to the element is in an uncached state.

[0124] Optionally, the adjusting module is specifically configured to:

[0125] in a case where the density is greater than a first preset value, increase the number of hash functions;

[0126] in a case where the density is less than a second preset value, decrease the number of hash functions.

[0127] Optionally, the cache data query apparatus 300 further includes:

[0128] The second obtaining module is configured to obtain the result of the task to be queried in a case where the value of the target element represents that the result of the task to be queried is in an uncached state.

[0129] a storage module, configured to store the result of the to-be-queried task into the cache database;

[0130] a second adjustment module, configured to adjust the value of the target element, so that the value of the target element represents that the result of the to-be-queried task is in a cached state.

[0131] Optionally, the first acquisition module 301 is specifically configured to:

[0132] perform calculation on the to-be-queried task to obtain the result of the to-be-queried task;

[0133] or, initiate a query request to a database, and determine the result of the to-be-queried task based on a query result, the query result being a result returned by the database based on the query request.

[0134] Optionally, the cache data query apparatus 300 further includes:

[0135] a receiving module, configured to receive a task request sent by a request end, the task request carrying task information of a target task;

[0136] a splitting module, configured to split the target task into a plurality of to-be-queried tasks based on the task information.

[0137] The cache data query apparatus 300 provided by the embodiment of the application can execute the cache data query method embodiment, and has similar implementation principles and technical effects, which will not be described here again.

[0138] In the several embodiments provided in the present application, it should be understood that the disclosed method and device can be implemented in other ways. For example, the device embodiments described above are only schematic. The division of the units is only a logical function division. There can be another division manner for actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between the units can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0139] In addition, each function unit in the embodiments of the application can be integrated into a processing unit, each unit can be a separate physical entity, or two or more units can be integrated into a unit. The above integrated unit can be implemented in the form of hardware, or can be implemented in the form of hardware plus software function units.

[0140] The integrated unit in the form of the software function unit can be stored in a computer readable storage medium. The software function unit is stored in a storage medium, and includes a plurality of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute part of steps of the transceiving method according to the embodiments of the present application. The storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various storage program code storage media.

[0141] As shown in Figure 4 The embodiments of the present application also provide an electronic device 400, which comprises a processor 401 configured to read a program in a memory 402 and perform the following steps:

[0142] obtain a task identifier of a task to be queried;

[0143] calculate the task identifier by using a hash function to obtain a hash value;

[0144] find an element in a bit array based on the hash value to obtain a target element;

[0145] extract a result of the task to be queried from a cache database in a case where a value of the target element represents that the result of the task to be queried is in a cached state.

[0146] Optionally, a number of the hash functions is a plurality, and different hash functions are used to determine different target elements.

[0147] The processor 401 is further configured to read the program in the memory 402 and perform the following steps:

[0148] extract the result of the task to be queried from the cache database in a case where values of all the target elements represent that the result of the task to be queried is in the cached state.

[0149] Optionally, the processor 401 is further configured to read the program in the memory 402 and perform the following steps:

[0150] adjust a number of the hash functions based on a density of the bit array, the density being determined based on a ratio of a target number to a size of the bit array, the target number being a number of elements in the bit array with a first value, and the first value being used to represent that a result of a task corresponding to the element is in a cached state.

[0151] According to a preset strategy, the bit array is reset, and values of all elements in the bit array are set to a second value, the second value being used to represent that a result of a task corresponding to the element is in an uncached state.

[0152] Optionally, the processor 401 is further configured to read a program in the memory 402 and perform the following steps.

[0153] In a case where the density is greater than a first preset value, the number of the hash functions is increased.

[0154] In a case where the density is less than a second preset value, the number of the hash functions is decreased.

[0155] Optionally, the processor 401 is further configured to read a program in the memory 402 and perform the following steps.

[0156] In a case where the value of the target element represents that the result of the to-be-queried task is in an uncached state, the result of the to-be-queried task is obtained.

[0157] The result of the to-be-queried task is stored in the cache database.

[0158] The value of the target element is adjusted, so that the value of the target element represents that the result of the to-be-queried task is in a cached state.

[0159] Optionally, the processor 401 is further configured to read a program in the memory 402 and perform the following steps.

[0160] The to-be-queried task is calculated to obtain the result of the to-be-queried task.

[0161] Or, a query request is initiated to a database, and the result of the to-be-queried task is determined based on a query result, the query result being a result returned by the database based on the query request.

[0162] Optionally, the processor 401 is further configured to read a program in the memory 402 and perform the following steps.

[0163] A task request sent by a request end is received, the task request carrying task information of a target task.

[0164] Based on the task information, the target task is split into a plurality of to-be-queried tasks.

[0165] The electronic device 400 provided in the embodiment of the application can execute the cache data query method provided in the above embodiment, and has similar implementation principles and technical effects, which will not be described herein again.

[0166] The embodiment of the present application further provides a readable storage medium, and the readable storage medium stores a program. The program is executed by a processor to implement each process of the cache data query method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein.

[0167] The readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to a magnetic storage (for example, a floppy disk, a hard disk, a magnetic tape, a magneto-optical disk (MO), etc.), an optical storage (for example, a compact disk (CD), a digital versatile disk (DVD), a Blu-ray disk (BD), a high-definition versatile disk (HVD), etc.), and a semiconductor storage (for example, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a non-volatile memory (NAND FLASH), a solid state disk (SSD), etc.).

[0168] It should be noted that, in this document, the terms "comprising", "including", or any other variant thereof are intended to cover non-exclusive inclusions, so that a process, method, article, or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such a process, method, article, or device. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of other identical elements in the process, method, article, or device including the element.

[0169] Those skilled in the art can clearly understand the above-mentioned embodiment method can be realized by means of software and necessary general hardware platform, of course, also can be realized by hardware, but in many cases, the former is a better embodiment. According to such understanding, the technical scheme of the present application can be embodied in the form of software product, and the computer software product is stored in a storage medium (such as ROM / RAM, disk, optical disk), including a plurality of instructions to make a terminal (which can be a mobile phone, computer, server, air conditioner, or network equipment, etc.) execute the method described in various embodiments of the present application.

[0170] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above-mentioned specific embodiments, and the above-mentioned specific embodiments are only illustrative, not limiting, and those skilled in the art can make many forms without departing from the purpose of the present application and the scope protected by the claims under the inspiration of the present application, which all belong to the protection of the present application.

Claims

1. A cache data query method, characterized in that: include: Get the task ID of the task to be queried; Calculate the task identifier using a hash function to obtain a hash value; Searching for an element in the bit array based on the hash value to obtain a target element; When the value of the target element indicates that the result of the task to be queried is in a cached state, the result of the task to be queried is extracted from a cache database.

2. The method according to claim 1, characterized in that There are multiple hash functions, and different hash functions are used to determine different target elements; When the value of the target element indicates that the result of the task to be queried is in a cached state, extracting the result of the task to be queried from the cache database includes: When the values ​​of all the target elements indicate that the result of the task to be queried is in a cached state, the result of the task to be queried is extracted from the cache database.

3. The method according to claim 1, characterized in that Before calculating the task identifier using a hash function to obtain a hash value, the method further includes: adjusting the number of hash functions based on a density of the bit array, the density being determined based on a ratio of a target number to a size of the bit array, the target number being the number of elements in the bit array having a first value, the first value being used to indicate that a result of a task corresponding to the element is in a cached state; The bit array is reset according to a preset strategy, and the values ​​of all elements in the bit array are set to a second value, where the second value is used to indicate that the result of the task corresponding to the element is in an uncached state.

4. The method according to claim 3, characterized in that The adjusting the number of the hash functions based on the density of the bit group includes: When the density is greater than a first preset value, increasing the number of the hash functions; When the density is less than a second preset value, the number of the hash functions is reduced.

5. The method according to claim 1, wherein After searching the elements of the bit array based on the hash value to obtain the target element, the method further includes: When the value of the target element indicates that the result of the task to be queried is in an uncached state, obtaining the result of the task to be queried; Storing the result of the task to be queried in the cache database; The value of the target element is adjusted so that the value of the target element indicates that the result of the task to be queried is in a cached state.

6. The method according to claim 5, characterized in that The obtaining of the result of the task to be queried includes: Calculating the task to be queried to obtain a result of the task to be queried; Alternatively, a query request is initiated to a database, and a result of the task to be queried is determined based on a query result, where the query result is a result returned by the database based on the query request.

7. The method according to claim 1, characterized in that Before obtaining the task identifier of the task to be queried, the method further includes: Receive a task request sent by a requesting end, wherein the task request carries task information of a target task; Based on the task information, the target task is split into a plurality of tasks to be queried.

8. A cache data query device, characterized in that: include: The first acquisition module is used to obtain the task identifier of the task to be queried; A calculation module, configured to calculate the task identifier using a hash function to obtain a hash value; A search module, configured to search for an element in the bit array based on the hash value to obtain a target element; The extraction module is configured to extract the result of the task to be queried from the cache database when the value of the target element indicates that the result of the task to be queried is in a cached state.

9. An electronic device comprising: A memory, a processor, and a program stored in the memory and executable on the processor; characterized in that: The processor is configured to read a program in a memory to implement the steps of the cache data query method according to any one of claims 1 to 7.

10. A readable storage medium for storing a program, characterized in that: When the program is executed by a processor, the steps of the cache data query method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Data storage method and device and storage medium

    CN108874803A

  • Data acquisition method, device and equipment and computer readable storage medium

    CN118132554A

  • Data acquisition method and device, computing equipment, medium and computer program product

    CN118193597A