CN120804160A - Cache data query method and device, electronic equipment and readable storage medium - Google Patents

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

Info

Publication number
CN120804160A
CN120804160A CN202510932627.9A CN202510932627A CN120804160A CN 120804160 A CN120804160 A CN 120804160A CN 202510932627 A CN202510932627 A CN 202510932627A CN 120804160 A CN120804160 A CN 120804160A
Authority
CN
China
Prior art keywords
task
queried
result
value
hash
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202510932627.9A
Other languages
Chinese (zh)
Inventor
马拂晓
陈国�
张春
王晓苏
陈海龙
李超
吴荣兵
李广辉
张瑾
李天波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Information Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile Information Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202510932627.9A priority Critical patent/CN120804160A/en
Publication of CN120804160A publication Critical patent/CN120804160A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a cache data query method, a device, electronic equipment and a readable storage medium, which relate to the technical field of information technology and are used for solving the problem of low cache data query efficiency. The method comprises the steps of obtaining a task identifier of a task to be queried, 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 extracting the result of the task to be queried from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state. The embodiment of the invention can improve the query efficiency of the cache data.

Description

Cache data query method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of information technology (Information Technology, IT) technologies, and in particular, to a method, an apparatus, an electronic device, and a readable storage medium for querying cache data.
Background
In the prior art, a cache Key (Key) is generally constructed according to service parameters, and a cache database is queried based on the cache Key. The intelligent center platform is a center platform integrating data capacity, artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) algorithm capacity and business service capacity and is used for supporting the rapid development and operation of various intelligent businesses of enterprises.
Because of the huge number of tasks processed by the intelligent middle station, the conventional cache data query method in the prior art can obviously reduce the query efficiency when processing large-scale tasks.
Disclosure of Invention
The embodiment of the invention provides a cache data query method, a device, electronic equipment and a readable storage medium, which are used for solving the problem of low cache data query efficiency.
In a first aspect, an embodiment of the present invention provides a method for querying cached data, including:
Acquiring a task identifier of a task to be queried;
Calculating the task identifier by using a hash function to obtain a hash value;
searching elements in the 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 task to be queried is in a cached state, extracting the result of the task to be queried from a cache database.
Optionally, the number of the hash functions is a plurality, and different hash functions are used for determining different target elements;
And extracting the result of the task to be queried from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state, wherein the method comprises the following steps:
And under the condition that the values of all the target elements represent that the results of the task to be queried are in a cached state, extracting the results of the task to be queried from a cache database.
Optionally, before the task identifier is calculated by using a hash function to obtain a hash value, the method further includes:
The method comprises the steps of adjusting the number of hash functions based on the density of a bit array, wherein the density is determined based on the ratio of the target number to the size of the bit array, the target number is the number of elements with first values in the bit array, and the first values are used for representing that the results of tasks corresponding to the elements are cached;
Resetting the bit array according to a preset strategy, and setting the values of all elements in the bit array to be second values, wherein the second values are used for representing that the results of the tasks corresponding to the elements are in an uncached state.
Optionally, the adjusting the number of hash functions based on the density of the bit array includes:
Increasing the number of hash functions if the density is greater than a first preset value;
And reducing the number of the hash functions under the condition that the density is smaller than a second preset value.
Optionally, after the target element is obtained by searching in the elements of the bit array based on the hash value, the method further includes:
acquiring the result of the task to be queried under the condition that the value of the target element represents that the result of the task to be queried is in an uncached state;
Storing the result of the task to be queried into the cache database;
And adjusting the value of the target element so that the value of the target element characterizes the result of the task to be queried as a cached state.
Optionally, the obtaining 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;
or, initiating a query request to a database, and determining the result of the task to be queried based on the query result, wherein the query result is the result returned by the database based on the query request.
Optionally, before the task identifier of the task to be queried is obtained, the method further includes:
receiving a task request sent by a request end, wherein the task request carries task information of a target task;
and splitting the target task into a plurality of tasks to be queried based on the task information.
In a second aspect, an embodiment of the present invention further provides a cached data query device, including:
The first acquisition module is used for acquiring a task identifier of a task to be queried;
the calculation module is used for calculating the task identifier by using a hash function to obtain a hash value;
the searching module is used for searching elements in the bit array based on the hash value to obtain target elements;
and the extraction module is used for extracting the result of the task to be queried from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state.
In a third aspect, an embodiment of the present invention further provides an electronic device, including a memory, a processor, and a program stored on the memory and executable on the processor;
The processor is configured to read a program in a memory to implement the steps in the cache data query method according to the first aspect.
In a fourth aspect, embodiments of the present invention further provide a readable storage medium storing a program, where the program when executed by a processor implements the steps of the cache data querying method according to the first aspect.
In the embodiment of the invention, a task identifier of a task to be queried is firstly obtained, then a hash function is used for calculating the task identifier to obtain a hash value, elements in a bit array are searched based on the hash value to obtain a target element, and finally the result of the task to be queried is extracted from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state. The embodiment provides an efficient cache query mechanism, and can realize the rapid positioning of massive task results through the combination of the bit array and the hash function, thereby improving the cache query efficiency.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the description of the embodiments of the present invention will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort to a person of ordinary skill in the art.
FIG. 1 is a flowchart of a method for querying cache data according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a cache data query system according to an embodiment of the present invention;
FIG. 3 is a block diagram of a cache data query device according to an embodiment of the present invention;
Fig. 4 is a block diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the embodiment of the application, the term "and/or" describes the association relation of the association objects, which means that three relations can exist, for example, A and/or B, and can mean that A exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship. The term "plurality" in embodiments of the present application means two or more, and other adjectives are similar. The terms first, second and the like in the description and in the claims, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments of the application are capable of operation in sequences other than those illustrated or otherwise described herein, and that the "first" and "second" distinguishing between objects generally are not limited in number to the extent that the first object may, for example, be one or more.
First, several terms involved in the present application will be described:
Bit Array (Bit Array) a data structure for saving space and efficiently representing boolean values (0/1) for efficiently storing and manipulating Bit-level data. As a specific bit array, the bit array is a one-dimensional array composed of binary bits (bits), and each element can be only 0 or 1.
Hash Function (Hash Function), a Function that converts an input of arbitrary length (such as a string, a file, a number, etc.) into an output value of fixed length (called a Hash value or Hash value), a process also called Hashing.
Based on the above, the embodiment of the application provides a cache data query method, a device, an electronic device and a readable storage medium, aiming at improving the query efficiency of cache data. As shown in fig. 1, the method for querying the cached data specifically includes the following steps:
Step 101, acquiring a task identifier of a task to be queried.
It should be appreciated that the task identity is unique and is capable of uniquely determining the task to be queried and its results. In particular, the specific format of the task identifier is not limited herein. As an alternative embodiment, the task identification is determined based on at least one of the name of the task to be queried, the number of the task to be queried, and a combination of parameters of the task to be queried.
In some embodiments, after extracting the task identifier from the task to be queried, the task identifier needs to be preprocessed so that the task identifier meets the input requirement of the hash function. Specifically, preprocessing the task identifier includes format conversion, deduplication, and the like.
Optionally, in some embodiments, before the step 101, the method further includes:
receiving a task request sent by a request end, wherein the task request carries task information of a target task;
and splitting the target task into a plurality of tasks to be queried based on the task information.
The method provided by the embodiment of the application can be executed by the server. As a specific embodiment, the server side includes a task control module, where the task control module is configured to receive a task request sent by the request side.
In a specific implementation, a user sends a task request through a request end. Specifically, the user may choose to initiate the task request via a client (e.g., an Application (APP) or web platform). For scenarios that require integration into third party systems or automation flows, the user may also initiate a task request through an application programming interface (Application Programming Interface, API) interface.
It should be appreciated that the task information includes task types and/or task parameters. After receiving the task request, the server verifies the task information, specifically, verifies the task parameters to ensure that the parameters are complete, legal and in accordance with the business rules.
As an alternative embodiment, the task request also carries authentication information. In this embodiment, before verifying the task information, the server first verifies the authentication information to ensure that the task request is from a legitimate user or an authorized system. Specifically, the specific manner of verifying the authentication information is not limited herein. For example, the authentication method may be a user name password authentication method, an oauth2.0 authorization method, or an API key authentication method.
In some embodiments, the server parses the task request, extracts key information and requirements based on task information, determines complexity of a target task and a data type to be processed according to a task type, splits the target task into a plurality of subtasks based on the complexity of the target task and the data type, each subtask includes a data segment and a logic processing unit required for execution, and each subtask serves as a task to be queried.
Specifically, the server evaluates whether the target task can be decomposed into a plurality of subtasks according to the complexity of the target task and the data volume to be processed, and considers the logic structure, the data dependency relationship and the possibility of parallel processing of the target task. Under the condition that the target task can be split, a task splitting strategy is formulated, the sub-tasks after splitting can be confirmed to be independently executed, and the execution results can be combined to obtain a final task result. Specifically, the task decomposition policy includes granularity of decomposition, division manner of subtasks, dependency relationship among subtasks, and the like.
In some embodiments, when splitting a target task into a plurality of tasks to be queried based on task information, a task identification for each task to be queried may be generated based on task decomposition-related logic processing.
In contrast to the situation that the related data of the task and the service are cached based on the whole task, in this embodiment, a task is split into a plurality of subtasks, and each subtask is used as a task to be queried to query. By the method, the granularity of the cache is reduced, and the method can be better suitable for business environments with high complexity and large difference, such as intelligent center desks.
And 102, calculating the task identifier by using a hash function to obtain a hash value.
In this embodiment, the hash function is used to calculate the task identifier, so as to obtain a hash value, where the hash value is a numerical value or a binary string, and is used to locate the cache location in the bit array of the result of the task to be queried. Specifically, the number of hash functions is not limited herein, and each hash function may calculate a hash value.
Optionally, in some embodiments, the number of hash functions is a plurality, 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.
In this embodiment, the number of hash functions is plural, and by using a plurality of different hash functions, a plurality of different hash values can be calculated. Wherein the number of hash functions is determined based on the size of the bit array, typically the number of hash functions is positively correlated with the size of the bit array.
It should be appreciated that the size of the array of bits is predetermined based on the traffic requirements and the size of the cache data, and that the size of the array of bits should be large enough to accommodate all possible cache entry identifications while also taking into account the efficiency of memory usage. In particular implementations, the server or cache system needs to allocate sufficient memory space for the bit number allocation to ensure that the allocated memory space is contiguous to improve access efficiency.
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, coefficients and the like, are set for each hash function to ensure the diversity and independence of the hash functions. The hash function should have good distribution and collision resistance to ensure that the task identity can be mapped uniformly into the bit array.
In this embodiment, on one hand, by using multiple hash functions, the probability that multiple task identifiers are calculated to obtain the same hash value may be reduced, so that hash collision (hash) is reduced, which improves the efficiency of searching and inserting the data structure. On the other hand, the plurality of hash functions can effectively disperse data, map a task identifier to a plurality of hash values, and greatly reduce the misjudgment rate (False Positive Rate).
And step 103, searching elements in the bit array based on the hash value to obtain a target element.
In this embodiment, the bit array is checked based on the hash value, and a corresponding element of the hash value in the bit array is obtained, where the element is a target element, and is used to record whether the result of the task to be queried is cached. As a specific embodiment, the target element has a value including two cases, the first case where the target element has a first value (e.g., 1) that is used to represent the cached state of the task represented by the element, and the second case where the target element has a second value (e.g., 0) that is used to represent the uncached state of the task represented by the element.
It should be understood that in the embodiment where the number of hash functions is plural, the number of hash values calculated is also plural, and a target element may be found based on each hash value. In this embodiment, the number of target elements is plural.
Step 104, extracting the result of the task to be queried from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state.
It should be understood that the cache database is used for temporarily storing the execution results of the subtasks, so as to facilitate efficient execution of the subsequent tasks. Under the condition that the value of the target element represents that the result of the task to be queried is in a cached state, the result of the task to be queried can be directly extracted from the cache database without repeatedly executing the task to be queried, thereby realizing the rapid multiplexing of the task and improving the processing efficiency of the task.
Optionally, in the case that the number of hash functions is plural, the step 104 includes:
And under the condition that the values of all the target elements represent that the results of the task to be queried are in a cached state, extracting the results of the task to be queried from a cache database.
In embodiments where the number of hash functions is multiple, multiple target elements may be queried. In this embodiment, when the values of all the target elements obtained by querying represent that the result of the task to be queried is in a cached state, the result of the task to be queried is considered to be cached, the result of the task to be queried is extracted from the cache database, otherwise, the result of the task to be queried is considered to be not cached. By the method, the accuracy of the query result can be improved, and misexistence and misjudgment are avoided.
Optionally, in some embodiments, after the step 103, the method further includes:
acquiring the result of the task to be queried under the condition that the value of the target element represents that the result of the task to be queried is in an uncached state;
Storing the result of the task to be queried into the cache database;
And adjusting the value of the target element so that the value of the target element characterizes the result of the task to be queried as a cached state.
It should be understood that, in the case where the result of the task to be queried is not cached, the result of the task to be queried cannot be obtained from the cache database. At this time, according to the requirement of the task to be queried, whether the result of the task to be queried is obtained directly through calculation or the result of the task to be queried is obtained by querying a database is judged.
Optionally, in some embodiments, the obtaining the result of the task to be queried includes:
and calculating the task to be queried to obtain a result of the task to be queried.
Under the condition that the task to be queried involves complex data processing or algorithm calculation, the calculation is directly carried out on the server side, and the result of the task to be queried is obtained. Specifically, for the task needing to be calculated, a corresponding algorithm or logic processing unit is called for calculation. In specific implementation, whether to directly calculate at the server side can be judged based on the data amount to be processed and a calculation algorithm to be adopted.
Optionally, in some embodiments, the obtaining the result of the task to be queried includes:
after the result of the task to be queried is obtained through calculation or query, a query request is initiated to a database, the result of the task to be queried is determined based on the query result, and the query result is returned by the database based on the query request. The database is used for storing the subtask calculation result in a lasting mode.
In a specific implementation, the required data is not queried in the cache database, and whether a query request needs to be initiated to the database can be judged according to the data source of the data required by the definition task and the data dependency relationship identified when the subtasks are divided.
Under the condition that the task to be queried depends on data stored in a database, a query request is initiated to the database, after a query result is obtained, the result of the task to be queried is determined based on the query result, wherein whether the query result is further processed to obtain the result of the task to be queried is mainly determined by service logic of the task to be queried. Specifically, for tasks requiring querying the database, a structured query statement (Structured Query Language, SQL) or other query command is constructed, a request is initiated to the database, and the query result is obtained.
It should be understood that after obtaining the query result or the result of the task to be queried, the query result or the result of the task to be queried may be verified, and the correctness and the integrity of the result may be determined. In some embodiments, the result is a string of data, the integrity of which and consistency with the original data is ensured by computing the MD5 check value of the data.
It should be understood that the results of the task to be queried may be stored in a cache database according to a preset cache policy. Illustratively, an appropriate caching policy is selected based on traffic requirements and data characteristics, such as least recently Used (LEAST RECENTLY Used, LRU) or least frequently Used (Least Frequently Used, LFU).
Specifically, the storage location and format of the cache may be a hash table, a dis cache, etc. in the memory. Specifically, if the hash table in the memory is used, the hash value of the result is calculated according to the hash function, the result is stored in the corresponding hash bucket, and if an external cache system such as Redis is used, the result is written into the cache through the corresponding client library.
After the storage is completed, the value of the corresponding target element is adjusted so that the value of the target element represents that the result of the task to be queried is in a cached state. Illustratively, modifying the value of the target element from 0 to 1 characterizes the cached results for the task to be queried. In the case that the number of hash functions is plural, a plurality of corresponding target elements may be obtained, and in this embodiment, the values of all the target elements need to be adjusted.
In this embodiment, the task to be queried is a subtask obtained by splitting from the target task, and the subtask is convenient to multiplex by storing the results of the task to be queried, so that the data processing efficiency can be effectively improved, the cache space utilization rate can be optimized, the resource consumption of the application service can be further reduced, and the operation cost of the system can be controlled.
Optionally, in some embodiments, before the calculating the task identifier using a hash function to obtain a hash value, the method further includes:
The method comprises the steps of adjusting the number of hash functions based on the density of a bit array, wherein the density is determined based on the ratio of the target number to the size of the bit array, the target number is the number of elements with first values in the bit array, and the first values are used for representing that the results of tasks corresponding to the elements are cached;
Resetting the bit array according to a preset strategy, and setting the values of all elements in the bit array to be second values, wherein the second values are used for representing that the results of the tasks corresponding to the elements are in an uncached state.
It should be understood that, the time for resetting the bit array according to the preset policy may be adjusted and set according to the actual situation, but in order to make the hash value obtained by calculating the task identifier using the hash function accurate, the operation of resetting the bit array needs to be completed before the hash value calculation is performed.
As an optional implementation manner, resetting the bit number set according to a preset policy includes:
When the server is updated or restarted, the bit array is reset, and the emptying operation of the bit array is synchronized with the updating time of the server through the setting, so that the consistency of the cached data can be ensured.
As another alternative embodiment, resetting the bit number set according to a preset policy includes:
And resetting the bit number group according to a preset period. The preset period may be daily, weekly, monthly, etc. The timeliness of the cached data can be ensured by regularly clearing the expired or invalid cache item identifiers in the bit array according to a preset period through a timing task or a trigger.
As another alternative embodiment, resetting the bit number set according to a preset policy includes:
And resetting the bit number set when the load of the server is lower than a preset value. In this embodiment, the load condition of the server is detected, and when the load of the server is lower than the preset value, the bit array is cleared, so that the influence of executing the clearing operation on the performance of the server in the high load can be avoided.
It should be appreciated that the hash function may be reset each time the bit array is cleared, so that the number of hash functions is more reasonable. Optionally, in some embodiments, the adjusting the number of hash functions based on the density of the bit array includes:
Increasing the number of hash functions if the density is greater than a first preset value;
And reducing the number of the hash functions under the condition that the density is smaller than a second preset value.
Specifically, assuming that the size of the bit array is m and the number of elements (i.e., set bits) having the first value is n, the density ρ=n/m of the bit array. The number k of hash functions can be dynamically adjusted according to the density ρ and a preset false positive rate threshold e. As a specific embodiment, the value of k is increased when ρ is greater than the first preset value ρ_max, and the value of k is decreased when ρ is less than the second preset value ρ_min.
In this embodiment, the number of hash functions is dynamically adjusted according to the current density of the bit array (i.e. the proportion of the set bits), and increasing the number of hash functions when the density is too high can reduce the false positive rate, and reducing the number of hash functions when the density is too low can save space. By the method, the cache system can be more flexibly adapted to different application scenes and data characteristics, and the cache efficiency and the space utilization rate are further improved. By the method, the cache system can better process the time-efficiency data, and the proportion of fresh data in the cache is improved.
In the embodiment of the application, a task identifier of a task to be queried is acquired, a hash function is used for calculating the task identifier to obtain a hash value, elements in a bit array are searched based on the hash value to obtain a target element, and the result of the task to be queried is extracted from a cache database under the condition that the value of the target element represents that the result of the task to be queried is in a cached state. The embodiment provides an efficient cache query mechanism, and can realize the rapid positioning of massive subtask results through the combination of the bit array and the hash function, thereby improving the cache query efficiency.
Referring to fig. 2, the embodiment of the invention also provides a cache query system, which comprises a client and a server, wherein the server comprises a task control module, a bit array, a hash function module and a cache database. The request end is used for sending a task request to the service end, and the request end is a middle-platform task or service calling and initiating party when the task is concretely implemented. And the task control module is used for identifying and disassembling the target task according to the type of the task after receiving the request, obtaining the task to be queried, and completing corresponding logic execution according to the task to be queried, the call bit array and the hash function module. And in the task execution process, the cache database is required to be read and written according to the data interaction result. The bit array is used for recording and controlling the mapping relation between tasks and the cache. The hash function module is used for calling a hash function, calculating a hash value and controlling the mapping relation calculation process of the bit array and the task.
Referring to fig. 3, an embodiment of the present invention further provides a cache data query apparatus 300. Fig. 3 is a block diagram of a cache data query device 300 according to an embodiment of the present invention. Since the principle of the cache data query device 300 for solving the problem is similar to that of the cache data query method shown in fig. 1 in the embodiment of the present invention, the implementation of the cache data query device 300 can refer to the implementation of the method, and the repetition is omitted.
As shown in fig. 3, the cache data query device 300 includes:
The first obtaining module 301 is configured to obtain a task identifier of a task to be queried;
the calculating module 302 is configured to calculate the task identifier by using a hash function to obtain a hash value;
a searching module 303, configured to search elements in the bit array based on the hash value to obtain a target element;
And the extracting module 304 is configured to extract the result of the task to be queried from the cache database when the value of the target element characterizes the result of the task to be queried is in a cached state.
Optionally, the number of the hash functions is a plurality, and different hash functions are used for determining different target elements;
The extracting module 304 is specifically configured to:
And under the condition that the values of all the target elements represent that the results of the task to be queried are in a cached state, extracting the results of the task to be queried from a cache database.
Optionally, the cache data query device 300 further includes:
the first adjusting module is used for adjusting the number of the hash functions based on the density of the bit array, wherein the density is determined based on the ratio of the target number to the size of the bit array, the target number is the number of elements with first values in the bit array, and the first values are used for representing that the results of tasks corresponding to the elements are cached states;
And the resetting module is used for resetting the bit array according to a preset strategy, setting the values of all the elements in the bit array to be second values, wherein the second values are used for representing that the results of the tasks corresponding to the elements are in an uncached state.
Optionally, the adjusting module is specifically configured to:
Increasing the number of hash functions if the density is greater than a first preset value;
And reducing the number of the hash functions under the condition that the density is smaller than a second preset value.
Optionally, the method of the cache data query device 300 further includes:
The second acquisition module is used for acquiring the result of the task to be queried under the condition that the value of the target element represents that the result of the task to be queried is in an uncached state;
The storage module is used for storing the result of the task to be queried into the cache database;
and the second adjusting module is used for 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 a cached state.
Optionally, the first obtaining module 301 is specifically configured to:
calculating the task to be queried to obtain a result of the task to be queried;
or, initiating a query request to a database, and determining the result of the task to be queried based on the query result, wherein the query result is the result returned by the database based on the query request.
Optionally, the cache data query device 300 further includes:
The receiving module is used for receiving a task request sent by a request end, wherein the task request carries task information of a target task;
and the splitting module is used for splitting the target task into a plurality of tasks to be queried based on the task information.
The cache data query device 300 provided in the embodiment of the present invention may execute the above embodiment of the cache data query method, and its implementation principle and technical effects are similar, and this embodiment will not be repeated here.
In the several embodiments provided in the present application, it should be understood that the disclosed methods and apparatus may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may be physically included separately, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in hardware plus software functional units.
The integrated units implemented in the form of software functional units described above may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium, and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform part of the steps of the transceiving method according to the embodiments of the present invention. The storage medium includes a U disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, an optical disk, or other various media capable of storing program codes.
As shown in fig. 4, the embodiment of the present invention further provides an electronic device 400, where the electronic device 400 includes a processor 401 for reading a program in a memory 402, and performing the following steps:
Acquiring a task identifier of a task to be queried;
Calculating the task identifier by using a hash function to obtain a hash value;
searching elements in the 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 task to be queried is in a cached state, extracting the result of the task to be queried from a cache database.
Optionally, the number of the hash functions is a plurality, and different hash functions are used for determining different target elements;
the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
And under the condition that the values of all the target elements represent that the results of the task to be queried are in a cached state, extracting the results of the task to be queried from a cache database.
Optionally, the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
The method comprises the steps of adjusting the number of hash functions based on the density of a bit array, wherein the density is determined based on the ratio of the target number to the size of the bit array, the target number is the number of elements with first values in the bit array, and the first values are used for representing that the results of tasks corresponding to the elements are cached;
Resetting the bit array according to a preset strategy, and setting the values of all elements in the bit array to be second values, wherein the second values are used for representing that the results of the tasks corresponding to the elements are in an uncached state.
Optionally, the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
Increasing the number of hash functions if the density is greater than a first preset value;
And reducing the number of the hash functions under the condition that the density is smaller than a second preset value.
Optionally, the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
acquiring the result of the task to be queried under the condition that the value of the target element represents that the result of the task to be queried is in an uncached state;
Storing the result of the task to be queried into the cache database;
And adjusting the value of the target element so that the value of the target element characterizes the result of the task to be queried as a cached state.
Optionally, the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
calculating the task to be queried to obtain a result of the task to be queried;
or, initiating a query request to a database, and determining the result of the task to be queried based on the query result, wherein the query result is the result returned by the database based on the query request.
Optionally, the processor 401 is further configured to read a program in the memory 402, and perform the following steps:
receiving a task request sent by a request end, wherein the task request carries task information of a target task;
and splitting the target task into a plurality of tasks to be queried based on the task information.
The electronic device 400 provided in the embodiment of the present invention may execute the above embodiment of the cache data query method, and its implementation principle and technical effects are similar, and this embodiment will not be described herein again.
The embodiment of the application also provides a readable storage medium, and the readable storage medium stores a program, which when executed by a processor, realizes the processes of the above embodiment of the cache data query method, and can achieve the same technical effects, so that repetition is avoided, and no further description is provided here.
The readable storage medium may be any available medium or data storage device that can be accessed by a processor, including, but not limited to, magnetic memories (e.g., floppy disks, hard disks, magnetic tapes, magneto-Optical disks (MO), etc.), optical memories (e.g., compact Disks (CD), digital video discs (DIGITAL VERSATILE DISC, DVD), blu-ray discs (BD), high-Definition VERSATILE DISC, HVD, etc.), and semiconductor memories (e.g., read-Only Memory (ROM), erasable programmable Read-Only Memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable programmable Read-Only Memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ ONLY MEMORY, EEPROM), nonvolatile Memory (NAND FLASH), solid state Disk (Solid STATE DISK or Solid STATE DRIVE, SSD)), etc.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. In light of such understanding, the technical solutions of the present application may be embodied essentially or in part in the form of a software product stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal (which may be a cell phone, computer, server, air conditioner, or network device, etc.) to perform the methods described in the various embodiments of the present application.
The embodiments of the present application have been described above with reference to the accompanying drawings, but the present application is not limited to the above-described embodiments, which are merely illustrative and not restrictive, and many forms may be made by those having ordinary skill in the art without departing from the spirit of the present application and the scope of the claims, which are to be protected by the present application.

