Data persistence method, device, equipment, medium and product
By using the state management library of the data persistence system, the application is initialized and the data that needs to be persisted is filtered out and stored in an encrypted manner. This solves the problem of dynamic data loss in the application, realizes long-term data retention and security, and ensures that the application can be quickly restored to the modified state.
Patent Information
- Application Number
- CN202511933854.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-04-10
Smart Images

Figure CN121833345A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular to a data persistence method, device, equipment, medium and product. BACKGROUND
[0002] Data persistence refers to persistently storing information generated during the running of an application program. However, the running environment of an application program itself is transient, and if there is no effective storage mechanism, all generated data will disappear with the termination of the process. Therefore, how to realize data persistence has become a technical problem to be solved in front-end development.
[0003] In the prior art, an application program usually stores dynamic data generated during running in a memory space. The specific implementation is to define variables, objects or build state management structures through program code, to directly save user interaction states, interface configuration information and temporary calculation results in a memory address allocated by the system, for real-time reading, writing and calling by the application program during running.
[0004] However, the prior art has the problem of being unable to perform data persistence. In the prior art, data can only be stored in the memory, and once the application program is refreshed or the application program is closed, this information will disappear, cannot be stored for a long time, and causes the user to need to reacquire or process related information when using the application again. SUMMARY
[0005] The embodiments of the present application provide a data persistence method, device, equipment, medium and product to solve the problem of being unable to perform data persistence in the prior art.
[0006] In a first aspect, the embodiments of the present application provide a data persistence method applied to a state management library of a data persistence system, the data persistence system further comprising a user end, and the method comprises:
[0007] initializing a preset application program to obtain an initialized application program, and obtaining a plurality of initial data; wherein the initialization is used to adjust the state of the application program to a preset initialization state, and the plurality of initial data refers to configuration data of the initialized application program;
[0008] in response to a first user operation, triggering a business process corresponding to the first user operation, and calling a state change tool corresponding to the business process to modify a plurality of first data to obtain a plurality of modified data and a modified state; wherein the plurality of initial data comprises the plurality of first data, and the plurality of modified data is a data set composed of data that is not modified in the plurality of initial data and data obtained by modifying the plurality of first data;
[0009] in response to the state of the application program being converted from the initialization state to the modified state, obtaining a plurality of second data; wherein the plurality of second data is data of a preset state field or module in the plurality of modified data that needs to be encrypted and persisted;
[0010] encrypting the plurality of second data to obtain a plurality of encrypted data, and storing the plurality of encrypted data to a preset local storage medium, so that the application program is recovered to the modified state according to the plurality of encrypted data after being refreshed or restarted.
[0011] In a possible design, after the plurality of encrypted data is stored to the preset local storage medium, the method further includes:
[0012] in response to the application program being refreshed or restarted, obtaining the plurality of encrypted data;
[0013] decrypting the encrypted data to obtain a decryption result and a plurality of decrypted data; wherein the decryption result includes success and failure;
[0014] in response to the decryption result being the success, performing state recovery on the application program according to the plurality of decrypted data, so that the state of the application program is recovered to the modified state;
[0015] in response to the decryption result being the failure, excluding the plurality of decrypted data and obtaining a plurality of remote data; wherein the excluding the plurality of decrypted data means that the plurality of decrypted data is not used when performing state recovery on the application program, and the plurality of remote data is data stored by a preset remote server, and the plurality of remote data is used to perform state repair of the application program when the decryption result is the failure;
[0016] performing state repair on the application program according to the plurality of remote data and a plurality of initial data, so that the state of the application program is recovered to a preset normal working state;
[0017] in response to a second user operation, interacting with the application program recovered to the normal working state according to the second user operation.
[0018] In a possible design, the normal working state includes the initialization state and a non-initialization state, and the performing state repair on the application program according to the plurality of remote data and the plurality of initial data, so that the state of the application program is recovered to the preset normal working state, includes:
[0019] obtaining a network connection state between the state management library and the remote server; wherein the network connection state includes being connected and being disconnected;
[0020] in response to the network connection state being the connected, performing state repair on the application according to the plurality of initial data, so as to restore the state of the application to the initialization state;
[0021] in response to the network connection state being the disconnected, performing state repair on the application according to the plurality of remote data, so as to restore the state of the application to the non-initialization state, the non-initialization state being a state other than the initialization state in the normal working state.
[0022] In a possible design, the storing the plurality of encrypted data to the preset local storage medium comprises:
[0023] obtaining a plurality of historical encrypted data, wherein the plurality of historical encrypted data are encrypted data stored to the local storage medium last time;
[0024] comparing the plurality of encrypted data with the plurality of historical encrypted data to obtain a plurality of changed data, wherein the plurality of changed data are data in the plurality of encrypted data that are changed compared with the plurality of historical encrypted data;
[0025] storing the plurality of changed data to the local storage medium.
[0026] In a possible design, the plurality of encrypted data comprises a plurality of first encrypted data and a plurality of second encrypted data, and the encrypting the plurality of second data to obtain a plurality of encrypted data comprises:
[0027] calculating the importance of each second data according to a preset importance calculation rule;
[0028] classifying the plurality of second data according to the importance of each second data to obtain a plurality of third data and a plurality of fourth data, wherein the plurality of third data are data in the plurality of second data whose importance is greater than or equal to a preset importance threshold, and the plurality of fourth data are data in the plurality of second data whose importance is less than the importance threshold;
[0029] encrypting the plurality of third data to obtain the plurality of first encrypted data;
[0030] encrypting the plurality of fourth data to obtain the plurality of second encrypted data, wherein the encryption strength of encrypting the plurality of third data is greater than the encryption strength of encrypting the plurality of fourth data.
[0031] In a possible design, the encrypting the plurality of third data to obtain the plurality of first encrypted data comprises:
[0032] acquire a data type of the plurality of third data;
[0033] match the plurality of third data with a plurality of preset encryption rules based on the data type of the plurality of third data, to obtain a target encryption rule; wherein the target encryption rule refers to a rule in the plurality of encryption rules that has the highest matching degree with the data type of the plurality of third data;
[0034] encrypt the plurality of third data according to the target encryption rule, to obtain a plurality of first encrypted data.
[0035] In a second aspect, an embodiment of the present application provides a data persistence device, applied to a state management library of a data persistence system, the data persistence system further comprising a user end, and the device comprising:
[0036] an initialization module, configured to initialize a preset application program, to obtain an initialized application program, and to acquire a plurality of initial data; wherein the initialization is configured to adjust a state of the application program to a preset initialization state, and the plurality of initial data refers to configuration data of the initialized application program;
[0037] a modification module, configured to trigger a business process corresponding to a first user operation in response to the first user operation, and to call a state change tool corresponding to the business process, to modify a plurality of first data, to obtain a plurality of modified data and a modified state; wherein the plurality of initial data comprises the plurality of first data, and the plurality of modified data is a data set composed of data that is not modified in the plurality of initial data and data obtained after the plurality of first data is modified;
[0038] a first acquisition module, configured to acquire a plurality of second data in response to a state of the application program being converted from the initialization state to the modified state; wherein the plurality of second data refers to data of a preset state field or module that needs to be encrypted and persisted in the plurality of modified data;
[0039] an encryption module, configured to encrypt the plurality of second data, to obtain a plurality of encrypted data, and to store the plurality of encrypted data to a preset local storage medium, so that the application program is recovered to the modified state according to the plurality of encrypted data after being refreshed or restarted.
[0040] In a possible design, the data persistence device further comprises:
[0041] a second acquisition module, configured to acquire the plurality of encrypted data in response to the application program being refreshed or restarted;
[0042] a decryption module, configured to decrypt the encrypted data to obtain a decryption result and a plurality of decrypted data, wherein the decryption result comprises success and failure;
[0043] a recovery module, configured to, in response to the decryption result being the success, perform state recovery on the application according to the plurality of decrypted data, so that the state of the application is recovered to the modified state;
[0044] a third obtaining module, configured to, in response to the decryption result being the failure, exclude the plurality of decrypted data and obtain a plurality of remote data, wherein the exclusion of the plurality of decrypted data means that the plurality of decrypted data is not used when performing state recovery on the application, and the plurality of remote data means data stored in a preset remote server, and the plurality of remote data is used to perform state repair on the application when the decryption result is the failure;
[0045] a repair module, configured to perform state repair on the application according to the plurality of remote data and a plurality of initial data, so that the state of the application is recovered to a preset normal working state;
[0046] an interaction module, configured to, in response to a second user operation, interact with the second user operation according to the application recovered to the normal working state.
[0047] In a possible design, the normal working state comprises the initial state and a non-initial state, and the repair module comprises:
[0048] a first obtaining unit, configured to obtain a network connection state between the state management library and the remote server, wherein the network connection state comprises connection and disconnection;
[0049] a first repair unit, configured to, in response to the network connection state being the connection, perform state repair on the application according to the plurality of initial data, so that the state of the application is recovered to the initial state;
[0050] a second repair unit, configured to, in response to the network connection state being the disconnection, perform state repair on the application according to the plurality of remote data, so that the state of the application is recovered to a non-initial state, wherein the non-initial state means a state other than the initial state in the normal working state.
[0051] In a possible design, the encryption module comprises:
[0052] a second obtaining unit, configured to obtain a plurality of historical encrypted data, wherein the plurality of historical encrypted data means encrypted data stored in the local storage medium last time.
[0053] a comparison unit, configured to compare the plurality of encrypted data with the plurality of historical encrypted data to obtain a plurality of changed data; wherein the plurality of changed data refers to data in the plurality of encrypted data that is changed compared with the plurality of historical encrypted data;
[0054] a storage unit, configured to store the plurality of changed data to the local storage medium.
[0055] In a possible design, the plurality of encrypted data includes a plurality of first encrypted data and a plurality of second encrypted data, and the encryption module includes:
[0056] a calculation unit, configured to calculate the importance of each of the second data according to a preset importance calculation rule;
[0057] a classification unit, configured to classify the plurality of second data according to the importance of each of the second data to obtain a plurality of third data and a plurality of fourth data; wherein the plurality of third data refers to data in the plurality of second data whose importance is greater than or equal to a preset importance threshold, and the plurality of fourth data refers to data in the plurality of second data whose importance is less than the importance threshold;
[0058] a first encryption unit, configured to encrypt the plurality of third data to obtain the plurality of first encrypted data;
[0059] a second encryption unit, configured to encrypt the plurality of fourth data to obtain the plurality of second encrypted data; wherein the encryption strength of encrypting the plurality of third data is greater than the encryption strength of encrypting the plurality of fourth data.
[0060] In a possible design, the first encryption unit includes:
[0061] an acquisition component, configured to acquire the data type of the plurality of third data;
[0062] a matching component, configured to match the plurality of third data with a plurality of preset encryption rules based on the data type of the plurality of third data to obtain a target encryption rule; wherein the target encryption rule refers to a rule in the plurality of encryption rules that has the highest matching degree with the data type of the plurality of third data;
[0063] an encryption component, configured to encrypt the plurality of third data according to the target encryption rule to obtain the plurality of first encrypted data.
[0064] In a third aspect, the present application provides an electronic device, including: a processor, and a memory connected with the processor in communication;
[0065] The memory stores computer-executable instructions.
[0066] The processor executes the computer-executable instructions stored in the memory, to implement the data persistence method according to any one of the first aspect.
[0067] In a fourth aspect, the present application provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions, when executed by a processor, are used to implement the data persistence method according to any one of the first aspect.
[0068] In a fifth aspect, the present application provides a computer program product, which comprises a computer program, and the computer program, when executed by a processor, is used to implement the data persistence method according to any one of the first aspect.
[0069] The data persistence method, device, equipment, medium and product provided by the present application can initialize an application program through a state management library of a data persistence system to obtain initial configuration data, trigger a corresponding business process in response to a user operation and modify related data to obtain modified data and a state, and after the state of the application program is changed from an initial state to a modified state, specific state fields or module data that need to be encrypted and persisted are screened out, and after encryption processing, the data is stored in a local storage medium, thereby solving the problem that in the prior art, dynamic data of an application program is only stored in a memory and is easy to lose after refreshing or restarting, and the user does not need to obtain or process related information again, and meanwhile, the data security is ensured through encryption processing, and the effect of quickly restoring the application program to the modified state after refreshing or restarting is achieved. BRIEF DESCRIPTION OF DRAWINGS
[0070] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.
[0071] Figure 1 An application scenario of the data persistence method provided by the embodiments of the present application is shown in the following figure.
[0072] Figure 2 A flowchart of the data persistence method provided by the embodiments of the present application is shown in the following figure. Figure 1
[0073] Figure 3 A flowchart of the data persistence method provided by the embodiments of the present application is shown in the following figure. Figure 2
[0074] Figure 4 A state management data flow of Vuex provided by the embodiments of the present application is shown in the following figure. Figure 1
[0075] Figure 2 A state management data flow conversion schematic provided by an embodiment of the present application for Vuex Figure 6 ;
[0076] Figure 7 A structure schematic of a data persistence device provided by an embodiment of the present application
[0077] Figure 1 A hardware structure schematic of an electronic device provided by an embodiment of the present application
[0078] The specific embodiments of the present application have been shown in the above-described drawings, and will be described in more detail hereinafter. These drawings and the written description are not intended to restrict the scope of the present application concept in any way, but to illustrate the present application concept to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0079] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, the same numbers are used to indicate the same or similar components. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application as detailed in the appended claims.
[0080] In the technical solutions of the present application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data comply with relevant laws and regulations and do not violate public order and good customs.
[0081] It should be noted that in the embodiments of the present application, some existing industry solutions, components, models, etc. may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0082] First, the terms involved in the present application are explained:
[0083] Vuex (Vue State Management Library): a centralized state management pattern designed for Vue.js applications, which allows developers to store the state shared by multiple components in a global repository (Store), ensuring state consistency and ease of maintenance.
[0084] Local Storage: a persistent storage mechanism provided by the browser, which can save data in the form of key-value pairs on the client side, and the data still exists after page refresh or browser closure. Its storage capacity is generally 5-10MB.
[0085] Persisted State Module is a module for saving Vuex state data to browser storage (such as Local Storage). Through this module, the state data of Vuex can be restored after the page is refreshed or the browser is closed.
[0086] Indexed Database is a low-level database API built into the browser, allowing developers to store large amounts of structured data (such as JSON objects) on the client side, supporting features such as transactions and indexing.
[0087] Encrypt Moudle is the process of encoding data, the purpose is to prevent unauthorized access to data.
[0088] Decrypt Moudle is the process of restoring encrypted data to its original form, usually requiring the key or password used to encrypt the data to decrypt it.
[0089] Session Storage is a local storage mechanism provided by the browser, similar to LocalStorage, but the data lifetime is limited to the current tab or session, and the data will be cleared when the tab is closed.
[0090] Cache API is an interface provided by the browser to store network resources (such as HTML, CSS, JS files, etc.). Cache API is often used with Service Worker, suitable for offline applications and resource caching.
[0091] The exemplary embodiments will be described in detail in this section. Where the description in this section uses numerals to identify a component, these numerals are used consistently throughout the description and / or drawings and are not intended to limit the scope of the disclosure. The following description of the exemplary embodiments is not intended to represent that the aspects of the present disclosure, as claimed below, can not be embodied in other ways other than the exemplary embodiments illustrated herein.
[0092] The technical solutions of the present application will be described in detail below with specific examples. The following specific examples can be combined with each other, and the same or similar concepts or processes may not be described again in some examples. The embodiments of the present application will be described below with reference to the drawings.
[0093] For the clear understanding of the technical solutions of the present application, first, the prior art solutions are introduced in detail. The running environment of the application program itself has instantaneity, if lacking effective storage mechanism, all generated data will disappear with the process termination. Therefore, how to realize the data persistence has become a technical problem to be solved in front-end development.
[0094] In the prior art, the application program usually stores the dynamic data generated during running in the memory space, the specific implementation is to define variables, objects or build state management structure through program code, save the user interaction state, interface configuration information and temporary calculation results directly in the memory address allocated by the system, for the application program to read and write and call in real time during running. In the prior art, once the application program refresh operation or the application program is closed, these information will disappear, cannot realize long time storage, resulting in that the user needs to reacquire or process the related information when using the application again. Therefore, the prior art has the problem of unable to perform data persistence.
[0095] Therefore, in order to solve the problem that data persistence cannot be performed in the prior art, it is found in research that in order to solve the problem, the dynamic data generated during the running of the application program which needs to be stored can be stored in a preset manner to a non-memory persistent storage carrier, realizing long-term storage of data: ①a data persistence management mechanism can be added in the running system of the application program, screening out the dynamic data generated during running which needs to be stored for a long time, using an adaptive storage strategy to transfer it to a non-memory persistent storage carrier, ensuring that the data is not lost when the application program state changes. ②The data persistence capability can be integrated into the state management system of the application program, when the dynamic data is generated or changed, the data persistence storage process is automatically triggered, by converting the data into a form suitable for persistent storage and saving it to a non-memory carrier, realizing long-term storage of data and traceable recovery of the running state of the application program. ③A data layered storage architecture can be built, the dynamic data during the running of the application program is classified according to the storage requirements, the data to be persisted is preprocessed by encryption, formatting, etc., and stored in the local or network end persistent storage carrier, which not only guarantees the long-term storage of data, but also takes into account the security and availability of data storage.
[0096] Specifically: an automatic state management intermediate layer can be introduced in the application architecture. The intermediate layer is responsible for detecting the state changes of the application program during running, and periodically or in real time saves the specific state data to the local persistent storage medium through serialization technology. When the application restarts, the intermediate layer can automatically read and deserialize the historical state data from the storage medium, and reload it into the memory, so that the application can seamlessly recover to the state before closing, realizing the persistent storage of data.
[0097] This application discloses a data persistence method, apparatus, device, medium, and product. Through the state management library of the data persistence system, the application is first initialized to obtain initial configuration data. In response to user operations, corresponding business processes are triggered, and relevant data is modified to obtain the modified data and state. After the application state changes from the initial state to the modified state, specific state fields or module data that need to be encrypted and persisted are selected, encrypted, and then stored on the local storage medium. This solves the problem in existing technologies where application dynamic data is only stored in memory and easily lost after refresh or restart. Users do not need to re-obtain or process relevant information, and encryption ensures data security, achieving the effect of quickly restoring the application to the modified state after refresh or restart.
[0098] Based on the above-mentioned inventive discovery, the technical solution of this application is proposed.
[0099] The following describes the application scenarios of the data persistence method provided in the embodiments of the present invention. Figure 1 This is a schematic diagram illustrating an application scenario of the data persistence method provided in the embodiments of this application. For example... Figure 2 As shown, the application scenario includes a user terminal 101 and a state management library 102. The state management library 102 initializes a preset application to obtain the initialized application and acquires multiple initial data. In response to a first user operation, the state management library 102 triggers the business process corresponding to the first user operation and calls the state change tool corresponding to the business process to modify the multiple first data, obtaining multiple modified data and a modified state. In response to the application's state changing from the initial state to the modified state, the state management library 102 acquires multiple second data. The state management library 102 encrypts the multiple second data to obtain multiple encrypted data and stores the multiple encrypted data in a preset local storage medium so that the application can be restored to the modified state based on the multiple encrypted data after refreshing or restarting.
[0100] The embodiments of the present invention will now be described with reference to the accompanying drawings.
[0101] Figure 1 Flowchart of the data persistence method provided in the embodiments of this application Figure 2 .like Figure 3 As shown, in this embodiment, the execution entity of this invention is a state management library. The data persistence method provided in this embodiment includes the following steps:
[0102] S201. Initialize the preset application to obtain the initialized application and acquire multiple initial data; wherein, initialization is used to adjust the state of the application to the preset initialization state, and multiple initial data refer to the configuration data of the initialized application.
[0103] Specifically, the initialization operation of the application can be completed by loading a preset basic configuration, starting a core running component of the application and adapting a running environment thereof, synchronously reading basic configuration information required for normal starting and running of the application, and obtaining corresponding initial data, thereby providing basic data support for subsequent operations such as responding to a user operation, triggering a business process, and carrying out data modification, encryption, and persistent storage, and ensuring smooth starting of the application from a preset initial state, thereby laying a foundation for implementation of the entire data persistent solution.
[0104] S202, in response to the first user operation, a business process corresponding to the first user operation is triggered, and a state change tool corresponding to the business process is called to modify the plurality of first data, to obtain a plurality of modified data and a modified state; wherein the plurality of initial data includes the plurality of first data, and the plurality of modified data is a data set composed of data that is not modified in the plurality of initial data and data obtained by modifying the plurality of first data.
[0105] Specifically, the initialization operation of the application can be completed by loading a preset basic configuration, starting a core running component of the application and adapting a running environment thereof, synchronously reading basic configuration information required for normal starting and running of the application, and obtaining corresponding initial data, thereby providing basic data support for subsequent operations such as responding to a user operation, triggering a business process, and carrying out data modification, encryption, and persistent storage, and ensuring smooth starting of the application from a preset initial state, thereby laying a foundation for implementation of the entire data persistent solution.
[0106] S203, in response to the state of the application being changed from the initial state to the modified state, a plurality of second data is obtained; wherein the plurality of second data refers to data of a preset state field or module that needs to be encrypted and persisted in the plurality of modified data.
[0107] Specifically, after the running state of the application is changed from the initial state to the modified state, key state information or specified function module related data that has a persistent storage requirement and needs to be encrypted is extracted from the modified data according to a preset screening rule, thereby accurately positioning and extracting core data that needs to be long-term retained, providing an explicit processing object for subsequent data encryption processing and persistent storage operation, ensuring the pertinence and effectiveness of the data persistent process, and providing a reliable data foundation for subsequent state recovery of the application.
[0108] S204, encrypt the plurality of second data to obtain a plurality of encrypted data, and store the plurality of encrypted data to a preset local storage medium, so that the application program is recovered to the modified state according to the plurality of encrypted data after refreshing or restarting.
[0109] Specifically, the extracted data to be persisted can be securely processed by using an adaptive data encryption method to generate encrypted target data, and the encrypted data is written into a preset local storage carrier to establish an associated mapping between the encrypted data and the application program running state. After the application program is interrupted or reset, the application program can be recovered to the previous modified running state by reading and analyzing the locally stored encrypted data. This step is used to securely and persistently store the data to be retained, so that the data is independent of the memory and is not lost when the application program state is changed. At the same time, the security of the data storage process is ensured, and the user can recover the historical running state of the application program without reoperation, improving the continuity and convenience of application use.
[0110] The data persistence method provided by the embodiment is used to initialize the application program by the state management library of the data persistence system to obtain initial configuration data, trigger the corresponding business process in response to user operation and modify the related data to obtain modified data and state, and filter out specific state fields or module data to be encrypted and persisted after the application program state is converted from the initialization state to the modified state. After encryption, the data is stored in the local storage medium, solving the problem that the dynamic data of the application program is only stored in the memory and is easily lost after refreshing or restarting. The user does not need to reacquire or process the related information, and the data security is ensured by encryption, achieving the effect of quickly recovering the application program to the modified state after refreshing or restarting.
[0111] In a possible design, S204, the plurality of encrypted data is stored to the preset local storage medium, including:
[0112] S2041, obtain a plurality of historical encrypted data; wherein the plurality of historical encrypted data refers to the encrypted data stored to the local storage medium last time.
[0113] Specifically, the local storage medium can be accessed to read the previously stored encrypted data, and the historical encrypted data is obtained. This step is used to provide reference data for the comparison operation between the newly generated encrypted data and the historical encrypted data, so as to filter out the changed content, avoid repeated storage of unchanged data, improve the data storage efficiency, and optimize the space usage of the local storage medium.
[0114] S2042, compare the plurality of encrypted data with the plurality of historical encrypted data to obtain a plurality of change data; wherein the plurality of change data refers to data in the plurality of encrypted data that changes compared with the plurality of historical encrypted data.
[0115] Specifically, the newly generated encrypted data and the obtained historical encrypted data can be compared according to a preset comparison rule to identify the differences between them, and then the change data is obtained. This step is used to accurately filter the changed part of the encrypted data, avoid redundant storage of unchanged repeated data, improve the efficiency of data storage, reduce the space occupation of the local storage medium, and ensure the simplicity and effectiveness of the stored data.
[0116] S2043, store the plurality of change data to the local storage medium.
[0117] Specifically, the filtered change data can be written into the appropriate storage location of the local storage medium according to the preset storage rule, and the corresponding content of the local storage is updated synchronously. This step is used to retain only the changed part of the encrypted data, avoid repeated storage of unchanged data, optimize the space occupation of the local storage medium, improve the storage efficiency of data persistence, and ensure that the encrypted data stored locally is always up-to-date, so that the latest valid data can be obtained when the state of the subsequent application program is restored.
[0118] The technical effect of this scheme in this embodiment is that by first obtaining the historical encrypted data stored in the local storage medium last time, comparing the current encrypted data to be stored with the historical encrypted data, filtering the change data that changes compared with the historical encrypted data, and storing only the change data to the local storage medium, the repeated storage of unchanged data is avoided, the storage space occupation of the local storage medium is reduced, the resource consumption in the data writing process is reduced, and the efficiency of data storage is improved.
[0119] In one possible design, the plurality of encrypted data includes a plurality of first encrypted data and a plurality of second encrypted data, S204, encrypting the plurality of second data to obtain the plurality of encrypted data, comprising:
[0120] S2041, calculate the importance of each second data according to a preset importance calculation rule.
[0121] Specifically, the importance of each second data can be determined according to a preset evaluation standard by combining relevant features such as the functional influence degree, user dependence degree, usage frequency, and sensitive attributes of the data. This step is used to provide a basis for subsequent classification and adaptation of different intensity encryption processing according to the importance of the data, to ensure that core critical data is protected with higher security, while the encryption efficiency of non-core data is taken into account.
[0122] The preset importance calculation rule can be a multi-dimensional weighted scoring rule, and the core includes four dimensions and fixed weights: sensitive attribute (40%), functional influence degree (30%), user dependence degree (20%), and use frequency (10%). Each dimension is scored in five levels according to data characteristics, such as sensitive attribute from high to low: strong identity information, private content, no sensitive information, etc. When calculating, first score each second data in each dimension, then calculate the comprehensive score by sensitive score x 40% + functional score x 30% + dependence score x 20% + frequency score x 10%, and finally determine the level according to the score, 8-10 points are extremely high, 6-7.9 points are high, 4-5.9 points are medium, and 1-3.9 points are low. For example, calculating the user's private chat record: 3 points (sensitive) for containing private content, 4 points (functional) for abnormal influence on chat function, 5 points (dependence) for daily use, and 5 points (frequency) for 120 times of monthly call, the comprehensive score = 3x0.4+4x0.3+5x0.2+5x0.1=3.9 points, and the importance is determined to be low. Calculating the community post record: 1 point (sensitive) for no sensitive information, 2 points (functional) for abnormal influence on viewing history, 3 points (dependence) for 1-2 times of weekly use, and 3 points (frequency) for 30 times of monthly call, the comprehensive score = 1x0.4+2x0.3+3x0.2+3x0.1=1.9 points, and the importance is determined to be low.
[0123] S2042, classify the plurality of second data according to the importance of each second data, to obtain a plurality of third data and a plurality of fourth data; wherein the plurality of third data refers to data whose importance is greater than or equal to a preset importance threshold in the plurality of second data, and the plurality of fourth data refers to data whose importance is less than the importance threshold in the plurality of second data.
[0124] Specifically, the importance of each second data can be compared with a preset importance determination benchmark, data whose importance reaches or exceeds the benchmark is divided into one category, and data whose importance does not reach the benchmark is divided into another category, and then corresponding third data and fourth data are obtained. This step is used to clarify the security protection priority of different data, to provide classification support for subsequent differential processing of higher strength encryption for core key data and adaptive strength encryption for non-core data, to realize precise matching of data security protection, and to consider the efficiency of encryption processing and reasonable allocation of resources.
[0125] S2043, encrypt the plurality of third data to obtain a plurality of first encrypted data.
[0126] Specifically, a high-security level encryption mechanism suitable for the importance of the third data can be adopted, and a plurality of third data is deeply and safely processed through a preset multi-level encryption logic to generate corresponding first encrypted data. The encryption processing has a higher protection strength than the encryption mode of the fourth data. This step is used to provide high-strength security protection for core data with higher importance, to maximize the resistance to data leakage or tampering, and to protect the confidentiality and integrity of the core data. At the same time, a differentiated encryption strategy is used to ensure the security of the key data and to balance the overall encryption efficiency, thereby providing high-security-level data support for subsequent persistent storage of core data and accurate recovery of application program state.
[0127] For example, if the third data is user sensitive information, a high-strength symmetric encryption algorithm can be used during encryption, and an encryption mode with integrity verification is used. First, an exclusive key and initialization information are created through a cryptographically secure random generation method to ensure that the initial conditions of each encryption are not repeated. Then each third data is converted into a standard encoding format, and then substituted into the above encryption algorithm for processing. A verification code for verifying that the data has not been tampered with is generated synchronously during the process. Finally, the initialization information, the verification code, and the encrypted result are combined in a fixed order to form the first encrypted data corresponding to each third data. At the same time, the exclusive key is stored separately in a secure server system to avoid problems caused by storing the key together with the encrypted data.
[0128] S2044, encrypting the plurality of fourth data to obtain a plurality of second encrypted data; wherein the encryption strength of encrypting the plurality of third data is greater than the encryption strength of encrypting the plurality of fourth data.
[0129] Specifically, an encryption mode suitable for the importance of the fourth data can be adopted, and a plurality of fourth data is safely processed through a preset lightweight encryption logic to generate corresponding second encrypted data. The encryption mode has a lower protection strength than the encryption processing strength of the third data. This step is used to avoid excessive encryption that causes resource consumption and processing efficiency to decline while ensuring the basic safety of non-core data, to balance data security protection and processing performance, and to complete the encryption processing of all data that needs to be persisted. This provides secure and efficient data support for subsequent differentiated storage and application program state recovery.
[0130] For example, if the fourth data is non-sensitive information of the user, a basic symmetric encryption algorithm can be used for encryption without additional complex verification mechanism. A fixed key bound to the application configuration is created without generating a new key for each encryption, and then each fourth data is converted into a simple encoding format and substituted into the basic encryption algorithm to complete the processing. No additional verification information is generated during the process. After encryption, only the simple encryption result is retained as the second encrypted data without combining other auxiliary information, which reduces the computational burden of the encryption process and the storage cost. At the same time, since the data itself has no sensitive information, the basic encryption strength can meet the security requirements.
[0131] The technical effect of this scheme in this embodiment is that the importance of each second data is determined according to the preset importance calculation rule, and the second data is divided into third data meeting the importance threshold and fourth data not meeting the importance threshold according to the preset importance threshold. The first encrypted data and the second encrypted data are obtained by encrypting the two types of data respectively, and the encryption strength of the third data is higher than that of the fourth data. On the basis of continuing the data persistence security and state recovery function, the precise matching of encryption strength and data importance is realized. The security protection level of core important data is guaranteed by high-strength encryption, and the resource consumption and efficiency loss caused by excessive encryption of secondary data are avoided.
[0132] In a possible design, S2043, the plurality of third data is encrypted to obtain a plurality of first encrypted data, including:
[0133] S20431, obtaining the data types of the plurality of third data.
[0134] Specifically, the attribute characteristics and functional association information of the plurality of third data can be analyzed through a preset type identification mechanism to determine the category of each third data and complete the data type acquisition. This step provides a core basis for subsequent matching and adaptation of encryption rules based on data types, ensures the precise fit of encryption rules and attribute characteristics of third data, improves the pertinence and security of core data encryption, and guarantees the effectiveness and rationality of high-strength encryption processing.
[0135] S20432, based on the data types of the plurality of third data, matching the plurality of third data with a plurality of preset encryption rules to obtain a target encryption rule; wherein the target encryption rule is the rule with the highest matching degree among the plurality of encryption rules and the data types of the plurality of third data.
[0136] Specifically, the data type characteristics of the third data can be compared with the applicable data types corresponding to the preset encryption rules one by one, the degree of fit between the two is analyzed, the encryption rule with the strongest adaptability to the data type is screened out, and the encryption rule is determined as the target encryption rule. This step is used to match the encryption rule most suitable for the attribute characteristics of the important third data, ensure that the encryption method is highly adapted to the data type, improve the accuracy and security of core data encryption, avoid encryption failure or insufficient protection caused by mismatch between encryption rule and data type, and provide a scientific basis for subsequent high-intensity encryption processing.
[0137] For example, assuming that the multiple third data are sensitive information submitted by a user, the specific data types include personal identity information and account security information, and the preset multiple encryption rules include three categories: the first category of rules is applicable to identity-related data that needs to be prevented from being tampered with, requires adding a data association verification identifier during encryption, the second category of rules is applicable to account data that needs to trace modification records, requires attaching an operation timestamp during encryption, and the third category of rules is applicable to user behavior data that only needs basic security, only requires simple symmetric encryption. First, the type of each third data is determined, and it is confirmed that it belongs to identity-related data or account security-related data. Then, the data types are compared with the applicable scenarios of the three categories of preset rules one by one, and it is found that the identity-related data tamper-proofing scenario of the first category of rules has the highest coincidence degree with the type attribute of the third data, which covers the security needs of identity information and ensures that the name and identity card information are not split and tampered with through the association verification identifier, which is higher than the second category of rules and the third category of rules. Finally, the first category of rules is determined as the target encryption rule.
[0138] S20433, encrypt the multiple third data according to the target encryption rule to obtain multiple first encrypted data.
[0139] Specifically, the encryption logic, operation process and security protection parameters set by the target encryption rule can be followed to perform encryption processing in combination with the attribute characteristics of the third data, and the security transformation of the multiple third data is completed through the rule-adapted encryption step to generate corresponding first encrypted data. This step is used to provide high-intensity encryption protection highly adapted to the type of important third data, ensure that the core data can obtain accurate and effective security protection during the encryption process, maximize the protection of its confidentiality and integrity, and avoid security problems caused by improper encryption method.
[0140] The technical effect of the scheme in the embodiment is: by first acquiring the data types corresponding to the plurality of third data, then comparing the data types with the plurality of preset encryption rules, screening out a target encryption rule with the highest matching degree, and encrypting the plurality of third data according to the target encryption rule to obtain first encrypted data, on the basis of continuing high-intensity encryption of the core data, precise adaptation of the encryption rule to the data type is realized, the encryption mode of the core data is more suitable for its own attribute characteristics, and the pertinence and security of core data encryption are improved.
[0141] Figure 2 Flowchart of the data persistence method provided by the embodiment of the application Figure 2 In the embodiment, in Figure 4 On the basis of the provided embodiment, the data persistence method is further explained. The data persistence method comprises:
[0142] S301, initializing a preset application program to obtain an initialized application program, and acquiring a plurality of initial data; wherein the initialization is used to adjust the state of the application program to a preset initialization state, and the plurality of initial data refers to configuration data of the initialized application program.
[0143] S302, in response to a first user operation, triggering a business process corresponding to the first user operation, and calling a state change tool corresponding to the business process to modify a plurality of first data to obtain a plurality of modified data and a modified state; wherein the plurality of initial data comprises the plurality of first data, and the plurality of modified data is a data set composed of data that is not modified in the plurality of initial data and data obtained by modifying the plurality of first data.
[0144] S303, in response to the state of the application program changing from the initialization state to the modified state, acquiring a plurality of second data; wherein the plurality of second data refers to data of a preset state field or module in the plurality of modified data that needs to be encrypted and persisted.
[0145] S304, encrypting the plurality of second data to obtain a plurality of encrypted data, and storing the plurality of encrypted data to a preset local storage medium, so that the application program is recovered to the modified state according to the plurality of encrypted data after refreshing or restarting.
[0146] S301-S304 are similar to S201-S204, and the embodiment will not be described again.
[0147] S305, in response to refreshing or restarting of the application program, acquiring the plurality of encrypted data.
[0148] Specifically, when it is detected that the application program is refreshed or restarted, the preset local storage medium can be automatically accessed, the previously stored encrypted data can be read, and the acquisition of multiple encrypted data can be completed. This step is used to provide core data support for subsequent decryption processing, application program state recovery or repair, and ensures that the application program can obtain historical persistent data after the running state is reset, and lays a foundation for subsequent recovery to the previous modified state or abnormal repair based on the data.
[0149] S306, decrypting the encrypted data to obtain a decryption result and multiple decrypted data; wherein the decryption result includes success and failure.
[0150] Specifically, the decryption logic corresponding to the encryption process and the adapted decryption method can be used to analyze and process the obtained encrypted data, to verify the execution result of the decryption operation synchronously, and to obtain the feedback of whether the decryption is successful and the restored original data. This step is used to provide a judgment basis and effective data support for application program state recovery or repair. When the decryption is successful, the historical running state can be recovered based on the restored data, and when the decryption fails, a subsequent abnormal processing process is triggered, thereby guaranteeing the rationality and effectiveness of the application program state repair.
[0151] S307, in response to the decryption result being successful, performing state recovery on the application program according to the multiple decrypted data, so that the state of the application program is recovered to the modified state.
[0152] Specifically, the original data obtained after successful decryption can be associated and matched with the state configuration item of the application program, the data corresponding to each configuration parameter, interaction record and function module state can be loaded according to the preset state recovery rule, the running parameters and interface display information of the application program can be updated synchronously, and the state recovery operation can be completed. This step is used to accurately restore the modified state of the application program before refreshing or restarting, so that the user can continue to use the process without re-executing the previous operation, thereby guaranteeing the coherence of the application program running and the consistency of the user experience.
[0153] S308, in response to the decryption result being failed, excluding the multiple decrypted data and acquiring multiple remote data; wherein the excluding the multiple decrypted data means that the multiple decrypted data is not used when the state of the application program is recovered, and the multiple remote data means the data stored in the preset remote server, and the multiple remote data is used for state repair of the application program when the decryption result is failed.
[0154] Specifically, after confirming that the decryption result is a failure, the decryption data can be marked as unusable by a preset invalid data processing rule, so as to prevent the decryption data from participating in the state recovery process of the application program, and a connection with a preset remote server is established to request and obtain backup data for state repair. This step is used to exclude invalid data in a timely manner to avoid affecting the state repair effect when the local encrypted data cannot be effectively decrypted, and to obtain reliable remote backup data to provide necessary support for subsequent combination of initial data to complete the state repair of the application program, thereby ensuring that the application program can still recover to a normal working state in a decryption exception scenario.
[0155] S309, state repair of the application program according to the plurality of remote data and the plurality of initial data, so that the state of the application program recovers to a preset normal working state.
[0156] Specifically, the obtained remote backup data can be fused and adapted with the initial basic data of the application program, and the core configuration information and functional module parameters of the application program can be supplemented and improved according to a preset state repair rule, with the initial data as a running reference, in combination with the remote data, to synchronously update the key configurations related to the running state, complete the state repair of the application program, and recover it to a preset normal working state. This step is used to provide a reliable state repair scheme for the application program through the cooperative support of the basic data and the remote backup data in a scenario where the local encrypted data fails to be decrypted and the history modification state cannot be recovered, so as to ensure that the application program can normally start and run, avoid the application program from being unable to use due to data decryption exceptions, and ensure the smooth development of subsequent user operations.
[0157] S310, in response to a second user operation, interacting with the application program recovered to a normal working state according to the second user operation.
[0158] Specifically, after the application program recovers to a preset normal working state, the operation instruction initiated by the user can be monitored in real time, the relevant running module of the application program can be called according to the function demand corresponding to the operation, the corresponding business processing process can be executed, and the operation result can be fed back to the user, so as to realize the effective interaction between the application program and the user operation. This step is used to ensure that the application program can normally respond to the subsequent use demand of the user after completing the state repair, to ensure the smooth execution of the user operation and the continuity of the use process, and to improve the usability of the application program and the user experience.
[0159] The technical effect of the scheme in this embodiment is: by first acquiring the locally stored encrypted data and decrypting it, processing according to the decryption result, if decryption is successful, restoring the application program to the modified state based on the decrypted data, if decryption fails, excluding invalid decryption data and acquiring preset data stored on the remote server, combining the initial data to repair the state of the application program to the normal working state, and after repair, responding to subsequent user operations, the dual-path mechanism of decryption success recovery-decryption failure repair improves the reliability and fault tolerance of state recovery, ensuring that the application program can quickly recover to the normal working state regardless of whether the decryption is successful, avoiding user operation interruption or data loss.
[0160] In a possible design, the normal working state includes an initialization state and a non-initialization state, and S309, state repair of the application program according to the plurality of remote data and the plurality of initial data to restore the state of the application program to a preset normal working state, includes:
[0161] S3091, acquiring a network connection state between the state management library and the remote server; wherein the network connection state includes connected and disconnected.
[0162] Specifically, a network connectivity detection request can be initiated by the state management library to the remote server to verify whether the communication link between the two is smooth, and then determine the current state of the network connection, which provides a basis for selecting the state repair path of the application program, ensuring that the corresponding repair scheme is adapted according to the actual network environment, so that the application program can be accurately restored to the preset normal working state, ensuring the effectiveness and adaptability of state repair.
[0163] S3092, in response to the network connection state being connected, state repair of the application program according to the plurality of initial data to restore the state of the application program to the initialization state.
[0164] Specifically, after confirming that the network connection state is connected, the initial data is used as a reference to load the corresponding basic configuration parameters, reset the function module state of the application program to a preset initial reference, and synchronize the update of the core configuration information required for running, to complete the state repair of the application program and restore it to the initialization state. This step is used to rely on the stability and normativity of the initial data in the scenario where the network environment is smooth, to ensure that the application program is restored to the preset basic running state, providing a unified and reliable starting point for subsequent user operations.
[0165] S3093, in response to the network connection state being disconnected, state repair of the application program according to the plurality of remote data to restore the state of the application program to a non-initialization state, which refers to a state other than the initialization state in the normal working state.
[0166] Specifically, after confirming that the network connection state is disconnected, the historical valid configuration information and the function module running parameters stored in the remote data are loaded, the core running configuration, the interaction record and the function module state of the application program are synchronously updated according to the preset non-initialization state repair rule, the state repair of the application program is completed, and the application program is restored to the normal working state except the initialization state. This step is used to guarantee that the application program can still be restored to the normal working state in the scene where the network cannot be connected, avoid that the application program cannot be started or the function is limited due to the network disconnection, and ensure the continuity of the subsequent operation of the user and the usability of the application program.
[0167] The normal working state refers to a complete runtime state of the application program, in which the application program is started, all necessary user data and configurations are loaded, and all core functions can be normally operated and used by the user. The initialization state specifically refers to the most basic state of the application program when it is just started and has not loaded any user data or personalized configuration, which is usually manifested as a blank interface, default setting or login state. The non-initialization state refers to any valid intermediate state between the initialization state and the complete normal working state, which contains part of the restored or cached data and configuration, enables the user to perform limited but continuous operation, and is characterized by skipping the blank or default stage of the initialization, restoring part of the user context, but not necessarily having all the latest data or complete functions when connected to the network. The three states constitute the recovery ladder of the application program after startup: from the blank initialization state, to the non-initialization state with part of the data restored, and finally to the normal working state with complete data and complete functions.
[0168] For example, taking a local note synchronization application as an example, the core function of the application is to allow users to edit notes and synchronize them to a remote server, while supporting the viewing of historical notes on the device side. When the network connection is normal, the application automatically saves the remote data obtained by the user from the remote server to the local device through the persistent storage module, and these data are all valid data synchronized from the remote server when the network is normal. The application compares the differences between the local and remote data each time it is connected to the network, updates the local cache, and ensures that the cached remote data copy is consistent with the server side. When the user opens the application next time, the application discovers through the built-in network detection function that the network connection state is disconnected, and at this time the application returns to the initialization state due to device restart, triggering the state repair process: at this time, the application does not attempt to connect to the remote server that has been disconnected, but directly calls the remote data copy stored in the local cache, sorts the cached note content by editing time to generate a historical note list, loads the recently edited note content to display in the editing area, and restores the display of note classification tags, finally making the application skip the blank state of initialization and restore to the non-initialization state of "viewing all historical notes and continuing to edit the latest note" when the user normally uses it. The "remote data" used for repair is the remote data copy cached locally when the network is normal, and does not need to be obtained from the server in real time when the network is disconnected.
[0169] The technical effect of this scheme in this embodiment is that the normal working state is subdivided into an initialization state and a non-initialization state, and the network connection state between the state management library and the remote server is obtained when repairing, and different repair schemes are adapted according to different network connection states: the application program is repaired to the initialization state based on the initial data when the network is connected, and the application program is repaired to the non-initialization state based on the remote data when the network is disconnected, realizing accurate adaptation to different network environments and solving the repair failure problem that may be caused by network state differences.
[0170] It should be noted that:
[0171] Vuex is a state management library designed specifically for Vue.js, providing a centralized state management pattern suitable for managing complex component states. It follows the concepts of single-directional data flow architecture such as Flux and Redux, storing the state of the application in a global warehouse (Store), ensuring the predictability and consistency of data flow. Its core is to store data through State, modify state through Mutation and Action, and finally obtain and derive data through Getter.
[0172] Flux is an application state management design pattern based on the concept of one-way data flow, used to regulate the logic of data flow in complex applications. Redux is a front-end state management library based on the simplification of the Flux architecture, which realizes centralized management of application state. The complete data flow process of Vuex is as follows:
[0173] 1. Initialize data (State).
[0174] The shared data of the application is saved in the global state State of Vuex, and all components can access these shared data by accessing the State.
[0175] 2. Trigger Action (user input or asynchronous operation).
[0176] Components trigger Actions through the dispatch method.
[0177] Actions can contain asynchronous logic (such as API requests, timers, etc.), and then call Mutations to modify the state.
[0178] 3. Perform Mutation (synchronous state modification).
[0179] Actions trigger Mutations through the commit method to directly modify the State.
[0180] Mutations must be synchronous operations to facilitate debugging and state tracking.
[0181] 4. Update State (state update).
[0182] After the global state State of Vuex is modified, all components using the state will automatically respond to reactive updates.
[0183] 5. Derive data (Getter).
[0184] Components get processed data from State through Getter, which is used to simplify state calculation logic.
[0185] 6. Component rendering update.
[0186] Vue's reactive mechanism detects changes in State and triggers component re-rendering.
[0187] Figure 1 Vuex state management data flow diagram provided for the embodiments of the present application Figure 4 , for example Figure 5As shown, it clearly shows the core process of Vuex (a state management library) in a Vue.js application and the interaction between modules: Vue components trigger Actions in Vuex through dispatch, Actions can handle asynchronous logic (such as data interaction with Backend API), and then Actions call Mutations through commit; Mutations are the only entry point for synchronously modifying the global state State, and the developer tool (Dev Tools) can monitor Mutations to realize state debugging and tracking; when the State (the global shared state of Vuex) is modified by Mutations, the responsive mechanism of Vue will trigger the Vue components that depend on the state to re-render, finally completing the complete flow of the entire state from triggering, processing to updating components, embodying the core role of Vuex in centralized management of shared state and ensuring the predictability of data flow.
[0188] However, it is limited to front-end state management: Vuex, as a front-end state management tool, although it is effective in managing global state within the same application, it cannot directly provide persistence functions. Vuex does not support cross-page, cross-tab synchronization: Vuex's state management is a state management solution for single-page applications and does not support cross-page or cross-tab synchronization of state.
[0189] Therefore, Vuex can be adjusted by the following steps:
[0190] 1. State initialization:
[0191] Vuex initializes the global state and provides the initial data of the application.
[0192] 2. State change:
[0193] User operations trigger Actions of Vuex, which modify the state through Mutations.
[0194] 3. Encryption and persistent storage:
[0195] After the state changes, the invention intercepts the specified state field or module.
[0196] The state data is encrypted by the encryption module and stored in the local storage (local Storage) of the browser, according to the business needs, not all data must be encrypted and decrypted.
[0197] 4. Recovery and decryption:
[0198] When the page is refreshed or the application is reloaded, the Persisted State module obtains the encrypted data from the storage.
[0199] Data is decrypted by the decryption module:
[0200] a. Decryption is successful:
[0201] If decryption is successful, the decrypted data is restored to the Vuex State for component use. Step 5 is performed.
[0202] b. Decryption fails (data is tampered with):
[0203] The data is not encrypted with the correct key (tampered with).
[0204] The data structure is incomplete (storage error or human modification).
[0205] Processing method:
[0206] Discard the invalid data extracted.
[0207] Initialize to default data in state management, or re-pull the required data through asynchronous calls (for example: reload user configuration or session data from the server). By calling the server-side API or the default logic of the application, the initial state data is reacquired, and step 1 is repeated.
[0208] 5. Interaction with components:
[0209] Components read state data through Vuex's State or Getters and interact with users.
[0210] Figure 2 Vuex state management data flow provided for the embodiments of the present application Figure 5 , for example Figure 6As shown in the figure, the figure takes the basic Vuex process as the core, that is, Vue components trigger Actions, Actions call Mutations to modify State, State drives component rendering, Dev Tools monitors state, and Actions interacts with Backend API, and adds state encryption persistence and recovery mechanism: when the Vuex State changes, the specified field / module will be intercepted, encrypted by the Encrypt Module, and stored by the Persist State Module (such as local Storage). When the page is refreshed or the application is restarted, the Persist State Module extracts encrypted data from the storage, decrypts it by the Decrypt Module, and if the decryption is successful, the data is restored to the State for component use, and if the decryption fails, the damaged data is discarded or the data is pulled to update the State. The whole process not only retains the predictability of Vuex centralized state management, but also enhances the security and data continuity of the client state through encryption and decryption and persistence. This adjustment can achieve:
[0211] 1. Data persistence:
[0212] Data is not lost after page refresh: the default state of Vuex is stored in memory, and the data will be lost after page refresh or browser closing. Persistence can save data to the browser's storage to ensure that data is still available after page refresh.
[0213] Improve user experience, users do not need to re-enter or load state.
[0214] Session and long-term storage support: the persistence mechanism allows switching between session Storage (short-term storage) and localStorage (long-term storage) to meet different scene needs.
[0215] 2. Improve user experience:
[0216] State retention: the state remains after the user closes the page or browser, for example:
[0217] Login status.
[0218] Intermediate state of form filling.
[0219] User preferences (such as theme mode, language selection, etc.).
[0220] Users can directly continue the unfinished operation when they reopen the page.
[0221] Offline Support: Persistence allows users to continue accessing and manipulating stored data even in offline state, without network connection, without affecting the basic functionality of the application. This is particularly important in PWA (Progressive Web App).
[0222] 3. Reduced Server Requests:
[0223] Reduced Server Load: By persistently storing user data, the need to frequently request the same data from the server is reduced. For example:
[0224] Local storage of user preferences or cached API data.
[0225] Improved application performance while reducing server stress.
[0226] Reduced Repetitive Loading: Users do not need to reload and initialize data every time they access a page.
[0227] 4. Improved Data Security:
[0228] Integrity Verification: Verify the integrity of data through decryption operations to prevent tampered data from misleading application logic.
[0229] Prevent Sensitive Data Leakage: If data is modified or damaged in browser storage, the system will discard these data. Only valid data generated by the encryption module will be restored to the application state, ensuring data security.
[0230] 5. Data Consistency Guarantee:
[0231] Active Discarding of Invalid Data: If data decryption fails or cannot pass verification, immediately discard invalid data to avoid the impact of incorrect data on application logic.
[0232] Pull Data Again: Get data from the server again to ensure that the application can recover a consistent and reliable state.
[0233] 6. Automation, Reduce User Intervention:
[0234] Seamless Data Recovery:
[0235] In the case of decryption failure, the system will automatically discard invalid data and trigger the logic to pull data again, without the need for user manual operation.
[0236] Improved user experience, avoiding users facing chaotic state due to local data problems.
[0237] Transparent Processing: The entire verification, discarding and recovery process is completely transparent to users and will not affect normal user operations.
[0238] Local storage can be replaced with indexed DB.
[0239] Indexed DB is a low-level API provided by browsers, which allows storing large amounts of structured data (such as JSON objects). Unlike local storage, it is asynchronous and suitable for large data storage in complex scenarios. The advantages are: support for large capacity storage, not limited to 5~10MB (can store hundreds of MB of data, depending on the browser); support for indexed queries, providing database-like capabilities; asynchronous operation, avoiding blocking the main thread; more suitable for complex application scenarios, such as Progressive Web App (PWA), offline support, etc.
[0240] The disadvantages are: the API is complex, and the learning cost is high; for simple storage needs, it may be too complex. Suitable scenarios are: the need to store large amounts of structured data (such as caching API data, offline documents, etc.); the need for high-performance query capabilities.
[0241] Figure 3 The structure diagram of the data persistence device provided by the embodiment of the application is shown in FIG. 1. Figure 2 As shown in the figure, the data persistence device comprises:
[0242] The initialization module 601 is configured to initialize a preset application program to obtain an initialized application program and acquire a plurality of initial data; wherein the initialization is configured to adjust the state of the application program to a preset initialization state, and the plurality of initial data refers to configuration data of the initialized application program.
[0243] The modification module 602 is configured to trigger a business process corresponding to a first user operation in response to the first user operation, and call a state change tool corresponding to the business process to modify a plurality of first data to obtain a plurality of modified data and a modified state; wherein the plurality of initial data comprises the plurality of first data, and the plurality of modified data is a data set composed of unmodified data in the plurality of initial data and data obtained by modifying the plurality of first data.
[0244] The first acquisition module 603 is configured to acquire a plurality of second data in response to the state of the application program being converted from the initialization state to the modified state; wherein the plurality of second data refers to data of a preset state field or module in the plurality of modified data that needs to be encrypted and persisted.
[0245] The encryption module 604 is configured to encrypt the plurality of second data to obtain a plurality of encrypted data, and store the plurality of encrypted data in a preset local storage medium, so that the application program can be restored to the modified state according to the plurality of encrypted data after being refreshed or restarted.
[0246] In a possible design, the data persistence apparatus further includes:
[0247] The second obtaining module is configured to obtain the plurality of encrypted data in response to the application program being refreshed or restarted.
[0248] The decryption module is configured to decrypt the encrypted data to obtain a decryption result and a plurality of decrypted data; the decryption result includes success and failure.
[0249] The recovery module is configured to perform state recovery on the application program according to the plurality of decrypted data in response to the decryption result being success, so that the state of the application program is recovered to the modified state.
[0250] The third obtaining module is configured to exclude the plurality of decrypted data and obtain a plurality of remote data in response to the decryption result being failure; the excluding the plurality of decrypted data means that the plurality of decrypted data is not used when the state recovery is performed on the application program, and the plurality of remote data means data stored in a preset remote server, and the plurality of remote data is used to perform state repair on the application program in response to the decryption result being failure.
[0251] The repair module is configured to perform state repair on the application program according to the plurality of remote data and the plurality of initial data, so that the state of the application program is recovered to a preset normal working state.
[0252] The interaction module is configured to interact with the second user operation according to the application program recovered to the normal working state in response to a second user operation.
[0253] In a possible design, the normal working state includes an initialization state and a non-initialization state, and the repair module includes:
[0254] The first obtaining unit is configured to obtain a network connection state between the state management library and the remote server; the network connection state includes connection and disconnection.
[0255] The first repair unit is configured to perform state repair on the application program according to the plurality of initial data in response to the network connection state being connection, so that the state of the application program is recovered to the initialization state.
[0256] The second repair unit is configured to perform state repair on the application program according to the plurality of remote data in response to the network connection state being disconnection, so that the state of the application program is recovered to the non-initialization state, which is a state other than the initialization state in the normal working state.
[0257] In a possible design, the encryption module 604 includes:
[0258] The second obtaining unit is configured to obtain a plurality of historical encrypted data; wherein the plurality of historical encrypted data refers to encrypted data stored to the local storage medium last time.
[0259] The comparison unit is configured to compare the plurality of encrypted data with the plurality of historical encrypted data to obtain a plurality of changed data; wherein the plurality of changed data refers to data in the plurality of encrypted data that is changed compared with the plurality of historical encrypted data.
[0260] The storage unit is configured to store the plurality of changed data to the local storage medium.
[0261] In a possible design, the plurality of encrypted data includes a plurality of first encrypted data and a plurality of second encrypted data, and the encryption module 604 includes:
[0262] The calculation unit is configured to calculate the importance of each second data according to a preset importance calculation rule.
[0263] The classification unit is configured to classify the plurality of second data according to the importance of each second data to obtain a plurality of third data and a plurality of fourth data; wherein the plurality of third data refers to data in the plurality of second data whose importance is greater than or equal to a preset importance threshold, and the plurality of fourth data refers to data in the plurality of second data whose importance is less than the importance threshold.
[0264] The first encryption unit is configured to encrypt the plurality of third data to obtain the plurality of first encrypted data.
[0265] The second encryption unit is configured to encrypt the plurality of fourth data to obtain the plurality of second encrypted data; wherein the encryption strength of encrypting the plurality of third data is greater than the encryption strength of encrypting the plurality of fourth data.
[0266] In a possible design, the first encryption unit includes:
[0267] The obtaining component is configured to obtain the data type of the plurality of third data.
[0268] The matching component is configured to match the plurality of third data with a plurality of preset encryption rules based on the data type of the plurality of third data to obtain a target encryption rule; wherein the target encryption rule refers to a rule in the plurality of encryption rules that has the highest matching degree with the data type of the plurality of third data.
[0269] The encryption component is configured to encrypt the plurality of third data according to the target encryption rule to obtain the plurality of first encrypted data.
[0270] The data persistence apparatus provided in this embodiment can perform Figure 2 The technical scheme of the data persistence method embodiment shown in FIG. 8 has the same implementation principles and technical effects as the data persistence apparatus provided in this embodiment. Figure 7An embodiment of the data persistence method is shown, and details are not repeated here.
[0271] Figure 7 A hardware structure schematic diagram of an electronic device is provided for the embodiment of the present application. As shown in the figure, The electronic device 70 includes at least one processor 701 and a memory 702. The electronic device 70 also includes a communication component 703. The processor 701, the memory 702, and the communication component 703 are connected through a bus 704.
[0272] In the implementation process, the at least one processor 701 executes the computer execution instructions stored in the memory 702, so that the at least one processor 701 is used to implement the data persistence method of the above-mentioned embodiment.
[0273] The specific implementation process of the processor 701 can refer to the above-mentioned method embodiment, which has similar implementation principles and technical effects, and details are not repeated here.
[0274] In the above-mentioned embodiment, it should be understood that the processor 701 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in combination with the application can be directly embodied as hardware processor execution, or executed by hardware and software modules in the processor.
[0275] The memory 702 can contain a high-speed RAM memory, and can also include a non-volatile storage NVM, such as at least one disk memory.
[0276] The bus 704 can be an industry standard architecture (ISA) bus, a peripheral component (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus 704 can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, the bus 704 in the drawings of the present application does not limit to only one bus or one type of bus.
[0277] The functions implemented by the electronic device and the host device are described above, and the scheme provided by the embodiments of the present application is introduced. It can be understood that, in order to implement the above functions, the electronic device or the host device comprises a hardware structure and / or a software module corresponding to the execution of each function. In combination with the units and algorithm steps of each example described in the embodiments of the present application, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or in the form of computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the technical solutions of the embodiments of the present application.
[0278] The embodiments of the present application also provide a computer readable storage medium, and the computer readable storage medium stores computer execution instructions. When the computer execution instructions are executed by a processor, a data persistence method is implemented. In the specific implementation of the foregoing data persistence method, each module can be implemented as a processor.
[0279] The foregoing readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0280] An exemplary readable storage medium is coupled to the processor, so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in the electronic device or the host device.
[0281] The embodiments of the present application also provide a computer program product, which comprises a computer program. When the computer program is executed by a processor, a data persistence method is implemented.
[0282] The computer program is stored in a readable storage medium, and at least one processor can read the computer program from the readable storage medium. The at least one processor executes the computer program to perform the scheme provided by any of the foregoing embodiments.
[0283] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware. The foregoing program can be stored in a computer readable storage medium. The program executes to perform the steps of the above-mentioned method embodiments; and the foregoing storage medium includes various storage media that can store program codes, such as ROM, RAM, magnetic disk or optical disk.
[0284] So far, the technical solutions of the present application have been described in combination with the preferred embodiments shown in the drawings, but those skilled in the art can easily understand that the protection scope of the present application is obviously not limited to these specific embodiments, and the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A data persistence method, characterized by, The application relates to a state management library applied to a data persistence system, the data persistence system also comprising a user terminal, and the method comprises the following steps: An application program is initialized to obtain an initialized application program, and a plurality of initial data are acquired; wherein the initialization is used for adjusting the state of the application program to a preset initialization state, and the plurality of initial data are configuration data of the initialized application program; In response to a first user operation, a business process corresponding to the first user operation is triggered, and a state change tool corresponding to the business process is called to modify a plurality of first data, so that a plurality of modified data and a modified state are obtained; wherein the plurality of initial data comprise the plurality of first data, and the plurality of modified data are a data set composed of unmodified data in the plurality of initial data and data obtained by modifying the plurality of first data; In response to the state of the application program being changed from the initialization state to the modified state, a plurality of second data are acquired; wherein the plurality of second data are data of preset state fields or modules in the plurality of modified data which need to be encrypted and persisted; The plurality of second data are encrypted to obtain a plurality of encrypted data, and the plurality of encrypted data are stored in a preset local storage medium, so that the application program can be restored to the modified state according to the plurality of encrypted data after refreshing or restarting.
2. The data persistence method of claim 1, wherein, After the plurality of encrypted data are stored in the preset local storage medium, the following steps are further included: In response to the application program being refreshed or restarted, the plurality of encrypted data are acquired; The encrypted data are decrypted to obtain a decryption result and a plurality of decrypted data; wherein the decryption result comprises success and failure; In response to the decryption result being the success, the state of the application program is restored according to the plurality of decrypted data, so that the state of the application program is restored to the modified state; In response to the decryption result being the failure, the plurality of decrypted data are excluded, and a plurality of remote data are acquired; wherein the plurality of decrypted data are excluded, that is, the plurality of decrypted data are not used when the state of the application program is restored, and the plurality of remote data are data stored in a preset remote server, and the plurality of remote data are used for state repair of the application program when the decryption result is the failure; The state of the application program is repaired according to the plurality of remote data and a plurality of initial data, so that the state of the application program is restored to a preset normal working state; In response to a second user operation, the application program restored to the normal working state is interacted with the second user operation.
3. The data persistence method of claim 2, wherein, The normal working state comprises the initialization state and a non-initialization state, and the state of the application program is repaired according to the plurality of remote data and the plurality of initial data, so that the state of the application program is restored to the preset normal working state, which comprises the following steps: A network connection state between the state management library and the remote server is acquired; wherein the network connection state comprises connection and disconnection. in response to the network connection state being the connected, performing state repair on the application according to the plurality of initial data, so as to restore the state of the application to the initialization state; in response to the network connection state being the disconnected, performing state repair on the application according to the plurality of remote data, so as to restore the state of the application to the non-initialization state, the non-initialization state being a state other than the initialization state in the normal working state.
4. The data persistence method of claim 1, wherein, The storing of the plurality of encrypted data to the preset local storage medium comprises: obtaining a plurality of historical encrypted data; wherein the plurality of historical encrypted data refers to encrypted data stored to the local storage medium last time; comparing the plurality of encrypted data with the plurality of historical encrypted data to obtain a plurality of changed data; wherein the plurality of changed data refers to data in the plurality of encrypted data that has changed compared with the plurality of historical encrypted data; storing the plurality of changed data to the local storage medium.
5. The data persistence method of claim 2, wherein, The plurality of encrypted data comprises a plurality of first encrypted data and a plurality of second encrypted data, and the encrypting of the plurality of second data to obtain a plurality of encrypted data comprises: calculating the importance of each second data according to a preset importance calculation rule; classifying the plurality of second data according to the importance of each second data to obtain a plurality of third data and a plurality of fourth data; wherein the plurality of third data refers to data in the plurality of second data whose importance is greater than or equal to a preset importance threshold, and the plurality of fourth data refers to data in the plurality of second data whose importance is less than the importance threshold; encrypting the plurality of third data to obtain the plurality of first encrypted data; encrypting the plurality of fourth data to obtain the plurality of second encrypted data; wherein the encryption strength of encrypting the plurality of third data is greater than the encryption strength of encrypting the plurality of fourth data.
6. The data persistence method of claim 5, wherein, The encrypting of the plurality of third data to obtain the plurality of first encrypted data comprises: obtaining the data type of the plurality of third data; based on the data type of the plurality of third data, matching the plurality of third data with a plurality of preset encryption rules to obtain a target encryption rule; wherein the target encryption rule refers to a rule in the plurality of encryption rules that has the highest matching degree with the data type of the plurality of third data; encrypting the plurality of third data according to the target encryption rule to obtain the plurality of first encrypted data.
7. A data persistence apparatus, characterized by, A state management library applied to a data persistence system, the data persistence system further comprising a user end, the device comprising: an initialization module configured to initialize a preset application to obtain an initialized application and obtain a plurality of initial data; wherein the initialization is configured to adjust the state of the application to a preset initialization state, and the plurality of initial data refers to configuration data of the initialized application; The modification module is configured to, in response to a first user operation, trigger a business process corresponding to the first user operation, and invoke a state change tool corresponding to the business process to modify a plurality of first data, to obtain a plurality of modified data and a modified state; wherein the plurality of initial data includes the plurality of first data, and the plurality of modified data is a data set composed of unmodified data in the plurality of initial data and data obtained after modification of the plurality of first data; The first obtaining module is configured to, in response to a state of the application program being changed from the initial state to the modified state, obtain a plurality of second data; wherein the plurality of second data refers to data of a preset state field or module in the plurality of modified data that needs to be encrypted and persisted; The encryption module is configured to encrypt the plurality of second data to obtain a plurality of encrypted data, and store the plurality of encrypted data to a preset local storage medium, so that the application program is recovered to the modified state according to the plurality of encrypted data after being refreshed or restarted.
8. An electronic device, comprising: Comprise: A processor, and a memory connected with the processor in communication; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, to implement the data persistence method of any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to implement the data persistence method of any one of claims 1 to 6.
10. A computer program product, characterised in that, The computer program is executed by the processor to implement the data persistence method of any one of claims 1 to 6.