Data statistics method, device, terminal and storage medium based on multi-level cache

Through multi-level caching technology, message data is stored hierarchically in the database and memory according to the data type, and processed in batches. This solves the storage space occupation and data loss problems caused by the data statistics architecture in the existing technology, and improves the performance of data statistics.

CN111723115BActive Publication Date: 2024-09-20WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010589637.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-24
Publication Date
2024-09-20
Estimated Expiration
2040-06-24

AI Technical Summary

Technical Problem

The existing data statistics architecture cannot send messages in time when the message construction speed is too fast, resulting in excessive terminal storage space usage or data loss, affecting terminal operation and data statistics performance.

Method used

Multi-level caching technology is adopted to determine the cache level according to the type attributes of message data. Important data is stored in the database cache and non-important data is stored in the memory cache. When conditions are met, batch uploading and deletion are performed to avoid long-term occupation of data. Terminal storage.

Benefits of technology

It effectively reduces the loss rate of important data, improves data upload efficiency, avoids excessive occupation of terminal storage space, and ensures terminal operating performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111723115B
    Figure CN111723115B
Patent Text Reader

Abstract

The present invention relates to the field of financial technology, and discloses a data statistics method, device, terminal equipment and computer storage medium based on multi-level cache. The data statistics method based on multi-level cache constructs message data according to the collected key data and the data type of the key data; detects the type attribute of the message data, and determines the cache level corresponding to the message data based on the type attribute; adds the message data to the corresponding storage space for caching according to the cache level; and batch uploads and deletes the message data in the storage space. The present invention can realize multi-level caching for message data, effectively reducing the data loss rate. In addition, the present invention integrates and uploads message data in batches in the storage space of different cache levels, improves the data upload efficiency, and avoids the large amount and long-term occupation of the terminal memory by data, ensuring the terminal operation performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a data statistics method, device, terminal equipment and computer storage medium based on multi-level cache. Background Art

[0002] With the development of computer technology, more and more technologies are being applied in the financial field. The traditional financial industry is gradually transforming into financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology.

[0003] like Figure 5 As shown, the existing data statistics architecture can usually be composed of three parts: data collection module, data formatting and integration module, and data sending module. Among them, the data collection module is the API (Application Interface) provided by the data statistics SDK (Software Development Kit). After the developer performs business embedding in the APP (Application), when the user operates the APP, the data statistics API will be triggered to construct a message-Message. Then, the constructed message-Message is integrated and processed by the data formatting module. Finally, the integrated message-Message is sent to the background server through the data sending module.

[0004] However, in actual application scenarios, since the message construction is generated too quickly, data transmission cannot be completed in time, so that the message seriously occupies the terminal storage space or causes data loss, thus affecting the operation of the terminal system and the performance of data statistics. Summary of the invention

[0005] The main purpose of the present invention is to provide a data statistics method, device, terminal equipment and computer storage medium based on multi-level cache, aiming to solve the technical problem that the existing data statistics architecture will cause terminal storage space and data loss, seriously affecting terminal operation and data statistics performance indicators.

[0006] To achieve the above object, the present invention provides a data statistics method based on multi-level cache, and the data statistics method based on multi-level cache includes:

[0007] Constructing message data according to the collected key data and the data type of the key data;

[0008] Detecting a type attribute of the message data, and determining a cache level corresponding to the message data based on the type attribute;

[0009] Adding the message data to the corresponding storage space for caching according to the cache level;

[0010] The message data is uploaded and deleted in batches in the storage space.

[0011] Optionally, before the step of constructing message data according to the collected key data and the data type of the key data, the method further includes:

[0012] Collect key data and data types of the key data based on a preset application program interface;

[0013] Alternatively, key data is collected based on preset data burying points and the importance of the preset data burying points is detected, and the data type of the key data is determined according to the importance.

[0014] Optionally, the data types include: important types, general types and non-essential types.

[0015] The step of constructing message data according to the collected key data and the data type of the key data comprises:

[0016] The key data is assembled and combined with the important type, the general type or the non-essential type to construct message data whose type attribute is an important message, a general message or a non-essential message.

[0017] Optionally, the cache level includes: memory cache and database cache,

[0018] The step of detecting the type attribute of the message data and determining the cache level corresponding to the message data based on the type attribute includes:

[0019] Detecting whether the type attribute of the message data is an important message, a general message, or a non-essential message;

[0020] If it is detected that the type attribute is an important message, determining that the cache level corresponding to the message data is a database cache;

[0021] If it is detected that the type attribute is a general message or a non-essential message, it is determined that the cache level corresponding to the message data is a memory cache.

[0022] Optionally, the step of adding the message data to a corresponding storage space for caching according to the cache level includes:

[0023] If it is detected that the cache level of the message data is database cache, an important message upload task is generated based on the message data;

[0024] Execute the important message uploading task to store the message data in a database and update the amount of message data in the database;

[0025] Alternatively, if it is detected that the cache level of the message data is a memory cache, the message data is added to a corresponding cache queue and the amount of message data in the memory is updated.

[0026] Optionally, the message data volume in the memory includes: general message data volume,

[0027] After the step of adding the message data to the corresponding cache queue and updating the amount of message data in the memory, the method further includes:

[0028] When it is detected that the amount of the general message data exceeds a preset batch data assembly threshold, extracting common parameters of the message data whose type attribute is a general message;

[0029] Formatting the common parameters into a message group, and generating an important message upload task based on the message group;

[0030] Executing the important message uploading task stores the message group in a database and updates the data volume of the message group in the database.

[0031] Optionally, the step of uploading and deleting the message data in batches in the storage space includes:

[0032] respectively reading target message data in the storage space corresponding to the message data, wherein the number of the target message data is greater than or equal to one;

[0033] The target message data is packaged and encapsulated and then synchronously uploaded to a preset background interface, and the target message data in the storage space is deleted after the upload is successful.

[0034] In addition, to achieve the above-mentioned purpose, the present invention further provides a data statistics device based on a multi-level cache, the data statistics device based on a multi-level cache comprising:

