Method, device, electronic device and medium for caching offline device instructions

By managing the offline device instruction cache of the IoT platform through a dual-timing queue mechanism, the problems of storage capacity and performance limitations and instruction timeliness are solved, efficient and flexible instruction processing is achieved, and resource waste and performance bottlenecks are reduced.

CN119512627BActive Publication Date: 2025-09-30E SURFING IOT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411508314.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-09-30
Estimated Expiration
2044-10-28

AI Technical Summary

Technical Problem

IoT platforms face storage capacity and performance limitations, as well as instruction timeliness issues, when processing offline device instructions. Existing technical solutions cannot efficiently manage the instruction cache of offline devices, resulting in wasted storage resources and performance bottlenecks.

Method used

A dual-timing queue mechanism is adopted, with two consecutive timing queues representing the current and next time windows respectively. Each queue contains multiple time windows, inserts instructions based on the expiration time, and performs cleaning and exchange processing when the time changes, reducing the frequency of database scanning.

Benefits of technology

It achieves efficient caching of offline device instructions, reduces memory resource consumption, improves the continuity and flexibility of instruction processing, and ensures instruction timeliness and system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512627B_ABST
    Figure CN119512627B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, electronic device and medium for caching offline device instructions. The present invention receives and stores new instructions in real time by initializing a queue and filling instructions within the current time range, quickly issues non-expired instructions when the device is online, regularly clears expired instructions, and supports instruction cancellation. Through a dynamic window switching mechanism, efficient management of instructions and rational use of resources are achieved, solving the problems of storage waste and poor performance in traditional delay queues and Redis solutions. The present invention uses a mechanism of two timing queues to only load cached instructions within two time windows, and only scans the cached instructions of the next time window when the queue is switched, which can avoid frequent database scanning when the time window scrolls. The embodiments of the present invention can effectively reduce the consumption of memory resources, efficiently realize the caching of offline device instructions, and can be widely used in the field of data processing technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, electronic device and medium for caching instructions of an offline device. Background Art

[0002] IoT platforms face two major challenges when processing commands from offline devices: storage capacity and performance limitations, and command timeliness. 1. Storage capacity and performance limitations: IoT platforms must manage numerous devices and data, resulting in limited storage resources. Excessive caching of commands consumes storage space, impacting platform performance and responsiveness. Storage resources must be properly planned to avoid overloading the system. 2. Command timeliness: Many control commands in IoT applications are time-sensitive and may become meaningless beyond a specific time window. Platforms must set a reasonable command time-to-live (TTL) to ensure that commands are processed within their validity period.

[0003] In the existing technology, the two typical solutions have their own problems:

[0004] 1. Delay queue-based solution: This solution uses message queue services (such as Kafka and Pulsar) to implement a delay queue to store unprocessed commands. The process includes creating a delay queue, enqueuing commands, processing them on the device, and clearing and marking expired commands. However, there's an issue with being unable to directly delete messages for specific devices, resulting in already issued commands still occupying storage space until the TTL expires.

[0005] 2. Redis-based device command caching solution: Design a Redis list structure to store device commands, using the device ID as the key. The process includes creating a device-level command list, caching commands, processing device online, and clearing and marking expired commands. Deleting successfully issued commands requires traversing the command list, with a time complexity of O(n). Clearing expired commands requires periodic scanning, with a time complexity of O(m) × O(n). Performance is poor when the number of devices and cached commands is large. Summary of the Invention

[0006] The present invention proposes a method, apparatus, electronic device and medium for caching offline device instructions, aiming to solve one of the technical problems in the related art to at least a certain extent. The embodiments of the present invention can efficiently implement caching of offline device instructions.

[0007] In one aspect, an embodiment of the present invention provides a method for caching instructions for an offline device, comprising:

[0008] The current time node is used as the target time node, and two consecutive time queues are initialized with the target time node as the starting point; the time queues include a first window queue and a second window queue in sequence; each time queue includes multiple time windows within a preset time range after the target time node;

[0009] Obtain the pending instructions and their expiration times of all offline devices, and insert the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with the device identification;

[0010] Obtain the operating status of the offline device and determine the offline device whose operating status is online as the online device; based on the device identification of the online device, take out the corresponding pending instruction from the timing queue and send it to the online device;

[0011] In response to the time change, the next time node of the target time node is used as the target time node, and the time window corresponding to the previous time node of the target time node is cleaned up;

[0012] Return to the step of obtaining pending instructions and their expiration times for all offline devices until all time windows in the first window queue have completed the cleanup operation;

[0013] Based on the next preset time range of the second window queue, the time node corresponding to each time window of the first window queue is reloaded, the queue pointers of the first window queue and the second window queue are exchanged, and the step of obtaining the pending instructions and their expiration times of all offline devices is returned to continue the instruction caching of offline devices.

[0014] Optionally, initializing two consecutive timed queues with the target time node as the starting point includes the following steps:

[0015] According to two consecutive preset time ranges after the target time node, a first window queue and a second window queue are created in combination with a preset basic data structure corresponding to the time window;

[0016] Among them, all time windows in each timing queue correspond to each time node within a preset time range in sequence; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.

[0017] Optionally, all time windows in each time queue sequentially correspond to each time node within a preset time range, and a list of instructions is provided in the time window; and inserting the to-be-processed instructions into the corresponding time window in the time queue based on the expiration time includes the following steps:

[0018] Determine the target time window based on the time node corresponding to the expiration time;

[0019] Insert the pending instruction into the instruction list in the target time window.

[0020] Optionally, after the steps of obtaining the pending instructions from the instruction database and taking out the corresponding pending instructions from the timing queue and sending them to the online device, the method further comprises the following steps:

[0021] The instruction state of the corresponding instruction to be processed in the instruction database is marked as the first state.

[0022] Optionally, the instruction to be processed is obtained from an instruction database; and a time window corresponding to a previous time node of the target time node is cleaned up, including the following steps:

[0023] Dequeue the pending instructions in the time window corresponding to the previous time node of the target time node.

[0024] Optionally, the method further comprises the following steps:

[0025] The instruction state of the pending instruction for executing the dequeue operation in the instruction database is marked as the second state.

[0026] Optionally, the instruction to be processed is obtained from an instruction database; the method further comprises the following steps:

[0027] In response to the target object's cancel operation on the pending instruction, the pending instruction on which the cancel operation is performed is deleted from the timing queue, and the instruction state of the pending instruction on which the cancel operation is performed is marked as a third state in the instruction database.

[0028] On the other hand, an embodiment of the present invention provides a cache device for offline device instructions, including:

[0029] The first module is configured to use the current time node as the target time node and initialize two consecutive time queues with the target time node as the starting point; the time queues sequentially include a first window queue and a second window queue; each time queue includes multiple time windows within a preset time range after the target time node;

[0030] The second module is used to obtain the pending instructions and their expiration times of all offline devices, and insert the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with the device identification;

[0031] The third module is used to obtain the operating status of the offline device and determine the offline device whose operating status is online as an online device; based on the device identification of the online device, the corresponding to-be-processed instruction is taken out from the timing queue and sent to the online device;

[0032] A fourth module is configured to, in response to a time change, set a next time node of the target time node as the target time node and perform a clearing operation on a time window corresponding to a previous time node of the target time node;

[0033] A fifth module is configured to return to executing the second module until all time windows in the first window queue are cleared.

[0034] The sixth module is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of offline devices.

[0035] Optionally, the instruction to be processed is obtained from an instruction database; the apparatus further includes:

[0036] A seventh module is configured to mark the instruction status of the corresponding instruction to be processed in the instruction database as a first status;

[0037] Among them, the seventh module is executed after the third module.

[0038] Optionally, the instruction to be processed is obtained from an instruction database; the apparatus further includes:

[0039] The eighth module is configured to mark the instruction status of the pending instruction for executing the dequeue operation in the instruction database as the second status.

[0040] Optionally, the instruction to be processed is obtained from an instruction database; the apparatus further includes:

[0041] The ninth module is configured to delete the pending instruction on which the cancellation operation is performed from the timing queue in response to the target object's cancellation operation on the pending instruction, and mark the instruction status of the pending instruction on which the cancellation operation is performed as a third status in the instruction database.

[0042] On the other hand, an embodiment of the present invention provides an electronic device, including: a processor and a memory; the memory is used to store programs; the processor executes the program to implement the above-mentioned offline device instruction caching method.

[0043] On the other hand, an embodiment of the present invention provides a computer storage medium storing a program executable by a processor. The program executable by the processor is used to implement the above-mentioned offline device instruction caching method when executed by the processor.

[0044] The embodiment of the present invention takes the current time node as the target time node and initializes two consecutive timing queues with the target time node as the starting point; the timing queues sequentially include a first window queue and a second window queue; each timing queue includes multiple time windows within a preset time range after the target time node; the pending instructions of all offline devices and their expiration times are obtained, and based on the expiration times, the pending instructions are inserted into the corresponding time windows of the timing queues; wherein the pending instructions are associated with device identifiers; the operating status of the offline devices is obtained, and the offline devices whose operating status is online are determined to be online devices; based on the device identifiers of the online devices, the corresponding pending instructions are taken out from the timing queues. Send to the online device; in response to the time change, take the next time node of the target time node as the target time node, and perform a cleanup operation on the time window corresponding to the previous time node of the target time node; return to execute the step of obtaining the pending instructions and their expiration time of all offline devices until all time windows of the first window queue have completed the cleanup operation; reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the step of obtaining the pending instructions and their expiration time of all offline devices, and continue to cache the instructions of the offline device. The present invention includes the following beneficial effects: the present invention uses the mechanism of two timing queues, only loads the cached instructions within the two time windows, and only scans the cached instructions of the next time window when the queue is switched, which can avoid frequent database scanning when the time window is scrolled. The embodiment of the present invention can effectively reduce the consumption of memory resources and efficiently implement the caching of offline device instructions. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings are used to provide a further understanding of the technical solution of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the technical solution of the present invention and do not constitute a limitation to the technical solution of the present invention.

[0046] Figure 1 A schematic diagram of an implementation environment for caching offline device instructions provided by an embodiment of the present invention;

[0047] Figure 2 A schematic flow chart of a method for caching instructions for an offline device provided in an embodiment of the present invention;

[0048] Figure 3 A schematic diagram of the expanded flow of instruction insertion provided by an embodiment of the present invention;

[0049] Figure 4 A schematic diagram of the overall flow of a method for caching offline device instructions provided by an embodiment of the present invention;

[0050] Figure 5 A schematic diagram of the data structure of a timing queue provided by an embodiment of the present invention;

[0051] Figure 6 A schematic diagram of the principle flow of a new cache instruction enqueue provided by an embodiment of the present invention;

[0052] Figure 7 A schematic diagram of the principle flow of dequeuing a cache instruction provided by an embodiment of the present invention;

[0053] Figure 8 A schematic diagram illustrating the principle of the time window switching process provided by an embodiment of the present invention;

[0054] Figure 9 A schematic structural diagram of a cache device for offline device instructions provided by an embodiment of the present invention;

[0055] Figure 10 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0057] It should be noted that although the system diagrams illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the system or the sequence in the flowcharts. The terms "first / S100" and "second / S200" in the specification, claims, and drawings are used to distinguish similar objects and are not necessarily used to describe a specific sequence or precedence.

[0058] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute a separate or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0059] To facilitate understanding of the technical solutions of the present invention, the following are first explained regarding the technical features that may appear in the embodiments of the present invention:

[0060] Command status: Command status is an important node in the process of sending commands to IoT devices, indicating the running status of a command, such as "stored", "sent", "expired", "cancelled", "sending failed", etc.

[0061] TTL (Time to Live): Indicates the maximum cache duration for commands. For offline IoT devices, the platform caches commands issued to these devices for a period of time. Commands that exceed the maximum cache duration are cleared by the platform and will no longer be issued to the device. The command status will be updated to "Expired."

[0062] Time window: The present invention uses a time window to represent a period of time, and the time window 10:00:00-10:59:59 represents the time within this period of time.

[0063] Time grid: The smallest unit of the timing queue in the present invention. One grid represents a time period of one second, and stores the instructions cached within this second.

[0064] Cached instructions within the time window: Indicates that the expiration time of the device instructions cached in the system is within the time window.