Claims (10)

1.一种缓存数据查询方法,其特征在于,包括:1. A cache data query method, comprising: 获取待查询任务的任务标识;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.根据权利要求1所述的方法,其特征在于,所述哈希函数的数量为多个,不同的所述哈希函数用于确定不同的所述目标元素;2. The method according to claim 1, wherein 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.根据权利要求1所述的方法,其特征在于,所述使用哈希函数对所述任务标识进行计算,得到哈希值之前,所述方法还包括:3. The method according to claim 1, wherein before calculating the task identifier using a hash function to obtain a hash value, the method further comprises: 基于所述位数组的密度调整所述哈希函数的数量,所述密度基于目标数量与所述位数组的大小的比值确定,所述目标数量为所述位数组中取值为第一取值的元素的数量,所述第一取值用于表征所述元素对应的任务的结果为已缓存状态;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.根据权利要求3所述的方法,其特征在于,所述基于所述位数组的密度调整所述哈希函数的数量,包括:4. The method according to claim 3, wherein adjusting the number of hash functions based on the density of the bit group comprises: 在所述密度大于第一预设值的情况下,增加所述哈希函数的数量;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.根据权利要求1所述的方法,其特征在于,所述基于所述哈希值在位数组的元素中查找,得到目标元素之后,所述方法还包括: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 comprises: 在所述目标元素的取值表征所述待查询任务的结果为未缓存状态的情况下,获取所述待查询任务的结果;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.根据权利要求5所述的方法,其特征在于,所述获取所述待查询任务的结果,包括:6. The method according to claim 5, wherein obtaining the result of the task to be queried comprises: 对所述待查询任务进行计算,得到所述待查询任务的结果;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.根据权利要求1所述的方法,其特征在于,所述获取待查询任务的任务标识之前,所述方法还包括:7. The method according to claim 1, characterized in that before obtaining the task identifier of the task to be queried, the method further comprises: 接收请求端发送的任务请求,所述任务请求携带目标任务的任务信息;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.一种缓存数据查询装置,其特征在于,包括:8. A cache data query device, comprising: 第一获取模块,用于获取待查询任务的任务标识;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.一种电子设备,包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的程序;其特征在于,9. An electronic device comprising: a memory, a processor, and a program stored in the memory and executable on the processor; characterized in that: 所述处理器,用于读取存储器中的程序实现如权利要求1至7中任一项所述的缓存数据查询方法中的步骤。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.一种可读存储介质,用于存储程序,其特征在于,所述程序被处理器执行时实现如权利要求1至7中任一项所述的缓存数据查询方法中的步骤。10. A readable storage medium for storing a program, wherein when the program is executed by a processor, the program implements the steps of the cache data query method according to any one of claims 1 to 7.
CN202510932627.9A 2025-07-07 2025-07-07 Cache data query method and device, electronic equipment and readable storage medium Pending CN120804160A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202510932627.9A CN120804160A (en) 2025-07-07 2025-07-07 Cache data query method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202510932627.9A CN120804160A (en) 2025-07-07 2025-07-07 Cache data query method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN120804160A true CN120804160A (en) 2025-10-17