[0035] A construction module, used to construct message data according to the collected key data and the data type of the key data;

[0036] A determination module, configured to detect a type attribute of the message data, and determine a cache level corresponding to the message data based on the type attribute;

[0037] A cache module, used for adding the message data to a corresponding storage space for caching according to the cache level;

[0038] The uploading module is used to upload and delete the message data in batches in the storage space.

[0039] In addition, to achieve the above-mentioned purpose, the present invention also provides a terminal device, which includes: a memory, a processor, and a multi-level cache-based data statistics program stored in the memory and executable on the processor, and the multi-level cache-based data statistics program, when executed by the processor, implements the steps of the multi-level cache-based data statistics method as described above.

[0040] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a data statistics program based on a multi-level cache is stored. When the data statistics program based on a multi-level cache is executed by a processor, the steps of the data statistics method based on a multi-level cache as described above are implemented.

[0041] The present invention provides a data statistics method, device, terminal equipment and computer storage medium based on multi-level cache, which construct message data according to collected key data and the data type of the key data; detect the type attribute of the message data, and determine the cache level corresponding to the message data based on the type attribute; add the message data to the corresponding storage space for caching according to the cache level; and upload and delete the message data in batches in the storage space.

[0042] The present invention obtains message data of different levels based on the type of data, then determines the cache level of the message data based on the type attributes of the message data of different levels, and stores the message data in the storage space of the corresponding level according to the determined cache level, thereby realizing multi-level caching for the message data, so that important data is preferentially stored in the storage space with a high cache level instead of being sent directly, thereby effectively reducing the loss rate of important data. In addition, the present invention integrates and uploads the message data in batches in the storage space of different cache levels for statistics, thereby improving the data upload efficiency, and avoiding the large amount and long-term occupation of the terminal memory by data, thereby ensuring the terminal operation performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 A schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;

[0044] Figure 2 It is a flow chart of a first embodiment of a data statistics method based on multi-level cache according to the present invention;

[0045] Figure 3 A schematic diagram of an application scenario involved in an embodiment of a data statistics method based on a multi-level cache of the present invention;

[0046] Figure 4 (a) and Figure 4 (b) are schematic diagrams of another application scenario involved in an embodiment of a data statistics method based on a multi-level cache according to the present invention;

[0047] Figure 5 A schematic diagram of the existing data statistics architecture described in the background technology of the data statistics method based on multi-level cache of the present invention;

[0048] Figure 6 It is a schematic diagram of functional modules of an embodiment of a data statistics device based on multi-level cache of the present invention.

[0049] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0051] Reference Figure 1 , Figure 1 The figure is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.

[0052] The terminal device in the embodiment of the present invention may be a smart phone, or may be a PC (Personal Computer), a tablet computer, a portable computer or other terminal device.

[0053] like Figure 1 As shown, the terminal device may include: a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory, or it may be a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may optionally be a storage device independent of the aforementioned processor 1001.

[0054] Those skilled in the art will understand that Figure 1 The terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0055] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a data statistics program based on a multi-level cache.

[0056] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client and communicate data with the client; and the processor 1001 can be used to call the data statistics program based on multi-level cache stored in the memory 1005, and perform the following operations based on the multi-level cache data statistics method.

[0057] Based on the above hardware structure, various embodiments of the data statistics method based on multi-level cache of the present invention are proposed.

[0058] It should be noted that in the prior art, the most common data statistics architecture is as follows: Figure 5 As shown in the figure, most of them are composed of three parts: data collection module, data formatting and integration module, and data sending module. Among them, the data collection module is the API provided by the data statistics SDK. After the developer performs business embedding in the APP, the data statistics API will be triggered when the terminal user operates the APP. At this time, the message-Message is constructed, and then the constructed message-Message generally needs to be processed by the data formatting module for different data. Finally, the data sending module will send the message-Message to the background server. However, in actual application scenarios, the message `Message` may be generated too quickly, and the network transmission is slow. If it is not processed, it may cause serious problems (such as the terminal crashes or important data is lost due to a large amount of memory or long-term occupancy). In addition, in the stage of reporting data on the network, if there is no good framework (data statistics framework) support, it will also affect the consumption of data (data upload to the background server), which will ultimately affect the various performance indicators of the data statistics function (data loss rate and real-time data synchronization upload).

[0059] In view of the above phenomenon, the present invention provides a data statistics method based on multi-level cache. Figure 2 , Figure 2 It is a flowchart of the first embodiment of the data statistics method based on multi-level cache of the present invention.

[0060] In this embodiment, the data statistics method based on multi-level cache includes:

[0061] Step S10, constructing message data according to the collected key data and the data type of the key data;

[0062] In an embodiment of the present invention, a new data statistics architecture is designed. After the terminal device collects key data and the data type of the key data through the data collection module of the data statistics architecture, the key data and the data type are combined to construct message data with different types of attributes.

[0063] Furthermore, in a feasible embodiment, before step S10, the data statistics method based on multi-level cache of the present invention may further include:

[0064] Step A, collecting key data and data types of the key data based on a preset application program interface;

[0065] The terminal device receives the key data passed in by the caller through the preset application program interface reserved on the data statistics architecture, and determines the data type of the key data.

[0066] It should be noted that, in this embodiment, the data type of key data includes but is not limited to: important type, general type and non-essential type.

[0067] Specifically, for example, in Figure 3 In the application scenario shown, the terminal device receives the key data passed in by the caller through the SDK API exposed by the data statistics framework-SDK through the API, as well as the data type (important type, general type and non-essential type) passed in at the same time as the key data.

[0068] It should be noted that, in this embodiment, the structure of the entire data statistics framework-SDK is as follows Figure 3 As shown, the structure can be divided into basic SDK API, data generation, data encapsulation and memory cache, database cache, and data network reporting from top to bottom. In the entire SDK architecture, the key data (also called valid data) that needs to be counted is defined as Payload, and then the Payload data is combined with other non-key data generated inside the SDK to construct message data (Message is used in this article to represent message data). In the memory cache layer of the SDK architecture, the memory cache manager used is defined as CacheManager, and in the database cache layer of the SDK architecture, the database cache manager is defined as DBManager. Finally, in the data network reporting layer of the SDK architecture, the manager who executes the data reporting service is defined as UploadManager.

