Data reading method and device, terminal equipment and storage medium
By retrieving target data in the cache space and updating cached data based on the database storage location, the problem of large resource overhead in the prior art is solved, the effect of reducing the number of IO reads and memory usage is achieved, and the performance of the terminal device is improved.
Patent Information
- Application Number
- CN202310957519.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-31
- Publication Date
- 2025-02-14
AI Technical Summary
The prior art has excessive resource overhead when updating cached data, which affects the performance of terminal devices.
By retrieving the target data in the cache space, if not found, some or all of the data in the cache space are updated based on the storage location of the target data and the most adjacent data in the database, and the target data is returned. At the same time, the most adjacent data is read in advance to reduce the number of subsequent IO reads.
Reduces unnecessary IO read times and memory usage, saves performance overhead, and improves the performance performance of terminal devices.
Smart Images

Figure CN119441232A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of information processing technology, and in particular, relates to a data reading method, device, terminal equipment and storage medium. Background Art
[0002] With the rapid development of electronic technology, terminal devices have become an indispensable tool for learning, working and entertainment in life. The cache space of terminal devices is usually limited in capacity. The data stored in the database will be temporarily stored in the cache space according to the actual reading needs of the application, so that the application can quickly read the cached data in the cache space.
[0003] Currently, every time an application reads data, the cache space usually reads a batch of new cache data from the database and fully overwrites the cached data. Each time a piece of data is read and overwritten, an IO reading process is required and memory is occupied. Therefore, the larger the capacity of the cache space, the more IO readings are performed for a data call and the larger the memory usage, resulting in excessive resource overhead and affecting the performance of the terminal device. Therefore, how to reduce the resource overhead when updating cache data has become an urgent problem to be solved. Summary of the invention
[0004] In view of this, embodiments of the present application provide a data reading method, apparatus, terminal device, and storage medium to solve the problem of high resource overhead when updating cached data in existing data reading methods.
[0005] A first aspect of an embodiment of the present application provides a data reading method, the method comprising:
[0006] In response to a data read instruction, retrieving target data indicated by the data read instruction in a cache space;
[0007] If the target data is not retrieved in the cache space, based on the storage location of the target data in the database and the storage location of the most adjacent data in the database, a portion or all of the data in the cache space is updated, and the target data is returned to the initiator of the data read instruction;
[0008] The most adjacent data is data stored in the cache space and located closest to the target data in the database.
[0009] A first aspect of an embodiment of the present application provides a data reading method, by which, if target data is not retrieved in the cache space, part or all of the data in the cache space is updated based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, and the target data is returned to the initiator of the data reading instruction; by pre-reading the most adjacent data into the cache space when reading the target data, if the target data indicated by the next data reading instruction is the above-mentioned most adjacent data, the cache space can directly return the above-mentioned most adjacent data, and compared to fully covering the cached data each time the data is updated, by determining the amount of data for each data update according to actual needs, it is possible to reduce unnecessary IO read times and memory usage when updating data, thereby saving performance overhead.
[0010] The second aspect of an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the data reading method provided in the first aspect of the embodiment of the present application when executing the computer program.
[0011] A third aspect of an embodiment of the present application provides a data reading device, including:
[0012] A retrieval module, configured to retrieve target data indicated by the data read instruction in the cache space in response to the data read instruction;
[0013] An update read module, configured to update part or all of the data in the cache space based on the storage position of the target data in the database and the storage position of the most adjacent data in the database if the target data is not retrieved in the cache space, and return the target data to the initiator of the data read instruction;
[0014] The most adjacent data is data stored in the cache space and located closest to the target data in the database.
[0015] The fourth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the data reading method provided in the first aspect of the embodiments of the present application are implemented.
[0016] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0019] Figure 2 This is a schematic diagram of the architecture of an operating system running on a terminal device provided in an embodiment of the present application;
[0020] Figure 3 This is a schematic diagram of a first flow chart of a data reading method provided in an embodiment of the present application;
[0021] Figure 4 This is a second flow chart of the data reading method provided in the embodiment of the present application;
[0022] Figure 5 This is a schematic diagram of a first scenario of updating data in a cache space provided in an embodiment of the present application;
[0023] Figure 6 This is a schematic diagram of a second scenario of updating data in a cache space provided in an embodiment of the present application;
[0024] Figure 7 This is a schematic diagram of a third scenario of updating data in a cache space provided in an embodiment of the present application;
[0025] Figure 8 This is a schematic diagram of a fourth scenario of updating data in a cache space provided in an embodiment of the present application;
[0026] Fig. 9 This is a schematic diagram of a fifth scenario of updating data in a cache space provided in an embodiment of the present application;
[0027] Fig.10 It is a structural schematic diagram of a data reading device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0029] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0030] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0031] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0032] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0033] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0034] In an application, every time an application calls data, the cache space usually reads a batch of new cache data from the database and fully overwrites the cached data. Each time a piece of data is read and overwritten, an IO reading process is required and memory is occupied. Therefore, the larger the capacity of the cache space, the more IO readings are performed for each data call and the larger the memory usage, resulting in excessive resource overhead and affecting the performance of the terminal device. Therefore, how to reduce the resource overhead when updating cache data has become an urgent problem to be solved.
[0035] In response to the above technical problems, an embodiment of the present application provides a data reading method. If the target data is not retrieved in the cache space, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, part or all of the data in the cache space is updated, and the target data is returned to the initiator of the data reading instruction; by pre-reading the most adjacent data to the cache space when reading the target data, if the target data indicated by the next data reading instruction is the above-mentioned most adjacent data, the cache space can directly return the above-mentioned most adjacent data, and compared with fully covering the cached data each time the data is updated, by determining the amount of data for each data update according to actual needs, it is possible to reduce unnecessary IO read times and memory usage when updating data, thereby saving performance overhead.
[0036] The data reading method provided in the embodiment of the present application can be applied to a terminal device. The terminal device can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc. The embodiment of the present application does not impose any restrictions on the specific type of the terminal device.
[0037] Figure 1 The schematic diagram of the structure of the terminal device 1 is shown as an example. The terminal device 1 includes a processor 10, a memory 20, an audio module 30, a camera module 40, a sensor module 50, an input module 60, a display module 70, a wireless communication module 80, and a power module 90. The audio module 30 may include a speaker 31 and a microphone 32, the camera module 40 may include a short-focus camera 41, a long-focus camera 42, and a flash 43, the sensor module 50 may include an infrared sensor 51, an acceleration sensor 52, a position sensor 53, a fingerprint sensor 54, and an iris sensor 55, the input module 60 may include a touch panel 61 and an external input unit 62, and the wireless communication module 80 may include wireless communication units such as Bluetooth, optical wireless communication (Optical Wireless), mobile communication (Mobile Communications), wireless local area network (Wireless Local Area Network, WLAN), near field communication (Near Field Communication, NFC) and ZigBee protocol (ZigBee).
[0038] In applications, the processor 10 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0039] In application, the memory 20 may be an internal storage unit of the terminal device in some embodiments, such as a hard disk or memory of the terminal device. The memory 20 may also be an external storage device of the terminal device in other embodiments, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the terminal device. Further, the memory 20 may also include both an internal storage unit of the terminal device and an external storage device. The memory 20 is used to store computer programs 21 such as an operating system, an application program, and a boot loader (BootLoader). The memory 20 may also be used to temporarily store data that has been output or is to be output.
[0040] In application, the display module 70 can be a flat screen, a curved screen or a flexible screen, specifically a folding screen. The folding screen may include at least one flexible screen, or the folding screen may include at least one flexible screen and at least one flat screen or curved screen. The embodiment of the present application does not impose any restrictions on the specific type of the display module 70.
[0041] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the terminal device 1. In other embodiments of the present application, the terminal device 1 may include more or fewer components than those illustrated, or may combine certain components, or different components, such as a graphics processor, etc. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0042] like Figure 2As shown, the architecture diagram of the operating system running on the terminal device 1 provided in the embodiment of the present application, the layered architecture can divide the operating system into multiple layers, and the layers communicate with each other through software interfaces. In some embodiments, the operating system can be divided from top to bottom into an application layer 100, a framework layer 200, a system runtime layer 300, a hardware abstraction layer 400, and a Linux kernel layer 500.
[0043] It should be noted that the type of the operating system may be an Android system, an operating system customized based on the Android system, or other different types of operating systems. The embodiments of the present application do not impose any limitation on the specific type of the operating system.
[0044] In the application, the five layers of the operating system are introduced as follows:
[0045] The application layer 100 may include built-in applications 120 built into the system and upper layer applications 110 provided by third-party application providers. The application programs of the application layer 100 may interact directly with users to implement different functions provided by the application programs. For example, the application layer 100 may specifically include built-in applications such as email, phone, calendar, camera, contacts, and Bluetooth, and upper layer applications such as map positioning, food delivery, and video playback.
[0046] The framework layer (ApplicationFramwork) 200 may include an application programming interface (API) and a programming framework. The application programming interface may be used to provide an interface for operating system developers to develop applications, and may also be used to call corresponding basic services for applications in the application layer when implementing different functions. For example, the framework layer may include different types of application programming interfaces such as window managers, content providers, phone managers, positioning managers, and view systems.
[0047] The window manager is used to manage window programs. Specifically, it can be used to obtain the window size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0048] Content providers are used to store and retrieve data and make the data accessible to applications. The data may include videos, images, audio, call logs, contacts, browsing history, and bookmarks.
[0049] The phone manager is used to provide communication functions of the terminal device 1, such as management of call status, including answering and hanging up calls, etc.;
[0050] The positioning manager is used to obtain the location information of the terminal device 1, which may include different types of location information such as satellite location information (obtained through the global positioning system), network location information (obtained through a network positioning service), and fused location information (obtained through a fused positioning service);
[0051] The view system is used to provide visual controls, such as controls for displaying text and controls for displaying pictures, and is also used to build applications for displaying the application layer 100. The view system can run multiple visual controls at the same time, so that the terminal device can display multiple views at the same time, for example, a view that displays text and a view that displays pictures at the same time.
[0052] The system runtime layer (Native) 300 may include a C / C++ library 310 and an Android runtime library 320, wherein the C / C++ library 310 may include a drawing function library, a font engine, a rendering engine, a multimedia library, and a database engine, etc. The drawing function library may be OpenGL For Embedded Systems 3D (a 3D open graphics library running on embedded systems); the font engine is used to provide different fonts, and may be FreeType (a portable font engine); the rendering engine is used to render two-dimensional graphics or three-dimensional graphics, and may be Skia Graphics Library (an engine for rendering two-dimensional graphics); the multimedia library (Media Framework) is used to support the playback, recording, and playback of audio and video in different formats; the database engine is used to provide storage functions for different types of databases, so that different types of data can be stored in different types of databases according to actual needs, or different types of data can be stored in a unified database.
[0053] The Android runtime 320 may include core libraries (Core Libraries) and an Android runtime environment (Android Runtime, ART), wherein after the Android 5.0 system, the Dalvik virtual machine is replaced by ART. The core library provides most of the functions of the Java language core library, so that developers can use the Java language to write Android applications. Compared with the Java Virtual Machine (Java Virtual Machine, JVM), the Dalvik virtual machine is specially customized for mobile devices, allowing multiple virtual machine instances to run simultaneously in limited memory, and each Dalvik application is executed as an independent Linux process. Independent processes can prevent all programs from being closed when the virtual machine crashes. The mechanism of ART, which replaces the Dalvik virtual machine, is different from Dalvik. Under Dalvik, every time an application runs, the bytecode needs to be converted into machine code by a just-in-time compiler, which slows down the running efficiency of the application. In the ART environment, when the application is installed for the first time, the bytecode will be pre-compiled into machine code, making it a truly local application.
[0054] The Hardware Abstraction Layer (HAL) 400 is an interface layer between the operating system kernel and the hardware circuit. Its purpose is to abstract the hardware. In order to protect the intellectual property rights of hardware manufacturers, it hides the hardware interface details of a specific platform, thereby providing a virtual hardware platform for the operating system, making it hardware-independent and portable on multiple platforms. From the perspective of software and hardware testing, the testing of software and hardware can be completed based on the hardware abstraction layer, so that the testing of software and hardware can be carried out in parallel.
[0055] The Linux kernel layer 500 can be used to provide system services of the operating system, including security services, memory management, process management, network protocol stack, driver model and other services of the operating system.
[0056] It should be noted that the computer-readable storage medium corresponding to the data reading method provided in the embodiment of the present application can be stored in the memory of the terminal device, and generate a first interface layer and a second interface layer based on the framework layer during operation. The first interface layer is connected to the logic implementation layer (which can be generated based on the framework layer, the system runtime layer or the Linux kernel layer), and the second interface layer is respectively connected to the logic implementation layer and at least one database.
[0057] In the application, the first interface layer is used to provide the terminal device with calling instructions for running the data reading method, and the calling instructions include but are not limited to: creation instructions, used to create a data reading device in the terminal device; forward retrieval instructions, used to read the next data in the cache; backward retrieval instructions, used to read the previous instruction in the cache; positioning retrieval instructions, used to read the indicated target data.
[0058] In the application, the logic implementation layer is used to respond to the call instruction received by the first interface layer, retrieve and return the target data in the cache or database.
[0059] In the application, the second interface layer is used to connect to at least one database and is compatible with different types of databases, such as SQL (Structured Query Language) databases and kv (Key-Value) databases; the second interface layer is also used to respond to retrieval requests from the logic implementation layer, and can be retrieved based on the memory size of the target data or based on the database serial number of the target data.
[0060] Understandably, Figure 2 The architecture diagram of an operating system is only shown by way of example. The operating system architecture can also be four-layer or six-layer, wherein the architecture of a four-layer operating system may include: an application layer, a framework layer, a system runtime layer and a Linux kernel layer; the architecture of a six-layer operating system may include: an application layer, a framework layer, a system runtime layer, a hardware abstraction layer, a Linux kernel layer and a hardware device layer. The embodiment of the method of the present application does not impose any limitation on the number of architecture layers and the specific architecture of the operating system.
[0061] like Figure 3 As shown, the data reading method provided in the embodiment of the present application includes the following steps S301 and S302:
[0062] Step S301 : In response to a data read instruction, the target data indicated by the data read instruction is retrieved in the cache space.
[0063] In the application, the initiator of the data read instruction may include any application in the application layer or any service in the framework layer. The terminal device can read data from the database and temporarily store the corresponding data in the cache space so that the user, any application or any service can quickly call it, saving the process of reading data in the database. The cache space (Cache) can include multiple data, and the number of data that the cache space can contain is determined by the storage capacity of the cache space and the size of each data. For example, assuming that the storage capacity of the cache space is 12 megabytes (MByte), if the size of each data is 1 megabyte, the cache space can contain 12 data.
[0064] In the application, after listening to the data read instruction, the terminal device can send the data read instruction to the cache space, so that the cache space can retrieve the corresponding target data according to the data read instruction. If the target data is retrieved in the cache space, it means that the cache space already contains the target data, and there is no need to read the target data from the database. The target data can be returned directly to the initiator of the data read instruction; if the target data is not retrieved in the cache space, it means that the cache space does not contain the target data, and it can be read from the database to the cache space. The specific reading method can refer to the relevant description in the following step S302.
[0065] Step S302: If the target data is not retrieved in the cache space, based on the storage location of the target data in the database and the storage location of the most adjacent data in the database, update part or all of the data in the cache space, and return the target data to the initiator of the data read instruction.
[0066] The most adjacent data is the data stored in the cache space and located closest to the target data in the database.
[0067] In the application, if the target data is not retrieved in the cache space, the target data can be read from the database to the cache space, or the target data and the most adjacent data can be read from the cache space. Specifically, the terminal device can determine the storage location of the target data in the database, and determine the most adjacent data according to the storage location of the target data in the database. The most adjacent data is the data stored in the cache space that is closest to the location of the target data in the database. For example, if the storage location of the target data in the database is the 5th data, then the corresponding most adjacent data may include the 4th and 6th data of the corresponding database, or the 3rd, 4th, 6th and 7th data of the corresponding database, or the 2nd, 3rd, 4th and 6th data of the corresponding database. The embodiment of the present application does not impose any restrictions on the number of most adjacent data.
[0068] It should be noted that in the database and cache space, all data are sorted according to the storage position in the database, specifically, they may be sorted in positive order, that is, the data stored in the cache space is a continuous section of data in the database.
[0069] In an application, when updating data in a cache space, by pre-reading the most adjacent data into the cache space, the cache space after the data update can contain not only the target data but also the most adjacent data of the target data, so that after the initiator of the data read instruction receives the target data, if the target data indicated by the next data read instruction is the above-mentioned most adjacent data, the cache space can directly return the above-mentioned most adjacent data without having to read the data from the database again, thereby reducing the number of IO reads and reducing memory usage.
[0070] In the application, the terminal device can configure the amount of data in the cache space each time the data is updated, so as to determine whether to update part of the data or all of the data. Specifically, the amount of data can be determined based on the difference between the storage location of the target data in the database and the storage location of the cached data in the database. The amount of data when the data is updated can also be pre-set, so that when updating the data, the amount of data can be determined according to actual needs, avoiding full overwriting of the cached data each time the data is updated, further reducing the number of IO reads and reducing memory usage.
[0071] like Figure 4 As shown, in one embodiment, based on Figure 3 The corresponding embodiment includes the following steps S401 to S405:
[0072] Step S401 : In response to a data read instruction, the target data indicated by the data read instruction is retrieved in the cache space.
[0073] In the application, the data reading method provided in step S401 can refer to the relevant description in the above step S301, which will not be repeated here.
[0074] Step S402: If the target data is not retrieved in the cache space, determine the minimum sequence number difference between the first cache data and the target data based on the database sequence number of the first cache data and the database sequence number of the target data; the first cache data is stored in the cache space, and the database sequence number is used to determine the storage location of the corresponding data in the database.
[0075] In the application, if the target data is not retrieved in the search space, it is necessary to read the target data from the database to the cache space. The minimum sequence number difference between the first cache data (the current data set stored in the cache space, including multiple cached data) and the target data can be determined first. Specifically, the absolute value of the difference between the database sequence number of each cached data in the first cache data and the database sequence number of the target database can be obtained, and the minimum absolute value is recorded as the minimum sequence number difference. The distance interval between the storage location of the first cache data and the target data in the database is determined, and the number of data to be updated in the cache space is determined based on the above distance interval. The method for determining the number of data is described in the following steps S403 and S404.
[0076] Step S403: If the minimum sequence number difference is less than the preset sequence number difference, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, part or all of the data in the cache space is updated to obtain second cache data; wherein the size of the preset sequence number difference is determined according to the storage capacity of the cache space, and the number of data updated in the cache space is not less than the minimum sequence number difference.
[0077] In the application, if the minimum sequence number difference is less than the preset sequence number difference, the cache space can update part of the data, thereby retaining part of the cached data to obtain the second cached data; or all of the data can be updated to fully cover the cached data to obtain the second cached data. It should be noted that if the cache space updates part of the data, the amount of data should not be less than the minimum sequence number difference to ensure that the target data can be updated to the cache space.
[0078] For example, assuming that the database sequence number of the first cache data is 5 to 10, and the database sequence number of the target data is 12, the minimum sequence number difference is 2. It is easy to understand that the direction of the cache space when updating data is the direction of the target data. If the number of data updated in the cache space is 2, the database sequence number of the second cache data obtained after the update is 7 to 12, which can just contain the target data; if the data update amount is 3, the database sequence number of the second cache data obtained after the update is 8 to 13; if the data update amount is 5, the database sequence number of the second cache data obtained after the update is 10 to 15; if the data update amount is 7, the database sequence number obtained after the update is 12 to 17, and all data in the cache space is updated.
[0079] In one embodiment, step S403 further includes:
[0080] When updating data in the cache space, if the minimum sequence number difference between the target data and the first cache data is not less than 2, the most adjacent data includes at least one data with a database sequence number greater than the database sequence number of the target data and at least one data with a database sequence number less than the database sequence number of the target data.
[0081] In the application, the most adjacent data can simultaneously include at least one forward data of the target data (the database sequence number is greater than the target data) and at least one backward data (the database sequence number is less than the target data), which can be suitable for the application scenario when the initiator of the data reading instruction repeatedly reads the local adjacent data, thereby reducing unnecessary IO read times and reducing memory usage.
[0082] Figure 5 The first scenario schematic diagram of updating data in the cache space is exemplarily shown.
[0083] In one embodiment, step S403 further includes:
[0084] When updating data in the cache space, the database serial number of the target data is the median of the database serial numbers in the second cache data; the second cache data is the data stored after the cache space is updated.
[0085] In applications, the cache space can evenly accommodate the forward data and backward data of the target data, further meeting the application scenario where the initiator of the data read instruction repeatedly reads local adjacent data, thereby reducing unnecessary IO read times and reducing memory usage.
[0086] Figure 6 A schematic diagram of a second scenario of updating data in the cache space is exemplarily shown.
[0087] In one embodiment, step S403 includes:
[0088] If the minimum sequence number difference is 1 and the database sequence number of the target data is greater than the database sequence numbers of all first cached data, all data in the cache space are updated based on the storage position of the target data in the database and the storage position of the most adjacent data in the database to obtain second cached data; the database sequence number of the target data is the smallest in the second cached data.
[0089] In the application, if the minimum sequence number difference is 1 and the database sequence number of the target data is greater than the database sequence numbers of all the first cached data, it means that the target data is adjacent to the cached data with the largest database sequence number in the first cached data (refer to Figure 7As shown), based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, all the data in the cache space can be updated to obtain the second cache data. Since the first cache data are all backward data of the target data, by making the second cache data other than the target data all forward data of the target data, the storage capacity of the cache space can be fully utilized while avoiding overlap with the first cache data, which is suitable for the use scenario where the initiator of the data read instruction only performs forward retrieval, thereby reducing unnecessary IO read times and reducing memory usage.
[0090] Figure 7 The third scenario schematic diagram of updating data in the cache space is exemplarily shown.
[0091] In one embodiment, step S403 includes:
[0092] If the minimum sequence number difference is 1 and the database sequence number of the target data is smaller than the database sequence numbers of all first cached data, all data in the cache space are updated based on the storage position of the target data in the database and the storage position of the most adjacent data in the database to obtain second cached data; the database sequence number of the target data is the largest in the second cached data.
[0093] In the application, if the minimum sequence number difference is 1 and the database sequence number of the target data is smaller than the database sequence numbers of all the first cached data, the data update method can refer to the above data update method where the minimum sequence number difference is 1 and the database sequence number of the target data is larger than the database sequence numbers of all the first cached data. The difference is that the target data is adjacent to the cached data with the smallest database sequence number in the first cached data (refer to Figure 8 As shown), the data in the second cache data except the target data are all backward data of the target data.
[0094] Figure 8 The fourth scenario schematic diagram of updating data in the cache space is exemplarily shown.
[0095] Step S404: If the minimum sequence number difference is not less than the preset sequence number difference, all data in the cache space are updated based on the storage position of the target data in the database and the storage position of the most adjacent data in the database to obtain second cache data.
[0096] In the application, if the minimum sequence number difference is less than the preset sequence number difference, if the cache space updates part of the data, the target data cannot be updated to the cache space, so all the data in the cache space needs to be updated. The target data can be located at any position in the second cache data. Specifically, the target data can have the smallest database sequence number in the second cache data, or the largest database sequence number in the second cache data, or the database sequence number of the target data can be the median of the database sequence numbers in the second cache data (refer to Fig. 9 As shown), the embodiment of the present application does not impose any restriction on the location of the target data in the second cache data.
[0097] Fig. 9 The fifth scenario schematic diagram of updating data in the cache space is exemplarily shown.
[0098] Step S405: Return the target data to the initiator of the data read instruction.
[0099] In the application, by obtaining the distance interval between the storage location of the first cache data and the target data in the database, and determining the amount of data to be updated in the cache space based on the above distance interval, it is possible to match the storage situation of the cache space and the actual needs of the initiator of the data reading instruction, reduce unnecessary IO read times and reduce memory usage, and further save performance overhead.
[0100] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0101] like Fig.10 As shown, the embodiment of the present application also provides a data reading device for executing the steps in the above data reading method embodiment. The data reading device can be a virtual appliance in a terminal device, which is run by a processor of the terminal device, or it can be the terminal device itself.
[0102] like Fig.10 As shown, the data reading device 2 provided in the embodiment of the present application includes:
[0103] A retrieval module 210, configured to retrieve target data indicated by the data read instruction in the cache space in response to the data read instruction;
[0104] An update read module 220, for updating part or all of the data in the cache space based on the storage location of the target data in the database and the storage location of the most adjacent data in the database if the target data is not retrieved in the cache space, and returning the target data to the initiator of the data read instruction;
[0105] The most adjacent data is the data stored in the cache space and located closest to the target data in the database.
[0106] In one embodiment, the update reading module 220 includes:
[0107] a position determination unit, configured to determine a minimum sequence number difference between the first cache data and the target data based on a database sequence number of the first cache data and a database sequence number of the target data; the first cache data is stored in the cache space, and the database sequence number is used to determine a storage position of the corresponding data in the database;
[0108] A first reading unit is used to update part or all of the data in the cache space based on the storage position of the target data in the database and the storage position of the most adjacent data in the database to obtain second cache data if the minimum sequence number difference is less than the preset sequence number difference;
[0109] A second reading unit is used to update all data in the cache space based on the storage position of the target data in the database and the storage position of the most adjacent data in the database to obtain second cache data if the minimum sequence number difference is not less than the preset sequence number difference;
[0110] The size of the preset sequence number difference is determined according to the storage capacity of the cache space, and the amount of data updated in the cache space is not less than the minimum sequence number difference.
[0111] In application, each module in the data reading device 2 may be a software program module, or may be implemented by different logic circuits integrated in a processor, or may be implemented by multiple distributed processors.
[0112] It should be noted that the information interaction, execution process and other contents between the above-mentioned modules are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0113] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned function allocation can be completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The functional modules in the embodiment can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software functional modules. In addition, the specific names of the functional modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0114] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned various data reading method embodiments can be implemented.
[0115] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may at least include: any entity or device that can carry the computer program code to the camera terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.
[0116] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0117] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0118] In the embodiments provided in the present application, it should be understood that the disclosed terminal device and method can be implemented in other ways. For example, the terminal device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0119] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A data reading method, characterized in that: The method comprises: In response to a data read instruction, retrieving target data indicated by the data read instruction in a cache space; If the target data is not retrieved in the cache space, based on the storage location of the target data in the database and the storage location of the most adjacent data in the database, a portion or all of the data in the cache space is updated, and the target data is returned to the initiator of the data read instruction; The most adjacent data is data stored in the cache space and located closest to the target data in the database.
2. The data reading method according to claim 1, characterized in that: The updating of part or all of the data in the cache space based on the storage location of the target data in the database and the storage location of the most adjacent data in the database includes: Determine the minimum sequence number difference between the first cache data and the target data based on the database sequence number of the first cache data and the database sequence number of the target data; the first cache data is stored in the cache space, and the database sequence number is used to determine the storage location of the corresponding data in the database; If the minimum sequence number difference is less than the preset sequence number difference, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, a part of the data or all of the data in the cache space is updated to obtain second cache data; The size of the preset sequence number difference is determined according to the storage capacity of the cache space, and the amount of data updated in the cache space is not less than the minimum sequence number difference.
3. The data reading method according to claim 2, characterized in that: The preset sequence number difference is greater than 1; if the minimum sequence number difference is less than the preset sequence number difference, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, part of the data or all of the data in the cache space is updated to obtain the second cache data, including: If the minimum sequence number difference is 1 and the database sequence number of the target data is greater than the database sequence numbers of all first cache data, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, all data in the cache space are updated to obtain second cache data; the database sequence number of the target data is the smallest in the second cache data.
4. The data reading method according to claim 2, characterized in that: The preset sequence number difference is greater than 1; if the minimum sequence number difference is less than the preset sequence number difference, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, part of the data or all of the data in the cache space is updated to obtain the second cache data, including: If the minimum sequence number difference is 1 and the database sequence number of the target data is smaller than the database sequence numbers of all first cache data, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, all data in the cache space are updated to obtain second cache data; the database sequence number of the target data is the largest in the second cache data.
5. The data reading method according to claim 1, characterized in that: The updating of part or all of the data in the cache space based on the storage location of the target data in the database and the storage location of the most adjacent data in the database includes: Determine the minimum sequence number difference between the first cache data and the target data based on the database sequence number of the first cache data and the database sequence number of the target data; the first cache data is stored in the cache space, and the database sequence number is used to determine the storage location of the corresponding data in the database; If the minimum sequence number difference is not less than the preset sequence number difference, based on the storage position of the target data in the database and the storage position of the most adjacent data in the database, all data in the cache space are updated to obtain second cache data; The size of the preset sequence number difference is determined according to the storage capacity of the cache space.
6. The data reading method according to any one of claims 1 to 5, characterized in that: When updating data in the cache space, if the minimum sequence number difference between the target data and the first cache data is not less than 2, the most adjacent data includes at least one data with a database sequence number greater than the database sequence number of the target data and at least one data with a database sequence number less than the database sequence number of the target data; The first cache data is stored in the cache space, and the database serial number is used to determine the storage location of the corresponding data in the database.
7. The data reading method according to claim 6, characterized in that: When the cache space is updated, the database serial number of the target data is the median of the database serial numbers in the second cache data; the second cache data is the data stored after the cache space is updated.
8. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the data reading method according to any one of claims 1 to 7 are implemented.
9. A data reading device, characterized in that: include: A retrieval module, configured to retrieve target data indicated by the data read instruction in the cache space in response to the data read instruction; an update read module, configured to update part or all of the data in the cache space based on the storage position of the target data in the database and the storage position of the most adjacent data in the database if the target data is not retrieved in the cache space, and return the target data to the initiator of the data read instruction; The most adjacent data is data stored in the cache space and located closest to the target data in the database.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the data reading method according to any one of claims 1 to 7 are implemented.