Family

ID=97327545

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202510932627.9A Pending CN120804160A (en) 2025-07-07 2025-07-07 Cache data query method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN120804160A (en)

Similar Documents

Publication Publication Date Title
US11494403B2 (en) Method and apparatus for storing off-chain data
CN111880746A (en) Method and device for writing service data into block chain system
CN115039082B (en) Log writing method, device, electronic device, and storage medium
US11182378B2 (en) System and method for committing and rolling back database requests
CN119397166A (en) A data request processing method, device, equipment and storage medium
US8560572B2 (en) System for lightweight objects
US9009731B2 (en) Conversion of lightweight object to a heavyweight object
US9659041B2 (en) Model for capturing audit trail data with reduced probability of loss of critical data
CN110222046B (en) List data processing method, device, server and storage medium
CN116954680A (en) Plug-in updating method, device, equipment, medium and program product of storage system
CN114443583A (en) Method, device and equipment for arranging fragment space and storage medium
CN120804160A (en) Cache data query method and device, electronic equipment and readable storage medium
CN111930781B (en) Method and device for processing data request of cache database
CN117667305A (en) Service scene-based security policy deployment method and device and electronic equipment
CN120935167B (en) Asynchronous file generation and download implementation methods and systems
CN118132520B (en) Storage system file processing method, electronic device, storage medium and program product
KR102727220B1 (en) Multiple smart contract operation system for stable and efficient blockchain service
CN119106409B (en) Front-end dynamic data authority binding and verification method, system and readable storage medium
US20250370811A1 (en) Workload distribution based on node properties
KR102278185B1 (en) System and method for serverless service using blockchain node
CN120415802A (en) Data encryption transmission method, device and equipment
CN120215817A (en) Disk defragmentation method, device, electronic device and storage medium
CN114881606A (en) Execution method, device, equipment and storage medium of policy modification behavior
CN117217540A (en) Sample construction methods, devices, equipment, media and program products
CN116112442A (en) Request-response method, apparatus, computer device, storage medium and program product

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