[0065] Time window sliding: If we consider time as a one-dimensional straight line, the time window continuously moves forward on the timeline, and the process of continuously reading data at new time points can be called time window sliding.

[0066] It is understandable that the caching method for offline device instructions provided in the embodiment of the present invention can be applied to any computer device with data processing and computing capabilities, and this computer device can be various terminals or servers. When the computer device in the embodiment is a server, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal is a smart phone, tablet computer, laptop computer, desktop computer, etc., but is not limited to this.

[0067] like Figure 1 FIG. 1 is a schematic diagram of an implementation environment provided by an embodiment of the present invention. Figure 1 , the implementation environment includes at least one terminal 102 and a server 101. The terminal 102 and the server 101 can be connected to the network in a wireless or wired manner to complete data transmission and exchange.

[0068] Server 101 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as big data and artificial intelligence platforms.

[0069] In addition, server 101 can also be a node server in a blockchain network. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm.

[0070] The terminal 102 may be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited thereto. The terminal 102 and the server 101 may be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment of the present invention.

[0071] Based on the example Figure 1 In the implementation environment shown, an embodiment of the present invention provides a method for caching offline device instructions. The following is an example of the offline device instruction caching method being applied in the terminal 102. It can be understood that the offline device instruction caching method can also be applied in the server 101.

[0072] Reference Figure 2 , Figure 2 This is a flowchart of a method for caching offline device instructions applied to a terminal according to an embodiment of the present invention. The execution subject of the method for caching offline device instructions can be any of the aforementioned computer devices (including servers or terminals). Figure 2 , the method comprises the following steps:

[0073] S100: Set the current time node as the target time node and initialize two consecutive timed queues with the target time node as the starting point;

[0074] The timing queue includes a first window queue and a second window queue in sequence; each timing queue includes multiple time windows within a preset time range after the target time node;

[0075] It should be noted that, in some embodiments, initializing two consecutive timed queues with the target time node as the starting point may include the following steps: creating a first window queue and a second window queue based on two consecutive preset time ranges after the target time node and combining the preset basic data structure corresponding to the time window; wherein, all time windows in each timed queue correspond sequentially to each time node within the preset time range; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.

[0076] For example, in some specific implementations, the present invention first creates a timed queue: initialize two queues, one representing the current time window and the other representing the next time window. Fill these two queues based on the current time, ensuring that each grid corresponds to an instruction within the next second. In some application scenarios, the present invention can create a timed queue as follows:

[0077] Data structure selection: Use HashMap <Long, HashSet <instruction>> As the basic data structure, the Long type represents the timestamp (accurate to the second), HashSet <instruction>Stores a list of pending instructions within the same second. Using a HashMap as the queue's underlying data structure allows for scalability, allowing for flexible adjustments to the time window size (i.e., the Map's capacity). A fixed-length array can also be used instead of a HashMap, but this requires adding records of the start timestamps of the two queues. Accessing each grid at a specific moment requires using a time offset (current time minus the queue's start time) as an array index.

[0078] Queue Initialization: When the system starts, two queues are created, one for the current time window and one for the next time window. Each queue contains a series of grids, each corresponding to a list of commands for the next second. The command data for the two time windows is loaded from the database, and the command ID is inserted into the Set of cached commands stored in the grid.

[0079] The timed queue built based on the time window can ensure that only the instruction data within the time window range is loaded, without loading all the cached instruction data.

[0080] S200: Obtain pending instructions and their expiration times from all offline devices, and insert the pending instructions into a corresponding time window in a timing queue based on the expiration time;

[0081] The pending instruction is associated with a device identifier;

[0082] It should be noted that all time windows in each timing queue correspond to each time node within a preset time range, and a command list is set in the time window; in some embodiments, such as Figure 3 As shown, based on the expiration time, inserting the pending instruction into the corresponding time window in the timing queue can include the following steps: S201, determining the target time window according to the time node corresponding to the expiration time; S202, inserting the pending instruction into the instruction list in the target time window.

[0083] For example, in some specific implementations, the present invention performs command enqueuing: when receiving a command for an offline device, the expiration time is checked to see if it falls within the time range covered by the current dual queue. If so, the command is inserted into the list at the corresponding "second" time. In some application scenarios, command enqueuing can be implemented as follows:

[0084] Timestamp Calculation: When the command service receives a command sent to an offline device, it calculates its cache expiration timestamp to determine whether it falls within the current dual queue time window. If it does, it is enqueued. Commands outside the time window are directly stored and wait for the window to roll out.

[0085] Instruction insertion: If the expiration time of the instruction is within the time window covered by the two queues, the instruction is inserted into the Set of the corresponding time grid according to the expiration timestamp.

[0086] This instruction enqueue method can ensure that newly added cache instructions can be quickly added to the corresponding time grid without the need for instruction cache expiration time sorting operations with high time complexity.

[0087] S300, obtaining the operating status of the offline device, determining the offline device whose operating status is online as the online device; based on the device identification of the online device, taking the corresponding to-be-processed instruction from the timing queue and sending it to the online device;

[0088] It should be noted that the pending instructions are obtained from the instruction database; in some optional embodiments, after the step of taking out the corresponding pending instructions from the timing queue and sending them to the online device, the method may also include the following steps: marking the instruction status of the corresponding pending instructions in the instruction database as the first status.

[0089] For example, in some specific implementations, the present invention addresses device online processing: After a device comes back online, all unexpired commands are immediately extracted from the queue and sent to the device. The command status is simultaneously updated to "issued" (a case of the first state) and removed from the queue. In some application scenarios, the present invention's device online processing can be implemented as follows:

[0090] Status Update and Record Deletion: After a device comes online, immediately retrieve all unexpired commands from the device session and send them to the device. For successfully sent commands, remove the corresponding record from the queue and update the command status in the database to "Successful" (an alternative to the first status).

[0091] S400: In response to a time change, taking the next time node of the target time node as the target time node, and performing a clearing operation on the time window corresponding to the previous time node of the target time node;

[0092] It should be noted that the pending instructions are obtained from the instruction database; in some embodiments, the cleaning operation on the time window corresponding to the previous time node of the target time node may include the following steps: dequeueing the pending instructions in the time window corresponding to the previous time node of the target time node.

[0093] In some optional embodiments, the method may further include the following step: marking the instruction status of the pending instruction that performs the dequeue operation in the instruction database as the second status.

[0094] For example, in some specific implementations, the present invention can implement expired device instruction cleanup and marking: the instructions in the current time window queue are checked every second, and for undelivered and expired instructions, their status is marked as "expired" (i.e., the second state), and the database is asynchronously updated. In some application scenarios, the present invention can implement expired device instruction cleanup and marking as follows:

[0095] Instruction dequeue: The system periodically takes out the instruction set cached in the time grid of this second from the queue every second and performs the dequeue operation.

[0096] Status update: Based on the cached expired instruction set retrieved, use an asynchronous thread to update the instruction status of the corresponding instruction in the database to "expired".

[0097] The time complexity of dequeuing expired instructions from the timed queue is O(1), which has a significant performance advantage over the above two technical solutions.

[0098] In some optional embodiments, the method may further include the following steps: in response to the target object's cancellation operation on the pending instruction, deleting the pending instruction that performs the cancellation operation from the timing queue, and marking the instruction status of the pending instruction that performs the cancellation operation in the instruction database as the third state.

[0099] For example, in some specific implementations, the present invention can also implement the processing of canceled instructions: before a command is issued to a device, it can be canceled. If the cache expiration time of the command is within the time window of two timer queues, the command can be deleted from the timer queue. In some application scenarios, the present invention can implement the following processing of canceled instructions:

[0100] Delete canceled orders from the queue: Based on the cache expiration time stored in the order data. If the order cache expiration time is within the current time window, the corresponding time grid is found based on the expiration time, and the corresponding order record in the Set is removed based on the order ID. If it is not within the time window, the order status is directly updated to "canceled" (the third state) in the database.

[0101] S500: Return to the step of obtaining pending instructions and their expiration times for all offline devices until all time windows in the first window queue have completed the cleanup operation.

[0102] S600. Reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to the step of obtaining the pending instructions and their expiration times of all offline devices, and continue to cache instructions of offline devices.

[0103] For example, in some specific implementations, the present invention can perform window switching: when the first window period ends, the current window queue is cleared, the next time window queue is upgraded to the current window, and the above process is repeated. In some application scenarios, the window switching of the present invention can be implemented as follows:

[0104] Window switching: When the first time window ends, the pointers to the two queues are swapped. The next time window queue is upgraded to the current window. At the same time, the next time window is pointed to the completed "current window queue". All data in the queue is cleared, and the instruction data within the next time window range is loaded from the database. The above process is repeated.

[0105] Loop processing: The system continuously monitors the device status and instruction status, and cyclically executes operations such as instruction queuing, device online processing, and expired instruction cleaning and marking to ensure the continuity and efficiency of instruction processing.

[0106] In order to explain the principle of the technical solution of the present invention in detail, the overall process of the present invention is described below in combination with some specific embodiments. It is easy to understand that the following is an explanation of the technical principle of the present invention and cannot be regarded as a limitation of the present invention.

[0107] First, it's important to note that the connection and data exchange between IoT devices and the IoT platform are the core of the IoT system. IoT devices typically include sensors, actuators, and smart terminals, which connect to the IoT platform via various communication protocols (such as Wi-Fi, Bluetooth, LoRa, and NB-IoT). Interaction between devices and the platform involves both data uplink and data downlink. IoT devices transmit collected data to the IoT platform via uplink channels; data downlink refers to the IoT platform sending instructions or configuration updates to devices.

[0108] IoT devices may not be able to stay online or maintain a long-term connection with the platform due to battery life limitations, insufficient network coverage, network congestion, device failures, security mechanisms, and protocol restrictions. These factors hinder real-time communication between devices and the platform, preventing the timely receipt and execution of platform-issued commands, impacting the efficiency and accuracy of remote control. For example, to conserve battery life, devices periodically enter low-power mode, becoming offline and unable to receive commands. When network signals are weak or network resources are limited, devices may frequently disconnect, similarly impacting the timely delivery of commands.

[0109] To address the issue of IoT devices being offline for various reasons, IoT platforms typically implement a command caching strategy. When the platform detects that a target device is offline, it doesn't immediately abandon the command transmission process. Instead, it stores these commands in a cache. Once the device comes back online, the platform immediately retrieves these pending commands from the cache and quickly sends them to the device. This ensures that commands are ultimately delivered even when the device is temporarily offline, improving system reliability and user experience.

[0110] Although IoT platforms use caching mechanisms to handle commands from offline devices, they cannot store these commands indefinitely for two key reasons:

[0111] 1. Storage Capacity and Performance Limitations: IoT platforms need to manage a large number of devices and data, and their storage resources are not unlimited. Excessive instruction caches consume valuable storage space, impacting the platform's overall performance and responsiveness. Therefore, platforms must rationally plan their storage resources to avoid overburdening the system due to excessive instruction caches.

[0112] 2. Command Timeliness: Many control commands in IoT applications are time-sensitive, meaning they are valid within a specific time window. Beyond this time window, the command may lose its meaning or become invalid. Therefore, the platform needs to set a reasonable command TTL to ensure that commands are processed within their validity period. Commands that exceed the TTL will be automatically cleared to avoid wasted resources.

[0113] Among existing technologies, there are two typical technical implementations:

[0114] 1. A delayed queue-based solution to control the TTL expiration cleanup mechanism for device command caches. A delayed queue is a special data structure that can be implemented using existing message queue services, such as Kafka and Pulsar. It allows messages to be consumed after a specified time point, making it ideal for processing tasks that need to be executed at a certain point in the future, such as instructions for offline devices. The specific process is as follows:

[0115] (1) Create a delay queue: In the IoT platform, a delay queue is created for each device or device group to store unprocessed instructions for the device.

[0116] (2) Command Enqueue: When a command is received for an offline device, the command service writes it into the database (the command status is "stored"), stores the message in the device's session information, sends it to the corresponding delay queue, and sets a TTL value to indicate the validity period of the command.

[0117] (3) Device online processing: When an offline device comes back online, the platform should immediately check the session of the device, send all non-timed-out instructions to the device for processing, and store a piece of instruction information and its status as "issued".

[0118] (4) Device command expiration cleanup and marking: Messages in the delay queue will still notify the command service to update the command status after the TTL expires. If the command status in the database is "issued", no processing will be done; if the command status is "stored", the command status will be updated to "expired".

[0119] Since the message queue middleware generally cannot directly delete a specific device message, after the instruction cached in the device session is issued, the delayed message in the message queue will not be directly deleted. The problems caused are:

[0120] (1) Actively canceled instructions cannot be deleted from the message queue.

[0121] (2) The cached command has been successfully sent and cannot be cleared from the message queue.

[0122] (3) All cached messages are accumulated in the message queue. When the message volume is large, it will cause a certain amount of pressure on the message queue.

[0123] Therefore, these issued instructions will still occupy storage space in the message cache queue until the TTL expires and the cached instruction message is consumed.

[0124] 2. A device command cache solution based on Redis is to design a list data type to store cached device commands. The device ID is used as the key of the Redis key-value pair, and the value is the command list corresponding to the device ID. The specific process of processing cached commands is as follows:

[0125] (4) Create a device-level command list: In the IoT platform, create a Redis list structure for each device or device group to store unprocessed commands for the device.

[0126] (5) Cached Commands: When a command is received for an offline device, the command service writes it to the database (the command status is "stored") and stores the message in the device's session information and in Redis. Because Redis's expiration policy can only set the TTL value of a key, it is not possible to set the TTL value of a specific command in the list. Therefore, only the device's cache time and the command ID can be stored as values ​​in the list.

[0127] (6) Device online processing: When an offline device comes back online, the platform should immediately check the device's session, send all non-timed commands to the device for processing, and store a command message with the status "issued". Traverse the device's cached command list in Redis and delete the issued commands.

[0128] (7) Expired device command cleanup and marking: Expired commands stored in Redis need to be scanned by a scheduled task in the command queue of each device cache. If the expiration time is less than the current time, the command is dequeued and the command service is notified to update the command status to "expired".

[0129] In this solution, deleting successfully issued instructions from the cache requires traversing the instruction list, with a time complexity of O(n), where n is the number of instructions cached on the device. Clearing expired instructions from the platform requires periodically scanning each device's cached instruction queue, with a time complexity of O(m) × O(n), where m is the number of devices and n is the number of cached instructions. Performance deteriorates when the number of devices and the number of cached instructions are large.

[0130] In summary, when processing instructions from offline devices, the IoT platform needs to provide the necessary instruction caching capabilities, consider storage capacity, performance limitations, and instruction timeliness, and provide a high-performance instruction caching strategy and TTL mechanism.

[0131] In view of this, the present invention designs two timed task queues, and designs the instruction expiration time with an accuracy of 1 second (which can be adjusted adaptively according to actual needs). It is divided into two queues, each of which contains a specified time grid, and each grid time unit is 1 second (which can be adjusted adaptively according to actual needs), pointing to the instruction cache list that expires in this second. The queue regularly takes out the instructions of the whole second every second for unified operation. Figure 4 As shown, the main process steps of the present invention are as follows:

[0132] (1) Create a timed queue: Initialize two queues, one for the current time window and the other for the next time window. Fill these two queues based on the current time, ensuring that each grid corresponds to an instruction within the next second.

[0133] (2) Command Enqueue: When receiving a command for an offline device, check whether its expiration time falls within the time range covered by the current dual queue. If so, insert the command into the list at the corresponding "second" time.

[0134] (3) Device online processing: After the device comes back online, all unexpired instructions are immediately extracted from the queue and sent to the device. At the same time, the instruction status is updated to "issued" and removed from the queue.

[0135] (4) Expired device command cleanup and marking: Check the commands in the current time window queue every second. For commands that have not been issued and have expired, mark their status as "expired" and update the database asynchronously.

[0136] (5) Processing canceled commands: A command can be canceled before being sent to the device. If the cache expiration time of the command is within the time window of the two timer queues, the command can be deleted from the timer queue.

[0137] (6) Window switching: When the first window period ends, the current window queue is cleared, the next time window queue is upgraded to the current window, and the above process is repeated.

[0138] The present invention can solve the following technical problems:

[0139] (1) Expired instruction cache occupies storage space: The technical solution based on the delay queue requires all cached messages to be accumulated in the message queue. There is no guarantee that the cached instructions will be deleted immediately after they are issued. They still need to continue to occupy storage space until the instruction reaches the expiration time, and the delayed message can be processed by the instruction service.

[0140] (2) Poor performance when the number of devices is large: The Redis-based solution has a large time complexity. When the number of devices is large, the scanning task will time out.

[0141] The technical effects achieved by the present invention are as follows: (1) High-precision time management: Through instruction expiration time management accurate to the second, the timeliness and accuracy of instructions are ensured. (2) Dynamic window switching: The dual-queue mechanism supports dynamic window switching, ensuring the continuity and flexibility of instruction processing. (3) Efficient resource utilization: The HashMap data structure is used to achieve fast retrieval and efficient storage of instructions; only instruction data within the time window is loaded, reducing memory resource consumption.

[0142] In some preferred embodiments, Figure 4 As shown, the process logic of the present invention can be specifically implemented as follows:

[0143] 1. Create a timed queue:

[0144] Data structure selection: Use HashMap <Long, HashSet <instruction>> As the basic data structure, the Long type represents the timestamp (accurate to the second), HashSet <instruction>Stores a list of pending instructions within the same second. Using a HashMap as the queue's underlying data structure allows for scalability, allowing for flexible adjustments to the time window size (i.e., the Map's capacity). A fixed-length array can also be used instead of a HashMap, but this requires adding records of the start timestamps of the two queues. Accessing each grid at a specific moment requires using a time offset (current time minus the queue's start time) as an array index.

[0145] Queue Initialization: When the system starts, two queues are created, one for the current time window and one for the next time window. Each queue contains a series of grids, each corresponding to a list of commands for the next second. The command data for the two time windows is loaded from the database, and the command ID is inserted into the Set of cached commands stored in the grid.

[0146] The timed queue built based on the time window can ensure that only the instruction data within the time window range is loaded, without loading all the cached instruction data.

[0147] 2. Command queue:

[0148] Timestamp Calculation: When the command service receives a command sent to an offline device, it calculates its cache expiration timestamp to determine whether it falls within the current dual queue time window. If it does, it is enqueued. Commands outside the time window are directly stored and wait for the window to roll out.

[0149] Instruction insertion: If the expiration time of the instruction is within the time window covered by the two queues, the instruction is inserted into the Set of the corresponding time grid according to the expiration timestamp.

[0150] This instruction enqueue method can ensure that newly added cache instructions can be quickly added to the corresponding time grid without the need for instruction cache expiration time sorting operations with high time complexity.

[0151] 3. Device online processing:

[0152] Status Update and Record Deletion: After a device comes online, immediately retrieve all unexpired commands from the device session and send them to the device. For successfully sent commands, remove the corresponding record from the queue and update the command status in the database to "Successful."

[0153] Deleting a successful command from the queue: Based on the cache expiration time stored in the command data. If the command cache expiration time is within the current time window, the corresponding time grid is found based on the expiration time, and the corresponding command record in the Set is removed based on the command ID. If it is not within the time window, the command status is directly updated to "Sent" in the database.

[0154] The above operation of removing instructions from the timed queue has a time complexity of O(1) and does not require a complete scan of the entire queue.

[0155] 4. Expired instruction cleanup and marking:

[0156] Instruction dequeue: The system periodically takes out the instruction set cached in the time grid of this second from the queue every second and performs the dequeue operation.

[0157] Status update: Based on the cached expired instruction set retrieved, use an asynchronous thread to update the instruction status of the corresponding instruction in the database to "expired".

[0158] The time complexity of dequeuing expired instructions from the timed queue is O(1), which has a significant performance advantage over the above two technical solutions.

[0159] 5. Processing of cancelled instructions:

[0160] Delete canceled orders from the queue: Based on the cache expiration time stored in the order data. If the order cache expiration time is within the current time window, the corresponding time grid is found based on the expiration time, and the corresponding order record in the Set is removed based on the order ID. If it is not within the time window, the order status is directly updated to "cancelled" in the database.

[0161] 6. Window switching and cycling:

[0162] Window switching: When the first time window ends, the pointers to the two queues are swapped. The next time window queue is upgraded to the current window. At the same time, the next time window is pointed to the completed "current window queue". All data in the queue is cleared, and the instruction data within the next time window range is loaded from the database. The above process is repeated.

[0163] Loop processing: The system continuously monitors the device status and instruction status, and cyclically executes operations such as instruction queuing, device online processing, and expired instruction cleaning and marking to ensure the continuity and efficiency of instruction processing.

[0164] Exemplarily, the process steps of the present invention are described below in combination with data examples of specific application scenarios. For example, when the device is offline at 10:00:05, the platform receives an instruction with an expiration time of 10:00:15, and the instruction is inserted into the 15th second grid of the second queue. The device comes online at 10:00:15, and the system immediately sends all non-expired instructions and updates the status. Subsequently, the system checks the current queue every second, marks and clears expired instructions. When 10:00:59 arrives, the first queue is emptied, and the second queue becomes the new current queue, continuing to execute instruction management and expiration processing. The specific processing flow example is as follows:

[0165] 1. Create a timed queue:

[0166] like Figure 5 As shown in the figure, assuming the current time is 10:00:00, the system initializes two one-hour queues, covering the time windows of 10:00:00-10:59:59 and 11:00:00-11:59:59, respectively. These correspond to the current time window and the next time window, respectively. Each queue contains 3600 cells, each keyed by a timestamp. A HashSet of 1000 cells is assigned, corresponding to the list of instructions within the next second. If a data structure is used to implement the queue, the array index is the offset in seconds between the expiration time and the queue start time.

[0167] 2. Command queue:

[0168] by Figure 5 As an example, the data structure of the timing queue shown in the figure is as follows: Figure 6 As shown in the figure, when the device goes offline at 10:05:00, the platform receives a command with an expiration time of 11:05:00. This command is inserted into the 300-second slot of the second queue. Cached commands with expiration times outside the time windows of the two timed queues are only processed into the warehouse.

[0169] 3. Device online processing:

[0170] by Figure 5 As an example, the data structure of the timing queue shown in the figure is as follows: Figure 7 As shown in the example, assuming the device corresponding to a command with an expiration time of 11:05:00 comes online at 10:10:15, the system immediately sends all unexpired commands and updates the command status in the database to "Successful." Based on the command expiration time of 11:05:00, successful commands are deleted from the queue within the time window of 11:00:00-11:59:59. Since cached commands with expiration times outside the time windows corresponding to the two timed queues exist only in the database, only the status of the corresponding command in the database is directly updated.

[0171] 4. Expired instruction cleanup and marking:

[0172] Every second, the system periodically removes the instruction set cached in the current second's time grid from the queue, executes the dequeue operation, and updates the instruction status in the database to "expired." For example, at 10:15:00, the instruction set stored in the current time grid is removed from the queue and assigned to the asynchronous thread for execution. The current time grid is then removed from the Map. The asynchronous thread, based on the instructions in the set, updates the "expired" status in the database. The system then waits for the next second to begin and repeats the process.

[0173] 5. Processing of cancelled instructions:

[0174] Suppose there's a command that expires at 11:10:59. If the command's cache expiration time is determined to be within the next time window, the corresponding time grid is found based on the command's cache expiration time of 11:10:59. Then, the corresponding command record in the Set is removed based on the command ID. If it's not within the time window, the command's status is directly updated to "cancelled" in the database.

[0175] 6. Window switching and cycling:

[0176] like Figure 8 As shown, when 10:59:59 arrives, the pointers of the two queues are exchanged, the second queue becomes the new current queue, and continues to perform instruction management and expiration processing. The first queue is cleared and the instruction data of the next time window is loaded.

[0177] In summary, the present invention proposes an instruction management solution based on dual timed task queues, which enables the caching of offline device instructions on an IoT platform, aiming to address the storage space and performance bottlenecks of instruction caching in large-scale device environments. The core of the present invention lies in the design of two high-precision (1-second) timed queues for storing expiring instructions. Each queue consists of a series of grids with 1-second time units, storing instructions in the form of a Map, where the key is a timestamp and the value is a list of cached instructions. The main process includes: initializing the queues and filling them with instructions within the current time range; receiving and categorizing new instructions in real time; quickly issuing non-expired instructions when a device comes online; regularly clearing expired instructions; and supporting instruction cancellation. Through a dynamic window switching mechanism, efficient instruction management and rational resource utilization are achieved, solving the storage waste and poor performance problems existing in traditional delay queues and Redis solutions, and improving the timeliness, accuracy, and overall system performance of instruction processing.

[0178] Compared with the prior art, the present invention includes at least the following innovations and beneficial effects:

[0179] 1. Dual timing queues ensure the continuity of processing cache instructions:

[0180] This invention uses a two-timing queue mechanism, creating a current time window queue and a next time window queue, to load only the cached instructions within the two time windows. This avoids frequent database scans when the time windows scroll. Cached instructions for the next time window are scanned only when the queues switch, reducing I / O times. The system supports dynamic window switching. When the first time window ends, the next time window queue is automatically upgraded to the current window, ensuring continuous instruction processing.

[0181] Second, the time window and time grid mechanism ensures high-precision instruction expiration time management:

[0182] The introduction of the concepts of time windows and time grids enables highly precise management of instruction expiration times. Each queue consists of a series of grids with one-second time units, meaning instruction expiration times are set to a precision of one second. Instructions are assigned to the corresponding grids through precise timestamp matching. This highly precise time management approach avoids instruction processing delays and resource waste caused by time ambiguity in traditional caching strategies.

[0183] 3. Dynamic deletion of cache instruction status:

[0184] The system is designed to support the deletion of queued cached commands. The underlying data structure already supports the rapid retrieval and restoration of commands that have expired at a specific time. For successfully issued or canceled cached commands, they can be removed from the queue at a very low cost to avoid repeated processing by the system.

[0185] 4. Data structure design with high performance and low resource usage:

[0186] A HashMap data structure is used to store instructions, where the key is the timestamp and the value is the instruction list. This design not only supports fast retrieval and efficient storage of instructions, but also reduces memory usage and improves system resource utilization.

[0187] On the other hand, Figure 9 As shown, an embodiment of the present invention provides a cache device 900 for offline device instructions, which may include:

[0188] The first module 901 is configured to use the current time node as a target time node and initialize two consecutive time queues with the target time node as the starting point; the time queues sequentially include a first window queue and a second window queue; each time queue includes multiple time windows within a preset time range after the target time node;

[0189] The second module 902 is configured to obtain pending instructions and their expiration times from all offline devices, and insert the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with device identifiers;

[0190] The third module 903 is used to obtain the operating status of the offline device, determine the offline device whose operating status is online as an online device; based on the device identification of the online device, take the corresponding to-be-processed instruction from the timing queue and send it to the online device;

[0191] The fourth module 904 is configured to, in response to the time change, set the next time node of the target time node as the target time node and perform a clearing operation on the time window corresponding to the previous time node of the target time node;

[0192] The fifth module 905 is configured to return to executing the second module until all time windows in the first window queue are cleared.

[0193] The sixth module 906 is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of the offline device.

[0194] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:

[0195] A seventh module is configured to mark the instruction status of the corresponding instruction to be processed in the instruction database as a first status;

[0196] Among them, the seventh module is executed after the third module.

[0197] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:

[0198] The eighth module is configured to mark the instruction status of the pending instruction for executing the dequeue operation in the instruction database as the second status.

[0199] In some embodiments, the instruction to be processed is obtained from an instruction database; the apparatus may further include:

[0200] The ninth module is configured to delete the pending instruction on which the cancellation operation is performed from the timing queue in response to the target object's cancellation operation on the pending instruction, and mark the instruction status of the pending instruction on which the cancellation operation is performed as a third status in the instruction database.

[0201] The contents of the method embodiments of the present invention are all applicable to the device embodiments. The functions specifically implemented by the device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0202] In another aspect, an embodiment of the present invention further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the sensitive information protection method described above when executing the computer program. The electronic device can be any intelligent terminal, including a tablet computer and an in-vehicle computer.

