Data caching method, device, electronic device and storage medium
By initializing the ring cache space in the car and dynamically adjusting the memory according to the amount of data, the problem of delay and resource waste when transmitting multimedia content in the car network is solved, and efficient utilization of memory resources and reduction of data transmission delay is achieved.
Patent Information
- Application Number
- CN202111400582.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-24
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2041-11-24
AI Technical Summary
In the prior art, when the automotive network transmits multimedia content, it is easy to cause delay and blockage due to excessive data volume, and the cache space is fixed, resulting in waste of memory resources.
By initializing the ring cache space and dynamically adjusting the memory space according to the amount of data stored and read, data receiving and reading threads are executed in parallel, and the cache space size is dynamically adjusted.
Improve the efficiency of memory resources and reduce the processing time and transmission delay of data cache.
Smart Images

Figure CN114048152B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer application technology, and in particular to a data caching method, device, electronic device, and storage medium. Background Art
[0002] With the development of internet technology, the intelligence of devices like cars and televisions is increasing year by year. Cars have also become a key carrier of multimedia services, with video, audio, and other media content enriching the car user experience. However, with the increasing amount of media content, the burden on car networks is gradually increasing. In particular, when transmitting and processing multiple media contents, the large amount of media data can easily lead to delays or even congestion in car networks.
[0003] To address these issues, cars need to pre-cache media content to prevent network congestion and data loss. Existing media content caching is primarily implemented using threads, with separate threads created for each piece of media content to receive and send data. However, this approach is only suitable for communication scenarios with low data flows, and the cache space allocated during data reception and transmission is relatively fixed, resulting in significant waste of memory resources. Summary of the Invention
[0004] The present invention provides a data caching method, device, electronic device and storage medium, which improve the utilization efficiency of memory resources and reduce the transmission delay caused by data caching by dynamic caching of data.
[0005] In a first aspect, an embodiment of the present invention provides a data caching method, wherein the method includes:
[0006] Initialize the ring buffer space according to the first memory threshold;
[0007] The memory space of the ring buffer space is dynamically adjusted according to the amount of stored data and / or read data.
[0008] In a second aspect, an embodiment of the present invention further provides a data cache device, wherein the device includes:
[0009] An initialization module, configured to initialize the ring buffer space according to a first memory threshold;
[0010] The dynamic adjustment module is used to dynamically adjust the memory space of the ring buffer space according to the amount of stored data and / or read data.
[0011] In a third aspect, an embodiment of the present invention further provides an electronic device, wherein the electronic device includes:
[0012] one or more processors;
[0013] a memory for storing one or more programs,
[0014] When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method as described in any one of the embodiments of the present invention.
[0015] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data caching method as described in any one of the embodiments of the present invention.
[0016] An embodiment of the present invention generates a circular cache space of a size corresponding to a first memory threshold, and dynamically adjusts the memory space of the circular cache space according to the amount of data during data storage and data reading, thereby realizing dynamic use of the cache space, improving the utilization efficiency of memory resources, reducing the processing time of the data cache, and reducing the data transmission delay. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 This is a flow chart of a data caching method provided in Example 1 of the present invention;
[0018] Figure 2 This is a flow chart of another data caching method provided by the second embodiment of the present invention;
[0019] Figure 3 This is an example diagram of a ring cache space provided by the second embodiment of the present invention;
[0020] Figure 4 This is an example diagram of a ring buffer space adjustment provided by the second embodiment of the present invention;
[0021] Figure 5 This is a flowchart of another data caching method provided in the third embodiment of the present invention;
[0022] Figure 6 This is a structural diagram of a data cache device provided by a fourth embodiment of the present invention;
[0023] Figure 7 This is a structural diagram of an electronic device provided in Example 5 of the present invention. DETAILED DESCRIPTION
[0024] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions, rather than all, of the present invention. Furthermore, the embodiments and features of the embodiments may be combined with one another unless they conflict.
[0025] Example 1
[0026] Figure 1 This is a flow chart of a data caching method provided in the first embodiment of the present invention. This embodiment is applicable to the case of business data caching in a car. The method can be executed by a data caching device, which can be implemented in hardware and / or software. Figure 1 The method provided in the embodiment of the present invention specifically includes the following steps:
[0027] Step 110: Initialize the ring buffer space according to the first memory threshold.
[0028] Among them, the first memory threshold can be a pre-set memory space occupancy value, the first memory threshold can be determined by the average length of the business data, the ring cache space can be a cache space connected at the end in the logical structure, and the business data can be cached in the ring cache space.
[0029] In an embodiment of the present invention, when caching service data, memory space may be applied for as a ring buffer space according to a first memory threshold, wherein the size of the memory space occupied by the ring buffer space may correspond to the first memory threshold. It is understood that the process of initializing the ring buffer space may include applying for a cache address of the ring buffer space and generating a read / write pointer of the ring buffer space.
[0030] Step 120: Dynamically adjust the memory space of the ring buffer space according to the amount of stored data and / or read data.
[0031] Storing data may be the process of caching data in a ring buffer space, and the stored data may include video data, audio data, and text data. Reading data may be the process of reading cached data from the ring buffer space. Data volume may be information reflecting the size of stored data or read data, and data volume may refer to the size of the ring buffer space required for storing or reading data.
[0032] Specifically, when reading or storing data, the ring buffer space can extract the amount of data read or stored, and increase or decrease the memory space occupied by the ring buffer space according to the amount of data. It is understood that the ring buffer space can be a continuous memory space or a discontinuous memory space node, and the process of dynamically adjusting the memory space can be to extend or shorten the continuous memory space or to increase or decrease the discontinuous memory space nodes.
[0033] An embodiment of the present invention generates a circular cache space of a size corresponding to a first memory threshold, and dynamically adjusts the memory space of the circular cache space according to the amount of data during data storage and data reading, thereby realizing dynamic use of the cache space, reducing the utilization efficiency of memory resources, improving the processing time of the data cache, and reducing the data transmission delay.
[0034] Example 2
[0035] Figure 2 This is a flowchart of another data caching method provided by the second embodiment of the present invention. This embodiment of the present invention is a specific embodiment of the above invention. Figure 2 The method provided in the embodiment of the present invention specifically includes the following steps:
[0036] Step 210: Apply for memory space as a ring buffer space according to the first memory threshold.
[0037] Specifically, a memory space may be applied for as a ring buffer space, and the size of the memory space may be a first memory threshold. It is understandable that the memory space may include a continuous memory space or multiple discontinuous memory space nodes.
[0038] Step 220: Initialize the read pointer and the write pointer according to the starting address of the memory space.
[0039] Among them, the starting address can be the logical address or physical address at the starting position of the memory space, the read pointer can be the identification information used to mark the starting position of data reading in the memory space, and the write pointer can be the identification information used to mark the starting position of data writing in the memory space.
[0040] In an embodiment of the present invention, the starting address of the memory space may be acquired, and a write pointer and a read pointer may be set for the ring buffer space. The write pointer and the read pointer may be set to point to the starting address.
[0041] Step 230: Initialize the first memory threshold to the remaining memory size of the ring buffer space.
[0042] The remaining memory size may be the size of the unoccupied memory space of the ring buffer space.
[0043] Specifically, the remaining memory size of the ring buffer space may be set to a first memory threshold, which may indicate that no data has been written into the ring buffer space.
[0044] In an exemplary embodiment, Figure 3 This is an example diagram of a ring buffer space provided by the second embodiment of the present invention, see Figure 3The ring buffer space can be a memory space connected at the end. A read pointer and a write pointer can be set in the memory space. Business data can be stored in the ring buffer space along the write direction according to the write pointer, and the business data stored in the ring buffer space can be read from the ring buffer space along the write direction according to the read pointer. The black part between the write pointer and the read pointer in the ring buffer space can represent the area where business data has been written. The white part between the write pointer and the read pointer in the ring buffer space can represent the blank area. The size of the blank area can represent the remaining memory size. See Figure 3 The ring buffer area can maintain two states: normal state and rollback state. In the normal state, the write pointer is writing data, and the read pointer is ahead of the write pointer, indicating that there is still free space in the memory space. In the rollback state, the write pointer is ahead of the read pointer, indicating that there is still free space in the memory space. The normal state can refer to the write pointer moving in the write direction, while the rollback state can refer to the write pointer moving in the opposite direction of the write direction.
[0045] Step 240: Create a data receiving thread to obtain business data and determine the size of the business data.
[0046] The data receiving thread may be the smallest execution unit for receiving data and may have independent system resources. There may be one or more data receiving threads, each of which may have its own system resources. Different data receiving threads may be executed in parallel to receive different business data.
[0047] In an embodiment of the present invention, a data receiving thread may be created to receive business data. After the business data is acquired using the data receiving thread, the amount of the received business data may be determined to determine the memory space occupied by the data in the ring buffer space.
[0048] Step 250: Determine whether the difference between the data size and the remaining memory size of the memory space meets the storage increase threshold.
[0049] Among them, the memory increase threshold can be the critical value that requires increasing the ring cache space. When the storage increase threshold is met, the memory space of the ring cache space needs to be increased. The memory increase threshold can be set in advance, and the value of the memory increase threshold can be determined according to the space size required for the rollback operation of the ring cache space.
[0050] In an embodiment of the present invention, the data volume size and the remaining memory size of the memory space can be compared to determine the difference between the two. If the difference is greater than or equal to the storage increase threshold, it means that the remaining memory of the ring cache space can store business data without increasing the memory space, and the storage increase threshold is met. If the difference is less than the storage increase threshold, it means that the memory space of the ring cache space cannot accommodate the number of businesses, and the memory space threshold does not meet the storage increase threshold.
[0051] Furthermore, based on the above embodiment of the invention, the storage increase threshold is determined according to the rollback space of the rollback operation of the ring cache space.
[0052] The rollback operation may be an operation to roll back the data storage state of the ring buffer space to a state between a certain time intervals. The rollback operation may affect the data storage state of the ring buffer space. The rollback space may be the minimum memory space required for data security of the rollback operation.
[0053] In the embodiment of the present invention, the storage increase threshold may be set to the size of the rollback space required by the ring buffer space when performing a rollback operation.
[0054] Step 260: If yes, store the service data into the memory space according to the write pointer of the ring buffer space.
[0055] Specifically, when the memory space of the ring buffer space meets the storage increase threshold, the business data may be written into the memory space in sequence starting from the write address of the ring buffer space, thereby implementing caching of the business data.
[0056] Step 270: If not, increase the memory space of the ring buffer space and then write the business data into the ring buffer space.
[0057] In an embodiment of the present invention, when the memory space of the ring buffer space does not meet the storage increase threshold, the memory space of the ring buffer space can be increased, and the service data can be written to the increased memory space of the ring buffer space. It is understood that the address of the increased memory space can be continuous or discontinuous with the address of the ring buffer space.
[0058] In an embodiment of the present invention, memory space is applied for as a circular cache space according to a first memory threshold, a read pointer and a write pointer are initialized using the starting address of the circular cache space, and the remaining memory size is set to the first memory threshold. A data receiving thread is used to receive business data, the data volume of the business data is obtained, and it is determined whether the difference between the data volume and the remaining memory size meets the storage increase threshold. If so, the business data is directly stored in the circular cache space. If not, the memory space of the circular cache space is increased and the business data is stored in the circular cache space, thereby realizing dynamic use of the cache space, improving the utilization efficiency of memory resources, reducing the processing time of the data cache, and reducing the data transmission delay.
[0059] Furthermore, based on the above-mentioned embodiment of the invention, the step of increasing the memory space of the ring buffer space and then writing the service data into the ring buffer space includes:
[0060] Apply for memory space as a new circular buffer space according to the sum of the first memory threshold and the storage increase threshold; migrate the storage data in the original circular buffer space to the new circular buffer space; write the business data into the new circular buffer space, and update the remaining memory size.
[0061] In an embodiment of the present invention, the sum of the first memory threshold and the storage increase threshold can be determined, and memory space can be re-applied as a new ring buffer space based on the sum. The stored data in the original ring buffer space can be copied to the new ring buffer space, the business data can be written to the new ring buffer space, and the remaining memory size can be updated to the remaining memory space size of the new ring buffer space. It is understood that after the stored data is copied to the new ring buffer space, the original ring buffer space can be released.
[0062] In an exemplary embodiment, Figure 4 This is an example diagram of a ring buffer space adjustment provided by the second embodiment of the present invention, see Figure 4 In the embodiment of the present invention, when business data is written into the ring buffer space or data is rolled back, there is a situation where the write pointer and the read pointer intersect, that is, when writing business data, the amount of business data and the remaining memory size of the memory space do not meet the storage increase threshold, and the memory space size of the ring buffer space needs to be adjusted. You can re-open a ring buffer space with a larger memory space, such as Figure 4 In the middle right annular buffer space, the stored data in the original annular buffer space can be written into the black portion of the new annular buffer space, and the business data to be written can be written into the oblique line portion of the new annular buffer space.
[0063] Example 3
[0064] Figure 5This is a process of another data caching method provided by the third embodiment of the present invention. This embodiment of the present invention is a specific embodiment based on the above invention embodiment. Figure 5 The method provided in the embodiment of the present invention specifically includes the following steps:
[0065] Step 310: Initialize the ring buffer space according to the first memory threshold.
[0066] Step 320: Create a data reading thread to read the business data in the ring buffer space and determine the data size of the business data.
[0067] Among them, the data reading thread can be the smallest execution unit for reading data in the ring cache space, can have independent system resources, the number of data reading threads can be one or more, the system resources between each data reading thread can be independent of each other, and different data reading threads can be executed in parallel.
[0068] In this embodiment of the present invention, a new data reading thread can be created and used to read the service data stored in the ring buffer space. For example, the service data can be read sequentially according to the read pointer of the ring buffer space. It is understood that while reading the service data, the amount of the service data read can be counted.
[0069] Step 330: When it is determined that the data size meets the storage reduction threshold, reduce the memory space of the ring buffer space.
[0070] Specifically, the amount of the read business data may be compared with a storage reduction threshold. If the storage reduction threshold is met, for example, the data amount is greater than or equal to the storage reduction threshold, the memory space of the control ring buffer space may be reduced.
[0071] In an embodiment of the present invention, the method of reducing the cache space may include releasing part of the memory space of the ring cache space, or applying for a new ring cache space with a smaller memory space, and copying the business data in the original ring cache space to the newly applied ring cache space to release the original ring cache space.
[0072] An embodiment of the present invention generates a circular cache space of a space size corresponding to a first memory threshold, uses a data reading thread to read the business data stored in the circular cache space, and counts the data volume of the business data. When the data volume meets the storage reduction threshold, the memory space occupied by the circular cache space is reduced, thereby realizing dynamic use of the cache space, improving the utilization efficiency of memory resources, and reducing data transmission delay.
[0073] Furthermore, based on the above embodiment of the invention, the remaining memory size of the annular buffer space is updated after the annular buffer space is increased or decreased.
[0074] In an embodiment of the present invention, after business data is written or read in the ring buffer space, the remaining memory size in the ring buffer space changes. The value of the remaining memory size can be increased or decreased according to the amount of business data written or read.
[0075] In an exemplary embodiment, a data caching method incorporating a windowed sliding ring buffer mechanism may include the following steps: 1. Initializing the necessary data structures for the windowed sliding ring buffer, which may include the ring buffer size, read pointer, and write pointer. 2. Starting two threads: one thread is responsible for receiving data and writing the received data into the windowed sliding ring buffer based on the amount of data received, the amount of available system memory, and the data transmission and reception speed. 3. In the other thread, data is read from the windowed sliding ring buffer. The operating principle of the windowed sliding ring buffer may be as follows: In a normal state, when the write pointer is writing data and the read pointer is ahead of the write pointer, there is free space at the back end of the buffer. In a pointer rollback state, when the write pointer is ahead of the read pointer, there is free space at the front end of the buffer. There is also a near-error state: when the write pointer rolls back and finds insufficient space, it will intersect with the read pointer (the dotted portion), which is obviously unreasonable. A portion of the unprocessed data will be overwritten and corrupted. Therefore, the entire buffer must be readjusted. Reallocation and adjustment: When insufficient space prevents write pointer rollback, we create a new, larger buffer, copy the unprocessed and written data sequentially to the new buffer, adjust the positions of the write and read pointers, and finally release the original buffer.
[0076] It's understandable that through continuous writing, reading, and expansion, the memory space of the window sliding ring buffer gradually expands. However, once the expansion reaches a certain level, a balance is reached. Because the amount of information cannot increase indefinitely, when the amount of information to be processed reaches its maximum, combined with the continuous processing of the read pointer, the buffer size will stabilize.
[0077] Example 4
[0078] Figure 6 This is a schematic diagram of the structure of a data caching device provided in Embodiment 4 of the present invention. It can execute the data caching method provided in any embodiment of the present invention and possesses the corresponding functional modules and beneficial effects. The device can be implemented in software and / or hardware and specifically includes an initialization module 401 and a dynamic adjustment module 402.
[0079] The initialization module 401 is configured to initialize the ring buffer space according to a first memory threshold.
[0080] The dynamic adjustment module 402 is configured to dynamically adjust the memory space of the ring buffer space according to the amount of stored data and / or read data.
[0081] In an embodiment of the present invention, an initialization module generates a circular cache space of a space size corresponding to a first memory threshold, and a dynamic adjustment module dynamically adjusts the memory space of the circular cache space according to the amount of data during data storage and data reading, thereby realizing dynamic use of the cache space, reducing the utilization efficiency of memory resources, improving the processing time of the data cache, and reducing the data transmission delay.
[0082] Furthermore, based on the above embodiment of the invention, the initialization module 401 includes:
[0083] A space applying unit is configured to apply for memory space as the ring buffer space according to the first memory threshold.
[0084] A pointer setting unit is used to initialize a read pointer and a write pointer according to the starting address of the memory space.
[0085] A memory recording unit is configured to initialize the first memory threshold to the remaining memory size of the ring buffer space.
[0086] Furthermore, based on the above embodiments of the invention, the dynamic adjustment module 402 includes:
[0087] The data receiving unit is used to create a data receiving thread to obtain business data and determine the data volume of the business data.
[0088] The memory judgment unit is used to determine whether the difference between the data amount and the remaining memory size of the memory space meets the storage increase threshold.
[0089] The first storage processing unit is configured to: if yes, store the service data into the memory space according to the write pointer of the ring buffer space.
[0090] The second storage processing unit is configured to, if not, increase the memory space of the annular buffer space and then write the business data into the annular buffer space.
[0091] Furthermore, based on the above-mentioned embodiments of the invention, the second storage processing unit is specifically used to: apply for memory space as the new ring cache space according to the sum of the first memory threshold and the storage increase threshold; migrate the storage data in the original ring cache space to the new ring cache space; write the business data into the new ring cache space, and update the remaining memory size.
[0092] Furthermore, based on the above-mentioned embodiment of the invention, the storage increase threshold in the apparatus is determined according to the rollback space of the rollback operation of the ring buffer space.
[0093] Furthermore, based on the above embodiments of the invention, the dynamic adjustment module 402 further includes:
[0094] The data reading unit is used to create a data reading thread to read the business data in the ring buffer space and determine the data volume of the business data.
[0095] The cache adjustment unit is configured to reduce the memory space of the ring cache space when it is determined that the data size meets a storage reduction threshold.
[0096] Furthermore, based on the above-mentioned embodiment of the invention, the device further includes:
[0097] The record updating unit is configured to update the remaining memory size of the annular buffer space after increasing or decreasing the annular buffer space.
[0098] Example 5
[0099] Figure 7 is a structural diagram of an electronic device provided by Embodiment 5 of the present invention. Figure 7 A block diagram of a computer device 312 suitable for implementing embodiments of the present invention is shown. Figure 7 The computer device 312 shown is only an example and should not limit the functionality and scope of use of the embodiments of the present invention. The device 312 is a typical computing device that implements the access control method.
[0100] like Figure 7 As shown, computer device 312 is implemented as a general-purpose computing device. Components of computer device 312 may include, but are not limited to, one or more processors 316, storage device 328, and a bus 318 that connects various system components (including storage device 328 and processor 316).
[0101] Bus 318 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0102] The computer device 312 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 312, including volatile and non-volatile media, removable and non-removable media.
[0103] The storage device 328 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 330 and / or cache memory 332. The computer device 312 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 334 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 Not shown, often called a "hard drive"). Although Figure 7 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a floppy disk) and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a Compact Disc-Read Only Memory (CD-ROM), a Digital Video Disc-Read Only Memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to bus 318 via one or more data media interfaces. Storage device 328 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present invention.
[0104] A program 336 having a set (at least one) of program modules 326 may be stored, for example, in a storage device 328. Such program modules 326 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 326 generally implement the functions and / or methods of the embodiments described herein.
[0105] The computer device 312 may also communicate with one or more external devices 314 (e.g., a keyboard, a pointing device, a camera, a display 324, etc.), one or more devices that enable a user to interact with the computer device 312, and / or any device that enables the computer device 312 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface 322. Furthermore, the computer device 312 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 320. As shown, the network adapter 320 communicates with the other modules of the computer device 312 via a bus 318. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in conjunction with the computer device 312, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (Redundant Arrays of Independent Disks, RAID) systems, tape drives, and data backup storage systems.
[0106] The processor 316 executes various functional applications and data processing by running the programs stored in the storage device 328, such as implementing the data caching method provided in the above embodiment of the present invention.
[0107] Example 6
[0108] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processing device, the data caching method described in the embodiment of the present invention is implemented. The computer-readable medium described above in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. The 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, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, 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 disclosure, a computer-readable signal medium may include a data signal transmitted in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take a variety of 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 send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0109] In some embodiments, the client and server can communicate using any currently known or future developed network protocol, such as HTTP (HyperText Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0110] The computer-readable medium may be included in the computer device, or may exist independently without being incorporated into the computer device.
[0111] The computer-readable medium carries one or more programs. When the one or more programs are executed by the computer device, the computer device: initializes the circular cache space according to the first memory threshold; and dynamically adjusts the memory space of the circular cache space according to the amount of stored data and / or read data.
[0112] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0113] 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 disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than 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 and / or flowchart, and the combination of the boxes in the block diagram and / 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.
[0114] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit does not necessarily limit the unit itself.
[0115] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0116] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0117] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A data caching method, characterized in that: The method comprises: Initialize the ring buffer space according to the first memory threshold; Dynamically adjust the memory space of the ring buffer space according to the amount of stored data and / or read data; The dynamically adjusting the memory space of the ring buffer space according to the amount of stored data and / or read data includes: Create a data receiving thread to obtain business data and determine the data volume of the business data; Determining whether a difference between the data amount and the remaining memory size of the memory space satisfies a storage increase threshold; If yes, storing the service data into the memory space according to the write pointer of the ring buffer space; If not, apply for memory space as the new ring cache space according to the sum of the first memory threshold and the storage increase threshold; migrate the storage data in the original ring cache space to the new ring cache space; write the business data into the new ring cache space, and update the remaining memory size; wherein, the storage increase threshold is determined according to the rollback space of the rollback operation of the ring cache space, and the rollback space is the minimum memory space required for the data security of the rollback operation.
2. The method according to claim 1, characterized in that Initializing the ring buffer space according to the first memory threshold includes: Applying for memory space as the ring buffer space according to the first memory threshold; Initializing a read pointer and a write pointer according to the starting address of the memory space; The first memory threshold is initialized to the remaining memory size of the ring buffer space.
3. The method according to claim 1, characterized in that The dynamically adjusting the memory space of the ring buffer space according to the amount of stored data and / or read data includes: Creating a data reading thread to read the business data in the ring buffer space and determine the data volume of the business data; When it is determined that the data amount meets the storage reduction threshold, the memory space of the ring buffer space is reduced.
4. The method according to claim 1 or 3, characterized in that Also includes: After increasing or decreasing the annular buffer space, the remaining memory size of the annular buffer space is updated.
5. A data cache device, characterized in that: The device comprises: An initialization module, configured to initialize the ring buffer space according to a first memory threshold; A dynamic adjustment module, configured to dynamically adjust the memory space of the ring buffer space according to the amount of stored data and / or read data; Wherein, the dynamic adjustment module includes: A data receiving unit, configured to create a data receiving thread to obtain business data and determine the amount of the business data; a memory determination unit, configured to determine whether a difference between the data amount and the remaining memory size of the memory space satisfies a storage increase threshold; a first storage processing unit, configured to, if yes, store the service data into the memory space according to the write pointer of the ring buffer space; The second storage processing unit is used to apply for memory space as the new ring cache space according to the sum of the first memory threshold and the storage increase threshold if not; migrate the storage data in the original ring cache space to the new ring cache space; write the business data into the new ring cache space, and update the remaining memory size; wherein, the storage increase threshold is determined according to the rollback space of the rollback operation of the ring cache space, and the rollback space is the minimum memory space required for the data security of the rollback operation.
6. An electronic device, characterized in that: The electronic device comprises: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method according to any one of claims 1 to 4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data caching method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Message processing method and system based on multiple circular caches
CN112148488A