[0069] Furthermore, in another feasible embodiment, before step S10, the data statistics method based on multi-level cache of the present invention may further include:

[0070] Step B, collecting key data based on preset data embedding points and detecting the importance of the preset data embedding points, and determining the data type of the key data according to the importance.

[0071] It should be noted that, in this embodiment, the preset data embedding points are pre-set by the developer of the terminal software application APP for collecting user behavior data, and when setting the preset data embedding points, the developer will define the importance of each preset data embedding point based on the necessity of collecting user behavior data: important embedding points, general embedding points or non-essential embedding points.

[0072] Specifically, for example, the terminal device receives the key data (user behavior data) collected by one or more data embedding points pre-set by the developer of the APP when the terminal user uses the APP through the SDK API exposed by the data statistics architecture-SDK, and then respectively detects the importance of the one or more data embedding points for collecting the key data, whether they are important embedding points, general embedding points or non-essential embedding points. Therefore, when the data embedding point is detected as an important embedding point, the data type of the key data collected through the important embedding point is determined to be an important type; or, when the data embedding point is detected as a general embedding point, the data type of the key data collected through the general embedding point is determined to be a general type; or, when the data embedding point is detected as a non-essential embedding point, the data type of the key data collected by the non-essential embedding point is determined to be a non-essential type.

[0073] In this embodiment, the developer of the terminal application defines the importance of the tracking point when setting the tracking point, or automatically determines the importance of the tracking point based on detecting the location where the developer sets the tracking point. Therefore, when the important data collected by the important tracking point is subsequently cached, instead of placing the important data in the terminal memory, the important data is promptly stored in the database, thereby ensuring that the important data will not be lost due to caching in the memory, effectively reducing the data loss rate. In addition, the non-important data collected by other non-important tracking points are directly cached in the memory during subsequent caching. In this way, hierarchical caching of data can also improve terminal operating performance and data statistical efficiency.

[0074] Furthermore, in a feasible embodiment, the above step S10 may include:

[0075] Step S101, assembling the key data and combining it with the important type, the general type or the non-essential type to construct message data with type attributes of important message, general message or non-essential message.

[0076] It should be noted that in this embodiment, after the terminal device collects key data based on the SDK API of the data statistics architecture-SDK, it needs to be encapsulated into Payload and Message inside the SDK. There are many types of payloads, such as KVPayload. KVPayload can additionally store key Key-Value pairs, but all types of payloads have the following member variables:

[0077] 1. sessionId: The timestamp of the last time the app entered the foreground (if messages have the same sessionId, it means they are a group of related messages);

[0078] 2. timestamp: the timestamp when the payload is generated;

[0079] 3. messageId: The unique identifier of the message. The specific generation rule is a unique identifier related to time and device.

[0080] 4. Other specific valid contents. For example, KVPayload is commonly used for data collection. The key data is Key and Value. Other types of Payload are used to store different reported information contents.

[0081] Based on the Payload, it is encapsulated into a message (hereinafter referred to as Message). The structure of the Message consists of the following member variables:

[0082] 1. Payload: key data of the message;

[0083] 2. type: describes the type attribute of the message. This type attribute can simply divide the messages into three categories according to their importance, namely important messages Important, general messages Info, and non-essential messages Verbose. Among them, the loss rate of important messages Important is the lowest and the network report is the most timely, and the general messages Info are second. The loss rate of non-essential messages Verbose is higher and the network report is the slowest. In addition, non-essential messages Verbose will not be reported automatically, but will be reported to the network only when the caller triggers the flush method to refresh the API externally;

[0084] 3. commonInfos: other additional public data, such as the device's unique identification number vendorId, user-related information userInfo, network information netInfo when the message is generated, and other data that remains unchanged or changes very little over a long period of time.

[0085] Specifically, for example, after the terminal device receives the key data and the data type of the key data (important type, general type or non-essential type) passed in by the caller through the SDK API interface, the terminal device first automatically generates sessionId, timestamp, messageId and other specific valid content, so as to assemble the key data into Payload, and then combines the Payload with the data type - important type, general type or non-essential type, so as to obtain a message - Message with corresponding type attributes of important message, general message or non-essential message, and automatically generates commonInfos.

[0086] Step S20, detecting a type attribute of the message data, and determining a cache level corresponding to the message data based on the type attribute;

[0087] After constructing message data of different types of attributes based on combining the key data and the data type of the key data, the terminal device detects the type attribute of the message data and determines the cache level of the corresponding message data based on the type attribute.

[0088] Specifically, for example, after the terminal device assembles the received key data into a Payload, it then combines the Payload with the data type - important type, general type or non-essential type, thereby obtaining a message - Message whose corresponding type attributes are important messages, general messages or non-essential messages. After that, the terminal device further detects the type attributes of each message - Message one by one, thereby determining the cache levels of the messages - Messages whose type attributes are important messages, general messages and non-essential messages respectively when caching the messages - Messages subsequently.

[0089] It should be noted that, in this embodiment, the cache level of message data includes but is not limited to: memory cache and database cache. The terminal device can independently define through the developer of the data statistics architecture-SDK to determine that the cache level of message data with the type attribute of important messages is database cache, and determine that the cache level of message data with the type attribute of general messages and non-essential messages is memory cache.

[0090] Step S30, adding the message data to the corresponding storage space for caching according to the cache level;

[0091] After the terminal device determines the cache level of the message data, it calls the memory cache manager or database cache manager corresponding to the cache level in the memory cache layer of the data statistics architecture to store the message data in the terminal device's memory or in a database independent of the memory, so as to cache the message data before reporting it to the network.