[0203] It can be understood that the contents of the above method embodiments are applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0204] like Figure 10 As shown, Figure 10 A specific example of the hardware structure of an electronic device 1000 according to an embodiment is shown. The electronic device 1000 includes:

[0205] The processor 1001 may be implemented as a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided by the embodiments of the present invention.

[0206] The memory 1002 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1002 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called by the processor 1001 to execute the network node population optimization method of the embodiment of the present invention.

[0207] Input / output interface 1003, used to implement information input and output;

[0208] Communication interface 1004, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);

[0209] Bus 1005 , which transmits information between various components of the device (e.g., processor 1001 , memory 1002 , input / output interface 1003 , and communication interface 1004 );

[0210] The processor 1001 , the memory 1002 , the input / output interface 1003 and the communication interface 1004 are connected to each other in communication within the device via the bus 1005 .

[0211] The electronic device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one location or distributed across multiple network units. Some or all of these modules may be selected based on actual needs to achieve the objectives of this embodiment.

[0212] The contents of the method embodiments of the present invention are all applicable to the electronic device embodiments. The functions specifically implemented by the electronic device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0213] Another aspect of an embodiment of the present invention further provides a computer-readable storage medium, wherein the storage medium stores a program, and the program is executed by a processor to implement the above method.

[0214] It should be noted that the computer-readable medium described in the embodiments of the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0215] The contents of the method embodiments of the present invention are all applicable to the computer-readable storage medium embodiments. The functions specifically implemented by the computer-readable storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0216] The present invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the above method.

[0217] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0218] It should be noted that although several modules of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules or units described above can be concretized in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.

[0219] Through the above description of the embodiments, it will be readily understood by those skilled in the art that the example embodiments described herein can be implemented via software or via a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored on a non-volatile storage medium (such as a CD-ROM, USB flash drive, or mobile hard drive) or on a network and includes instructions for causing a computing device (such as a personal computer, server, touch terminal, or network device) to execute the methods according to the embodiments of the present invention.

[0220] In some optional embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided in an exemplary manner for the purpose of providing a more comprehensive understanding of the technology. The disclosed method is not limited to the operation and logic flow presented herein. Optional embodiments are contemplated in which the order of the various operations is changed and the sub-operations described as a part of a larger operation are performed independently.

[0221] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise stated, one or more of the functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in separate physical devices or software modules. It will also be understood that a detailed discussion of the actual implementation of each module is not necessary for understanding the present invention. More specifically, given the properties, functions, and internal relationships of the various functional modules in the devices disclosed herein, the actual implementation of the module will be understood within the ordinary skill of an engineer. Therefore, a person skilled in the art will be able to implement the present invention as set forth in the claims using ordinary skill without undue experimentation. It will also be understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.

[0222] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the method of the present invention. The aforementioned storage medium includes various media that can store program code, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.