[0092] It should be noted that in this embodiment, since the subsequent data statistics architecture will delete the cached message data in the cached storage space after uploading the cached message data based on the network reporting service, at this time, the caching of the message data by the data statistics architecture can be a temporary cache or a permanent storage.

[0093] Specifically, for example, in Figure 3 In the application scenario shown, the terminal device encapsulates the key data to obtain the Payload and constructs a message with different types of attributes based on the Payload and the data type (important type, general type or non-essential type). Then, according to the type attribute of the message (important message, general message or non-essential message), it determines whether the corresponding cache level is the database cache or the memory cache. If the cache level of the message is the memory cache, the terminal device calls the memory cache manager in the memory cache layer of the data statistics framework to store the message data in the memory of the terminal device. Alternatively, if the cache level of the message data is the database cache, the terminal device calls the database cache manager in the memory cache layer of the data statistics framework to store the message data in the database of the terminal device.

[0094] Furthermore, in a feasible embodiment, after storing the message data in the corresponding storage space, the terminal device will also synchronously update the data volume of the stored message data in the storage space.

[0095] Step S40: batch upload and delete the message data in the storage space.

[0096] Based on the data reporting service in the data network reporting layer of the data statistics architecture, the terminal device calls the data reporting service to package the message data and upload it to the background server for subsequent data statistics based on the data reporting service in the data network reporting layer of the data statistics architecture. When it detects that the message data cached in the storage space corresponding to different cache levels meets the preset data reporting conditions, the terminal device calls the data reporting service to package the message data and upload it to the background server for the background server to perform subsequent data statistics. After successfully sending the message data to the background server, the message data cached in the storage space is synchronously deleted.

[0097] It should be noted that, in this embodiment, the preset data reporting conditions can be specifically defined in advance by the developer of the data statistics architecture. For example, when the network status of the terminal device meets the data reporting requirement bandwidth and the amount of message data cached in the storage space is greater than zero, the message data in the storage space is immediately sent to the background server.

[0098] Specifically, for example, the terminal device detects the network status through periodic polling system, and when it detects that the network status meets the bandwidth required for data reporting, it synchronously or asynchronously detects whether the database volume of messages in the memory and database storing messages is greater than 0. If so, the terminal device immediately calls the data statistics architecture - SDK data network reporting layer to execute the data upload service manager - UploadManager, and gives priority to reading the messages in the database in batches (such as reading 10 messages at a time), and packages the read batches of messages and uploads them to the background server, and then upon receiving the upload success instruction fed back by the background server for the uploaded batch of messages, the batch of messages stored in the database is deleted.

[0099] After the terminal device uploads all the messages cached in the database to the server, it starts to call the manager UploadManager to read the messages in the memory in batches (such as reading 10 messages at a time), and packages the read batches of messages and uploads them to the background server for the background server to count the messages. Then, when receiving the upload success instruction fed back by the background server for the uploaded batch of messages, the batch of messages stored in the memory is deleted.

[0100] Furthermore, in a feasible embodiment, after the terminal device successfully uploads the message data in the storage space to the backend server and deletes the same message data in the storage space, the terminal device synchronously updates the data volume of the message data stored in the storage space.

[0101] The embodiment of the present invention provides a data statistics method based on multi-level cache. After the terminal device collects key data and the data type of the key data through the data collection module of the data statistics architecture, the key data and the data type are combined to construct message data with different types of attributes; the type attribute of the message data is detected and the cache level of the corresponding message data is determined based on the type attribute; in the memory cache layer of the data statistics architecture, the memory cache manager or the database cache manager corresponding to the cache level is called to store the message data in the memory of the terminal device or in a database independent of the memory, so as to cache the message data before network reporting; based on the data reporting service in the data network reporting layer of the data statistics architecture, when it is detected that the message data cached in the storage space corresponding to different cache levels meets the preset data reporting conditions, the data reporting service is called to package the message data and send it to the background server, and then after the message data is successfully sent to the background server, the message data cached in the storage space is synchronously deleted.

[0102] The present invention constructs message data based on the type of data to classify the message data, then determines the cache level of the message data based on the type attributes of the message data of different levels, and stores the message data in a memory or database of the corresponding cache level according to the determined cache level, thereby realizing multi-level caching for message data, storing important data in a database with a high cache level, and then, when reporting the message data, giving priority to reporting the message data cached in the database with a high cache level, thereby effectively reducing the loss rate of important data.

[0103] In addition, the present invention avoids large-scale and long-term occupation of terminal storage space by data by uploading message data in batches in storage spaces corresponding to different cache levels, thereby ensuring terminal operation performance.

[0104] Further, based on the above first embodiment, a second embodiment of the data statistics method based on multi-level cache of the present invention is proposed. In this embodiment, the cache levels corresponding to the message data of different attribute types include but are not limited to memory cache and database cache. Step S20, detecting the type attribute of the message data, and determining the cache level corresponding to the message data based on the type attribute, may include:

[0105] Step S201, detecting whether the type attribute of the message data is an important message, a general message or a non-essential message;

[0106] Step S202, if it is detected that the type attribute is an important message, determining that the cache level corresponding to the message data is a database cache;

[0107] After constructing and obtaining message data with different types of attributes, the terminal device detects whether the type attribute of the message data is an important message, a general message or a non-essential message. If the terminal device detects that the type attribute of the message data is an important message, in order to reduce the loss rate of the message data and ensure that important messages are not lost, the terminal device determines that the corresponding conversion level of the message data is a database cache, so that when the message data with the type attribute of important messages is subsequently cached, the message data will be stored in a database independent of the terminal device memory.

[0108] Step S203: If it is detected that the type attribute is a general message or a non-essential message, it is determined that the cache level corresponding to the message data is a memory cache.

[0109] When the terminal device detects whether the type attribute of the message data is an important message, a general message or a non-essential message, if the terminal device detects that the type attribute of the message data is a general message or a non-essential message, it directly determines that the conversion level corresponding to the message data is the memory cache, and when the message data with the type attribute of a general message or a non-essential message is subsequently cached, the message data is directly stored in the terminal device memory.

[0110] Further, in a feasible embodiment, the above step S30 of adding the message data to the corresponding storage space for caching according to the cache level may include:

[0111] Step S301, if it is detected that the cache level of the message data is database cache, an important message upload task is generated based on the message data;

[0112] Step S302, executing the important message upload task to store the message data in a database and updating the amount of message data in the database;

[0113] When the terminal device caches the message data, if it detects that the cache level corresponding to the message data is the database cache, the terminal device immediately calls the database cache manager in the data statistics architecture to generate an important message upload task for the message data.

[0114] The terminal device executes the important message upload task through the database cache manager to directly write the message data into a database independent of the terminal device memory for caching, and updates the data volume of the stored message data in the database.

[0115] It should be noted that in this embodiment, since the data statistics architecture proposed in this embodiment has two caching methods for message data, namely memory caching and database caching, the terminal device needs to first detect the cache levels corresponding to the determined message data before caching the constructed message data.

[0116] Specifically, for example, after the terminal device constructs the message - Message, it calls the message data cache method (addMessage) of the memory cache manager - CacheManager in the data cache layer of the data statistics architecture - SDK. This method constructs an executable block of a cache task - CacheOperation, and then directly adds the executable block of the cache task - CacheOperation to the cache task queue - CacheOperationQueue for asynchronous execution using the method - dispatch_async to add the task queue asynchronously. The executable code block logic of the cache task - CacheOperation executes the two methods of adding cache - addCache and processing cache - processCache, where the processing logic of the add cache - addCache method is:

[0117] 1. First, determine the type attribute of the message added to the executable block of the cache task - CacheOperation;

[0118] 2. If it is determined that the type attribute is an important message, that is, the message is an important message, it is necessary to fully ensure that the message has an extremely low loss rate. Therefore, the message is cached in the database. As a result, the terminal device directly calls the addSimple method of the database cache manager DBManger to add a single message data. Through the addSimple method, the message is directly written into the database for database caching, and an executable code block for creating an important message task -ImportantOperation is constructed at the same time. The executable code block is sent to the manager UploadManager who executes the data reporting service in the data statistics architecture -SDK, so that the UploadManager can upload the message to the background server.

[0119] It should be noted that, in the present embodiment, the database cache manager DBManager will store two categories of message data, namely single message data simple and message group Group. The simple and Group correspond to single messages - Message and message groups - MessageGroup respectively. The external function API of the database cache manager DBManager is to add, query and delete corresponding contents respectively. The database cache manager DBManager also has two member variables, namely the number of single message data simpleCount and the number of message groups groupCount, which are used to store the data volume of single message data simple and message group Group in the database respectively. The database cache manager DBManager needs to update the data volume of corresponding single message data simple and message group Group, namely the number of single message data simpleCount and the number of message groups groupCount, each time it adds and deletes message data.

[0120] Step S303: If it is detected that the cache level of the message data is the memory cache, the message data is added to the corresponding cache queue and the amount of message data in the memory is updated.

[0121] When the terminal device caches message data, if it detects that the cache level corresponding to the message data is memory cache, the terminal device immediately calls the memory cache manager in the data statistics architecture to directly add the message data to the cache queue set in the terminal device memory that corresponds to the type attribute of the message data, and then updates the data volume of the message data stored in the terminal device memory.

[0122] It should be noted that, in this embodiment, the memory cache manager CacheManager cache module interface in the data cache layer of the data statistics architecture SDK uses an asynchronous method to process the incoming message -Message. The memory cache manager CacheManager is composed of two cache queues, namely infoQueue (general message cache queue) and verboseQueue (non-essential message cache queue). The two cache queues are used to cache messages - Message, whose attribute type is general message - info and non-essential message - verbose. In addition, the memory cache manager CacheManager has two attributes, general message data number infoCount and non-essential message data number verboseCount, which are used to record the number of messages - Message stored and managed in the two cache queues, general message cache queue infoQueue and non-essential message cache queue verboseQueue respectively; moreover, the memory cache manager CacheManager also has a cache task queue CacheOperationQueue, which is an object of NSOperationQueue (task queue based on IOS system). The cache task queue CacheOperationQueue is a sequentially executed queue used to execute the executable code block of the cache task CacheOperation; the memory cache manager CacheManager has methods such as adding cache addMessage to message data, adding cache task addCache, processing cache task processCache and clearing cache task flushCache.

[0123] Specifically, for example, when the terminal device calls the memory cache manager CacheManager to cache a message -Message with a cache level of memory cache, if the memory cache manager CacheManager detects that the type attribute of the message -Message is a general message -info, then the memory cache manager CacheManager calls the addition target addObject of the general message queue infoQueue to add the message -Message to the tail of the queue of the general message queue infoQueue, and updates the number of general message data items infoCount (plus one); or, if the memory cache manager CacheManager detects that the type attribute of the message -Message is a non-essential message -verbose, then the memory cache manager CacheManager calls the addition target addObject of the non-essential message queue verboseQueue to add the message -Message to the tail of the non-essential message queue verboseQueue and then updates the number of non-essential message data items verboseCount (plus one).

[0124] Furthermore, in another feasible embodiment, after the above step S303, the data statistics method based on multi-level cache of the present invention may further include:

[0125] Step S304, when it is detected that the amount of the general message data exceeds the preset batch data assembly threshold, extracting the common parameters of the message data whose type attribute is the general message;

[0126] Step S305, formatting the common parameters into a message group, and generating an important message upload task based on the message group;

[0127] Step S306, executing the important message upload task to store the message group into a database and updating the amount of message group data in the database.

[0128] After the terminal device adds the message data to a cache queue corresponding to the type attribute of the message data set in the terminal device memory and updates the data volume of the message data stored in the terminal device memory, the terminal device detects the data volume of the general messages stored in the memory, and when it detects that the data volume of the general messages is greater than the preset batch data assembly threshold, extracts a group of general messages with a number equal to the preset batch data assembly threshold, and extracts the common parameters of the group of general messages, and after the common parameters are formatted into a message group, generates and executes an important message upload task to store the message group in the database according to the cache level of the important messages, and after successfully uploading the message group, updates the data volume of the message group stored in the database.