[0223] The logic and / or steps represented in a flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution apparatus, device, or apparatus (e.g., a computer-based apparatus, a processor-included apparatus, or other apparatus capable of fetching and executing instructions from, an instruction execution apparatus, device, or apparatus). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution apparatus, device, or apparatus.

[0224] More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting, or processing it in another suitable manner as necessary, and then storing it in a computer memory.

[0225] It should be understood that various components of the present invention may be implemented using hardware, software, firmware, or a combination thereof. In the aforementioned embodiments, multiple steps or methods may be implemented using software or firmware stored in a memory and executed by a suitable instruction execution device. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof may be used: a discrete logic circuit having logic gate circuits for implementing logic functions on data signals, an application-specific integrated circuit having suitable combinational logic gate circuits, a programmable gate array (PGA), a field-programmable gate array (FPGA), etc.

[0226] Throughout this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples" indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.

[0227] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to the embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the claims and their equivalents.

[0228] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.< / instruction> < / instruction> < / instruction> < / instruction>

Claims

1. A method for caching instructions for an offline device, characterized in that: The following steps are involved: The current time node is used as the target time node, and two consecutive time queues are initialized with the target time node as the starting point; the time queues sequentially include a first window queue and a second window queue; each of the time queues includes multiple time windows within a preset time range after the target time node; Obtaining pending instructions and their expiration times of all offline devices, and inserting the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with device identifiers; Acquire the running status of the offline device, and determine the offline device whose running status is online as an online device; based on the device identification of the online device, take out the corresponding pending instruction from the timing queue and send it to the online device; In response to a time change, taking a next time node of the target time node as the target time node, and performing a clearing operation on the time window corresponding to a previous time node of the target time node; Returning to the step of obtaining the pending instructions and their expiration times of all offline devices, until all the time windows in the first window queue have completed the cleanup operation; Based on the next preset time range of the second window queue, the time node corresponding to each time window of the first window queue is reloaded, the queue pointers of the first window queue and the second window queue are exchanged, and the step of obtaining the pending instructions and their expiration times of all offline devices is returned to execute, and the instruction caching of the offline devices is continued.