[0129] It should be noted that, in this embodiment, the preset batch data assembly threshold can be independently defined by the developer of the data statistics framework based on the design needs of actual applications, for example, set to threshold1.

[0130] Specifically, for example, after the terminal device calls the memory cache manager CacheManager to cache the message -Message with the cache level being the memory cache, the memory cache manager CacheManager detects the data size of the message -Message with the type attribute of the general message stored in the memory of the terminal device (i.e., the number of general messages infoCount) based on the processCache method of processing the cache task, and determines whether the number of general messages infoCount is greater than the batch data assembly threshold -threshold1. If the number of general messages infoCount is greater than or equal to threshold1, the memory cache manager CacheManager reads and deletes threshold1 number of messages -Message from the head of the general message queue infoQueue, and then extracts common parameters for the group of messages -Message read, and then formats the common parameters into a message group called MessageGroup, writes the message group MessageGroup into the database, and adds the executable code block of the general message upload task infoUploadOperation in the upload module of the manager - UploadManager that executes the data upload service.

[0131] In addition, if the memory cache manager CacheManager determines that the number of general messages infoCount is less than threshold1, or after the memory cache manager CacheManager writes the message group MessageGroup into the database and adds the executable code block of the general message upload task infoUploadOperation in the upload module of the manager-UploadManager that executes the data upload service, the memory cache manager CacheManager further determines whether the data volume of the message-Message whose type attribute is a non-essential message-the number of non-essential messages verboseCount is greater than the loss threshold-threashold2. If the number of non-essential messages verboseCount is greater than threshold2, the memory cache manager CacheManager directly deletes the message-Message at the head of the non-essential message queue verboseQueue.

[0132] In this embodiment, the type attribute of the message data is detected to determine whether it is an important message, a general message or a non-essential message; if the type attribute is detected to be an important message, the cache level corresponding to the message data is determined to be a database cache; if the type attribute is detected to be a general message or a non-essential message, the cache level corresponding to the message data is determined to be a memory cache.

[0133] For the database cache or memory cache of message data, if it is detected that the cache level of the message data is the database cache, an important message upload task is generated based on the message data; the important message upload task is executed to store the message data in the database and update the amount of message data in the database; or, if it is detected that the cache level of the message data is the memory cache, the message data is added to the corresponding cache queue and the amount of message data in the memory is updated.

[0134] After adding the message data to the corresponding cache queue and updating the amount of message data in the memory, if it is detected that the amount of general message data exceeds the preset batch data assembly threshold, the common parameters of the message data with the type attribute of the general message are extracted; the common parameters are formatted into a message group, and an important message upload task is generated based on the message group; the important message upload task is executed to store the message group in the database and update the amount of message group data in the database.

[0135] A multi-level cache for message data is implemented, and important data is stored in a database with a high cache level, which effectively reduces the loss rate of important data. By extracting the common parameters of general message data in the memory, storing the common parameters in the database and deleting the original general message data in the memory accordingly, and performing loss processing on non-essential message data that exceeds the loss threshold, different loss strategies are implemented for message data of different importance levels. Under the premise of ensuring the data loss rate, the problem of memory being occupied in large quantities and for a long time, which seriously affects the operation, is further avoided, thereby improving the operating performance of the terminal device.

[0136] Further, based on the above first embodiment, a third embodiment of the data statistics method based on multi-level cache of the present invention is proposed. In this embodiment, the above step S40, uploading and deleting the message data in batches in the storage space, may include:

[0137] Step S401, respectively reading target message data in the storage space corresponding to the message data, wherein the number of the target message data is greater than or equal to one;

[0138] Step S402: Packaging and encapsulating the target message data and synchronously uploading them to a preset background interface, and deleting the target message data in the storage space after the upload is successful.

[0139] After the terminal device caches the message data in the terminal device memory corresponding to the memory cache at the cache level, or stores it in the database corresponding to the database cache at the cache level, the terminal device calls the manager who performs the data reporting service in the data statistics framework data network reporting layer, first reads a preset number of target message data from the database, then packages and encapsulates the read message data and synchronously uploads it to the preset background interface, and sends the message data to the background server through the preset background interface. Finally, after receiving the instruction of successful message data transmission from the background server, the terminal device deletes the target message data stored in the database.

[0140] After all the message data in the database are uploaded to the preset background interface to complete the upload to the background server, the manager who executes the data reporting service further reads the message data in the terminal device memory in batches, and uploads the message data stored in the terminal device memory to the background server in the same way, and after the upload is successful, the message data stored in the terminal device memory is synchronously deleted.

[0141] It should be noted that, in this embodiment, the manager UploadManager that performs the data reporting service in the data statistics framework data SDK network reporting layer includes two key attributes, namely, the number of single message data simpleCount and the number of message groups groupCount, which respectively represent the number of single message data simple and message groups group Message currently stored in the database.

[0142] In addition, the manager UploadManager that executes the data reporting service has two key methods: initialization init and adding upload task addOperation method. Among them, the initialization init method needs to be called when the entire data statistics architecture-SDK is started. The initialization init method queries the single message data simple and message group group Message in the terminal device database, and assigns values ​​to the single message data number simpleCount and the message group number groupCount; and the initialization init method will maintain a message upload task queue UploadOperationQueue inside. The message upload task queue UploadOperationQueue is a subclass object of NSOperationQueue. If a message task Operation object is added to the message upload task queue UploadOperationQueue, the executable code block of the message task Operation will be asynchronously executed in the child thread in the order of addition. In addition, the addOpertaion method of adding an upload task adds an executable task to the message upload task queue UploadOperationQueue, and before adding the executable task, the addOpertaion method of adding an upload task will first determine whether there is a task of the same type waiting to be executed. If so, the task will not be added to the message upload task queue UploadOperationQueue.