2. The offline device instruction caching method according to claim 1, characterized in that: Initializing two consecutive timing queues with the target time node as the starting point includes the following steps: The first window queue and the second window queue are created according to two consecutive preset time ranges after the target time node and in combination with a preset basic data structure corresponding to the time window; Among them, all the time windows in each of the timing queues correspond sequentially to each time node within the preset time range; an instruction list is set in the time window, and the instruction list is used to store one or more instructions to be processed.

3. The offline device instruction caching method according to claim 1, characterized in that: All the time windows in each of the timing queues sequentially correspond to each time node within the preset time range, and a list of instructions is set in the time window; and inserting the to-be-processed instructions into the corresponding time window in the timing queue based on the expiration time comprises the following steps: Determine a target time window according to the time node corresponding to the expiration time; Inserting the pending instruction into the instruction list in the target time window.

4. The offline device instruction caching method according to claim 1, characterized in that: The pending instructions are obtained from an instruction database; after the step of taking out the corresponding pending instructions from the timing queue and sending them to the online device, the method further includes the following steps: The instruction state of the corresponding instruction to be processed in the instruction database is marked as the first state.

5. The offline device instruction caching method according to claim 1, characterized in that: The to-be-processed instruction is obtained from an instruction database; and the clearing operation on the time window corresponding to the previous time node of the target time node comprises the following steps: A dequeue operation is performed on the pending instructions in the time window corresponding to the previous time node of the target time node.

6. The method for caching offline device instructions according to claim 5, characterized in that: The method further comprises the following steps: The instruction state of the pending instruction for executing the dequeue operation in the instruction database is marked as a second state.

7. The offline device instruction caching method according to claim 1, characterized in that: The instructions to be processed are obtained from an instruction database; the method further comprises the following steps: In response to the target object canceling the pending instruction, the pending instruction executing the cancel operation is deleted from the timing queue, and the instruction state of the pending instruction executing the cancel operation in the instruction database is marked as a third state.

8. A cache device for offline device instructions, characterized in that: include: The first module is configured to use the current time node as a target time node and initialize two consecutive time queues with the target time node as a starting point; the time queues sequentially include a first window queue and a second window queue; each of the time queues includes multiple time windows within a preset time range after the target time node; The second module is configured to obtain pending instructions and their expiration times of all offline devices, and insert the pending instructions into the corresponding time window of the timing queue based on the expiration time; wherein the pending instructions are associated with device identifiers; The third module is configured to obtain the operating status of the offline device, determine the offline device whose operating status is online as an online device; and based on the device identifier of the online device, retrieve the corresponding pending instruction from the timing queue and send it to the online device; A fourth module is configured to, in response to a time change, use a next time node of the target time node as the target time node and perform a clearing operation on the time window corresponding to a previous time node of the target time node; A fifth module is configured to return to executing the second module until the cleanup operation is completed for all the time windows in the first window queue; The sixth module is used to reload the time node corresponding to each time window of the first window queue based on the next preset time range of the second window queue, exchange the queue pointers of the first window queue and the second window queue, return to execute the second module, and continue to cache instructions of the offline device.

9. An electronic device, characterized in that: including a processor and a memory; The memory is used to store programs; The processor executes the program to implement the method according to any one of claims 1 to 7.

10. A computer storage medium storing a program executable by a processor, characterized in that: The program executable by the processor is used to implement the method according to any one of claims 1 to 7 when executed by the processor.