[0143] Specifically, for example, please refer to Figure 4(a) shows an application scenario of the executable task - important message upload task ImportantUploadOperation. The terminal device executes the executable task - important message upload task ImportantUploadOperation by calling the manager UploadManager of the execution data reporting service. It first determines the network status of the terminal device. If the network status meets the required bandwidth of the network upload (if it does not meet the requirement, it will return directly). Then it determines whether the number of single message data simpleCount is greater than 0. If the number of single message data simpleCount is greater than 0, it calls the querySimples method of the database cache manager DBMananger to read a maximum of 10 single message data simple messages at a time (if the number of single message data simpleCount is greater than 0, it will read a maximum of 10 single message data simple messages at a time). If unt is equal to 0, it returns directly, or, if the single message data simple message-Message is less than 10, all are read); then, the read message-Message is packaged and encapsulated, and the network upload service is used synchronously to send the packaged result to the corresponding background interface and then sent to the background server. If the data upload success instruction is received from the background server, the messages that have been successfully uploaded-Messages are deleted in the database and the number of single message data simpleCount is modified; finally, the addOperation method of adding the upload task is continued to be called, and the important message upload task importantUploadOperation is added to the message upload task queue uploadOperationQueue to execute in a loop until the single message data simple message-Message is all uploaded to the background server.

[0144] In addition, please refer to Figure 4(a) shows an application scenario of the executable task - general message upload task InfoUploadOperation. The terminal device executes the executable task - general message upload task InfoUploadOperation by calling the manager UploadManager that executes the data reporting service. It first determines the network status of the terminal device. If the network status meets the required bandwidth for network upload (if it does not meet the requirements, it will be returned directly), then it is determined whether the number of message groups groupCount is greater than 0. If the number of message groups groupCount is greater than 0, the querySimples method of the database cache manager DBMananger is called to query the single message data, read the oldest (based on timestamp judgment) message group - MessageGroup, and synchronously use the network upload service to send the message group - MessageGroup to the corresponding background interface and send it to the background server. If the data upload success instruction is received from the background server, the message group - MessageGroup that has been successfully uploaded is deleted from the database and the number of message groups groupCount is modified; finally, the addOperation method of adding the upload task is continued to be called to add the general message upload task infoUploadOperation to the message upload task queue uploadOperationQueue to execute in a loop until all the message groups - MessageGroup are uploaded to the background server.

[0145] In addition, in this embodiment, the terminal device also adds an executable code block of a non-essential message upload task verboseUploadOperation in the manager UploadManager that executes the data reporting service by calling the flush method, so that the manager UploadManager that executes the data reporting service first determines the network status of the terminal device. If the network status meets the required bandwidth for network upload (if it does not meet the requirements, it will return directly), all messages with the type attribute of non-essential messages - verbose are read directly from the non-essential message queue verboseQueue of the memory cache manager CacheManager, and then the read messages - Message are integrated and packaged and the packaged results are synchronously sent to the background using the network upload service and sent to the background server. If a data upload success instruction is received from the background server, the uploaded messages - Message in the non-essential message queue verboseQueue are cleared.

[0146] In this embodiment, after the terminal device caches the message data in the terminal device memory corresponding to the memory cache at the cache level, or stores it in the database corresponding to the database cache at the cache level, the terminal device first reads a preset number of target message data in the database by calling the administrator who performs the data reporting service in the data network reporting layer of the data statistics framework, and then packages and encapsulates the read message data and uploads it to the preset background interface synchronously, and sends the message data to the background server through the preset background interface. Finally, after receiving the instruction of the successful message data transmission fed back by the background server, the terminal device deletes the target message data stored in the database. In this way, it is realized that important data is uploaded first according to the importance of the message data, and the cached original message data is deleted only after the data is uploaded successfully, which can avoid the risk of data loss and effectively reduce the data loss rate; in addition, the integration and packaging of different types of data can also improve the overall efficiency of data transmission.

[0147] The invention also provides a data statistics device based on multi-level cache.

[0148] Please refer to Figure 6 , Figure 6 Schematic diagram of functional modules of an embodiment of a data statistics device based on multi-level cache according to the present invention. Figure 6 As shown, the data statistics device based on multi-level cache includes:

[0149] A construction module 10, configured to construct message data according to the collected key data and the data type of the key data;

[0150] A determination module 20, configured to detect a type attribute of the message data, and determine a cache level corresponding to the message data based on the type attribute;

[0151] A cache module 30, configured to add the message data to a corresponding storage space for caching according to the cache level;

[0152] The upload module 40 is used to upload and delete the message data in batches in the storage space.

[0153] Furthermore, the data statistics device based on multi-level cache of the present invention also includes:

[0154] A collection module is used to collect key data and the data type of the key data based on a preset application interface; or to collect key data based on preset data points and detect the importance of the preset data points, and determine the data type of the key data according to the importance.

[0155] Furthermore, the data types include: important types, general types and non-essential types. The construction module 10 is also used to assemble the key data and combine it with the important type, the general type or the non-essential type to construct message data with type attributes of important messages, general messages or non-essential messages.

[0156] Furthermore, the cache level includes: memory cache and database cache, and the determination module 20 includes:

[0157] A first determining unit, configured to determine that the cache level corresponding to the message data is a database cache if it is detected that the type attribute is an important message;

[0158] The second determining unit is configured to determine that the cache level corresponding to the message data is a memory cache if it is detected that the type attribute is a general message or a non-essential message.

[0159] Furthermore, the cache module 30 includes:

[0160] A first task generating unit, configured to generate an important message upload task based on the message data if it is detected that the cache level of the message data is a database cache;

[0161] A database cache unit, used to execute the important message upload task to store the message data in a database and update the amount of message data in the database;

[0162] A memory cache unit is used to add the message data to a corresponding cache queue and update the amount of message data in the memory if it is detected that the cache level of the message data is the memory cache.

[0163] Furthermore, the message data volume in the memory includes: general message data volume, and the cache module 30 also includes:

[0164] A parameter extraction unit, configured to extract common parameters of message data whose type attribute is a general message when detecting that the amount of the general message data exceeds a preset batch data assembly threshold;

[0165] A second task generating unit, configured to format the common parameters into a message group, and generate an important message uploading task based on the message group;

[0166] The cache updating unit is used to execute the important message uploading task to store the message group in the database and update the data volume of the message group in the database.

[0167] Furthermore, the upload module 40 includes:

[0168] a reading unit, configured to read target message data respectively in the storage space corresponding to the message data, wherein the number of the target message data is greater than or equal to one;

[0169] The sending unit is used to package and encapsulate the target message data and upload it to the preset background interface synchronously, and delete the target message data in the storage space after the upload is successful.

[0170] Among them, the functional implementation of each module in the above-mentioned data statistics device based on multi-level cache corresponds to the various steps in the above-mentioned data statistics method embodiment based on multi-level cache, and its functions and implementation processes are no longer repeated here.

[0171] The present invention also provides a computer storage medium, which stores a data statistics program based on a multi-level cache. When the data statistics program based on a multi-level cache is executed by a processor, the steps of the data statistics method based on a multi-level cache as described in any of the above embodiments are implemented.

[0172] The specific embodiments of the computer storage medium of the present invention are basically the same as the embodiments of the above-mentioned data statistics method based on multi-level cache, and will not be described in detail here.

[0173] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0174] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0175] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A data statistics method based on multi-level cache, characterized in that: The data statistics method based on multi-level cache includes: Constructing message data according to the collected key data and the data type of the key data; Detecting the type attribute of the message data, and determining the cache level corresponding to the message data based on the type attribute; adding the message data to the corresponding storage space for caching according to the cache level; Batch uploading and deleting the message data in the storage space; The cache level includes memory cache and database cache; The step of detecting the type attribute of the message data and determining the cache level corresponding to the message data based on the type attribute includes: Detecting whether the type attribute of the message data is an important message, a general message, or a non-essential message; If it is detected that the type attribute is an important message, determining that the cache level corresponding to the message data is a database cache; If it is detected that the type attribute is a general message or a non-essential message, determining that the cache level corresponding to the message data is a memory cache; The step of adding the message data to the corresponding storage space for caching according to the cache level includes: If it is detected that the cache level of the message data is database cache, an important message upload task is generated based on the message data; Execute the important message uploading task to store the message data in a database and update the amount of message data in the database; Alternatively, if it is detected that the cache level of the message data is a memory cache, the message data is added to a corresponding cache queue and the amount of message data in the memory is updated; the amount of message data in the memory includes: a general message data amount; When it is detected that the amount of the general message data exceeds a preset batch data assembly threshold, extracting common parameters of the message data whose type attribute is a general message; Formatting the common parameters into a message group, and generating an important message upload task based on the message group; Executing the important message uploading task stores the message group in a database and updates the data volume of the message group in the database.

2. The data statistics method based on multi-level cache according to claim 1, characterized in that: Before the step of constructing message data according to the collected key data and the data type of the key data, the method further includes: Collect key data and data types of the key data based on a preset application program interface; Alternatively, key data is collected based on preset data burying points and the importance of the preset data burying points is detected, and the data type of the key data is determined according to the importance.

3. The data statistics method based on multi-level cache according to claim 1, characterized in that: The data types include: important types, general types and non-essential types. The step of constructing message data according to the collected key data and the data type of the key data comprises: The key data is assembled and combined with the important type, the general type or the non-essential type to construct message data whose type attribute is an important message, a general message or a non-essential message.

4. The data statistics method based on multi-level cache according to any one of claims 1 to 3, characterized in that: The step of uploading and deleting the message data in batches in the storage space comprises: respectively reading target message data in the storage space corresponding to the message data, wherein the number of the target message data is greater than or equal to one; The target message data is packaged and encapsulated and then synchronously uploaded to a preset background interface, and the target message data in the storage space is deleted after the upload is successful.

5. A data statistics device based on multi-level cache, characterized in that: The data statistics device based on multi-level cache includes: A construction module, used to construct message data according to the collected key data and the data type of the key data; A determination module, configured to detect a type attribute of the message data, and determine a cache level corresponding to the message data based on the type attribute; A cache module, used for adding the message data to a corresponding storage space for caching according to the cache level; An upload module, used to upload and delete the message data in batches in the storage space; The cache level includes memory cache and database cache; The determination module is further used to detect whether the type attribute of the message data is an important message, a general message or a non-essential message; If it is detected that the type attribute is an important message, determining that the cache level corresponding to the message data is a database cache; If it is detected that the type attribute is a general message or a non-essential message, determining that the cache level corresponding to the message data is a memory cache; The cache module is further configured to generate an important message upload task based on the message data if it is detected that the cache level of the message data is a database cache; Execute the important message uploading task to store the message data in a database and update the amount of message data in the database; Alternatively, if it is detected that the cache level of the message data is a memory cache, the message data is added to a corresponding cache queue and the amount of message data in the memory is updated; the amount of message data in the memory includes: a general message data amount; The cache module is further configured to extract the common parameters of the message data whose type attribute is a general message when it is detected that the amount of the general message data exceeds a preset batch data assembly threshold; Formatting the common parameters into a message group, and generating an important message upload task based on the message group; Executing the important message uploading task stores the message group in a database and updates the data volume of the message group in the database.

6. A terminal device, characterized in that: The terminal device includes: a memory, a processor, and a multi-level cache-based data statistics program stored in the memory and executable on the processor. When the multi-level cache-based data statistics program is executed by the processor, the steps of the multi-level cache-based data statistics method as described in any one of claims 1 to 4 are implemented.

7. A computer storage medium, characterized in that: The computer storage medium stores a data statistics program based on a multi-level cache, and when the data statistics program based on a multi-level cache is executed by a processor, the steps of the data statistics method based on a multi-level cache as described in any one of claims 1 to 4 are implemented.