A data persistent storage method based on a web database

By initializing the local database on the client, using HTML5 storage or cookie storage, and combining the internal service providers and database managers of the space to realize local storage and remote synchronization of data, the problem of high server pressure and poor compatibility in the existing technology is solved, and the user experience and system performance are improved.

CN114254235BActive Publication Date: 2025-06-13HANGZHOU DIANZI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111560360.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-20
Publication Date
2025-06-13
Estimated Expiration
2041-12-20

AI Technical Summary

Technical Problem

The existing data persistence technical solutions in the Internet environment with high concurrency, high availability, and demanding user experience, resulting in excessive server pressure, high cost, poor compatibility and insufficient storage standardization.

Method used

The data persistent storage method based on web database is adopted. By initializing the local database on the client, using HTML5 storage or cookie storage, combined with the internal service provider and database manager of the space, local storage and remote synchronization of data are achieved, reducing server pressure.

Benefits of technology

Effectively reduces server pressure, improves user experience, realizes local storage and remote synchronization of data, has good compatibility, and is suitable for offline applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114254235B_ABST
    Figure CN114254235B_ABST
Patent Text Reader

Abstract

The present invention discloses a data persistent storage method based on a web database, belonging to the technical field of Internet software, and specifically relates to a front-end data storage method with good compatibility and simplicity and ease of use. Based on the web Storage API and combined with the JSON language, the present invention transforms localStorage, abstracts a management space class, manages the initialization data of the space and the establishment and insertion rules of the space, and additionally sets up an internal service provider in the space to complete the specific data operation functions, making it an application with database characteristics. Compared with the previous server-side storage solutions, the present invention effectively saves server bandwidth, alleviates server pressure, significantly helps to improve system performance, and is more convenient to use by setting up a local storage transfer station between the client and the server.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of Internet software, and particularly relates to a data persistent storage method based on a web database. Background Art

[0002] With the rapid development of Internet technology, software application functions are becoming more complex, data interaction is becoming more frequent, and the requirements for user experience are also getting higher and higher. The requirements for the performance of high concurrency, high availability, high performance, and high scalability of back-end services are also becoming more and more stringent. Previous data storage solutions have focused on the server side, resulting in an increasing server pressure. Although the current hardware upgrade cost is not high, blindly increasing machines to relieve the pressure will result in unpredictable and high costs. Combining with a web database for effective technical optimization solutions is the solution.

[0003] Existing data persistent technology solutions can be summarized as follows: 1) Completely rely on server-side storage. When operating data frequently, the server pressure is too high. 2) Use HTTP negotiation caching. Here, the negotiation method is controlled by the Last-Modified and Etag of the Http protocol. When requesting the server, if the content has not changed, the server returns a 304 response. Although the data transmission is simplified through a simple response, a request connection still needs to be sent to the server, and the problem is not fundamentally solved. 3) Use webSQL for local storage. A local database application can be directly implemented in the browser or client, but the compatibility is poor, and the support for it among browsers has not been standardized. 4) Simply use the webStorgeAPI. This method can only achieve the storage of simple data, and it will be obviously powerless when the data volume is large or complex.

[0004] Therefore, it is necessary to implement a method with good compatibility, standardized storage, and the access function completely independent of the server side. Summary of the Invention

[0005] In view of the above problems, the present invention proposes a data persistent storage method based on a web database. The data is stored locally, which is easy to use, has good compatibility, effectively improves the user experience, relieves the server pressure, and since it can be decoupled from the server storage, it also means that it can still be used normally in offline applications.

[0006] To achieve the above object, the present invention adopts the following technical solutions:

[0007] A data persistent storage method based on a web database, comprising the following steps:

[0008] Step 1: Initialize the client environment;

[0009] Step 2: Determine the client environment. If HTML5 storage is supported, use the normal mode; otherwise, use the compatible mode to store data using cookies.

[0010] Step 3: Check if there is cached data in the local database. If not, initialize the local database, create a space internal service worker class and mount it globally. If so, send a pre-check request to synchronize the remote database data based on the local cache summary.

[0011] Step 4: Create a global management space class to manage space operation methods, and create a database manager to maintain the access to the space table.

[0012] Step 5: The management space class mounts the methods for creating a space (createSpace), deleting a space (deleteSpace), inserting data (insert), updating data (update), and deleting data (delete).

[0013] Step 6: Load the query function (select).

[0014] Step 7: Call the functions of the management space class to operate on the data, call the specific operation interfaces through the space internal service, generate new data, and calculate the cache summary based on the content of the generated new data.

[0015] Step 8: Register the new data after the operation through the database manager and store the data in the corresponding space.

[0016] Step 9: Synchronize the data between the local database and the remote database at regular intervals.

[0017] Furthermore, the space internal service is a method for specifically operating on data storage, and the instance objects of the space internal service are included in the built-in methods of the management space class.

[0018] Furthermore, the database manager is a table containing all the storage space names of the database, with the data type being an array, and each space information is included in the array. The space information is an object structure, containing data values and data content summaries.

[0019] Furthermore, the data content summary is a 128-bit string calculated by the Murmurhash hash function based on the data content, used as a marker for data summary. When synchronizing data, a pre-check request is sent based on the summary. If the summary changes, it indicates that the content is not synchronized, and the remote database and the local database perform data synchronization. If the summary remains unchanged, it indicates that the content has not changed, and no subsequent synchronization request is made.

[0020] The beneficial effects of the present invention are manifested in the following aspects: 1) Local storage is performed based on a web database, fundamentally reducing the server pressure; 2) An elegant degradation scheme is adopted. When the running environment is incompatible with the webStorage API, it automatically degrades to cookie storage. When it is incompatible with cookies, the data is automatically uploaded to the remote end; 3) Through the transformation of localStorage and combined with the JSON language features, the localStorage class has the characteristics of a database, which is beneficial to improving the overall performance of the system and has good compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a schematic structural diagram of the present invention;

[0022] Figure 2 is an internal flow chart designed by the present invention;

[0023] Figure 3 is a software design flow chart of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0024] The present invention will be described in detail below with reference to the accompanying drawings.

[0025] Refer to Figure 1 , a data persistent storage method based on a web database, and the overall architecture is as follows:

[0026] A local storage database is set up at the upper layer of the browser. Standalone applications do not need to connect to the remote database. Online applications can set up a database at the remote end to synchronize the data information between the remote end and the local end. When operating data, it is transferred through the local database, and the remote database is not operated. The data information between the remote end and the local end is synchronized regularly, avoiding the repeated operation of data, which increases the server pressure.

[0027] In this example, the database includes a management space class, a database space manager, and an internal space service provider.

[0028] The management space class is the main class of the entire database, mounted on the global window object, responsible for exposing the operation API interfaces, which include createSpace (create data space), deleteSpace (delete data space), insert (insert data), update (update data), delete (delete data), and select (query) methods.

[0029] The database space manager is data in JSON format stored in local memory, maintaining all stored space table information, and it can be retrieved through the internal space service provider.

[0030] The internal space service is a class defined using the ES6 specification. Its behavior is like basic SQL operations, with methods for storing, retrieving, deleting, and clearing data.

[0031] In this example, the logic of the database in the management space class is as follows:

[0032] 1) Create a data space design:

[0033] ① Initialize the database space manager, create an empty spaceObject array and convert it to JSON format using the JSON.stringify method. Initialize the memory space through the internal space service to maintain the space table for storage. If the database space manager already exists, skip this step.

[0034] ② Iterate through all spaceObjects, check if the new space already exists. If it exists, throw an error; otherwise, register the new space using the database space manager, save the new space name in the object data structure, retrieve the database space manager through the internal space service using JSON.parse, and add the new space object to the database space manager.

[0035] ③ Use the internal space service to create a value space with the name of the input parameter and store the data in local memory.

[0036] 2) Delete a data space design:

[0037] ① Check if the input parameter is of type String. If not, throw an error. Initialize the index of the space to be deleted as -1 and the deletion flag as FALSE.

[0038] ② Obtain the database space manager through the internal space service, get the space name table data in the space manager, and check if there is space data with the input parameter as the name by traversing. If it exists, reset the deletion flag to TRUE and the space name index to the traversal coefficient i.

[0039] ③ Find the data to be deleted, delete the space name table information, and update the space manager.

[0040] ④ Delete the space using the delete method of the internal space service.

[0041] 3) Insert data design:

[0042] Obtain the corresponding space through the internal space service, add data using the array method, and call the insert method of the internal space service.

[0043] 4) Update data design:

[0044] ① Obtain the corresponding space through the in-space service provider, retrieve the data stored in the space, convert it into an object through JSON.parse, and initialize the flag for the old data to be updated to -1.

[0045] ② Use the depth-first search algorithm DFS to traverse the object.

[0046] ③ If the old data to be updated is found, reset the flag and update the data through the in-space service provider; if not found, throw an error.

[0047] 5) Data deletion design:

[0048] ① Obtain the corresponding space through the in-space service provider, retrieve the data stored in the space, convert it into an object through JSON.parse, and initialize the flag for the data to be deleted to -1.

[0049] ② Use the breadth-first search algorithm BFS to traverse.

[0050] ③ If the data to be deleted is found, reset the flag and delete the data through the in-space service provider; if not found, throw an error.

[0051] 6) Query function design:

[0052] ① Initialize the result array structure and use the factory pattern to produce the objects stored in the structure array.

[0053] ② Obtain the corresponding space through the in-space service provider

[0054] ③ Parse the query conditions.

[0055] ④ If the query conditions are missing, traverse the entire data set, create a result object through the factory function, and store it in the result array.

[0056] ⑤ If there are query conditions, use the breadth-first search algorithm BFS to perform iterative queries starting from the first layer. If not found, recursively go to the next layer. If found, save the result to the result array structure.

[0057] ⑥ Return the result set.

[0058] In this example, the parameter descriptions of the database management space class functions are as follows:

[0059]

[0060] In this example, the logic in the in-space service provider is as follows:

[0061] The in-space service provider is an operation class that should include a method to judge the running environment, that is, to determine which storage method to use. Its this pointer should include methods for obtaining, storing, deleting, and clearing.

[0062] In the class function, initialize the storage variable to undefined, check whether the localStorage and cookieStorage variables exist globally to determine the running environment, and assign the storage environment to the initialized storage variable.

[0063] The this pointer of the class function always points to the internal service instance object of the space.

[0064] Add methods such as setItem (store), getItem (retrieve), removeItem (delete), and clearItem (clear) to the this pointer. Inside the methods, call the corresponding methods on the corresponding storage prototype by using the.call function.

[0065] Refer to Figure 2 , a data persistent storage method based on a web database, with the internal process as follows:

[0066] Monitor data operations. When there are data operations, register the operation information on the database space manager, and then make a unified dispatch through the database space manager to the specific space service to implement the specific operation. The space service directly operates on the local memory.

[0067] Refer to Figure 3 , a data persistent storage method based on a web database. The specific method includes the following steps:

[0068] Step 1: Initialize the client environment;

[0069] Step 2: Judge the client environment. If HTML5 storage is supported, use the normal mode; if not, use the compatible mode to store data using cookies;

[0070] Step 3: Check whether there is cached data in the local database. If not, initialize the local database, create the internal service worker class of the space and mount it globally. If so, send a preflight request to synchronize the remote database data based on the local cache summary;

[0071] Step 4: Create a global management space class to manage space operation methods, and create a database manager to maintain the access space table;

[0072] Step 5: The management space class mounts methods such as createSpace (create space); deleteSpace (delete space); insert (insert data); update (update data); delete (delete data);

[0073] Step 6: Load the query function (select);

[0074] Step 7: Call the management space class function to operate data, call the specific operation interface through the internal service provider of the space to generate new data; and calculate the cache digest according to the content of the generated new data;

[0075] Step 8: Register the new data after the operation through the database manager and store the data in the corresponding space;

[0076] Step 9: Synchronize the data between the local database and the remote database according to the set time interval.

Claims

1. A data persistent storage method based on a web database, characterized in that, the method comprises the following steps: Step 1: Initialize the client environment; Step 2: Judge the client environment. If HTML5 storage is supported, use the normal mode; if not, use the compatible mode to store data using cookies; Step 3: Judge whether there is cached data in the local database. If not, initialize the local database, create a space internal service worker class and mount it globally. If so, send a pre-check request to synchronize the data of the remote database according to the local cache summary; Step 4: Globally create a management space class to manage space operation methods, and create a database manager to maintain access to space tables; Step 5: The management space class mounts methods for creating spaces, deleting spaces, inserting data, updating data, and deleting data; Step 6: Load the query function; Step 7: Call the management space class function to operate data, call the specific operation interface through the space internal service, generate new data; and calculate the cache summary according to the content of the generated new data; Step 8: Register the new data after the operation through the database manager, and store the data in the corresponding space; Step 9: Synchronize the data between the local database and the remote database at a set time interval; The global in Step 1 is the window object; The normal mode in Step 2 uses the HTML5 localStorage API; Among them, the management space class is the main class of the entire database, mounted on the global window object, responsible for exposing the API interfaces for operations, and built-in with methods for creating data spaces, deleting data spaces, inserting data, updating data, deleting data, and select queries; Among them, the database space manager is data in JSON format stored in local memory, maintaining information about all stored space tables, and can be retrieved through the space internal service; Among them, the space internal service is a class defined using the ES6 specification, and its behavior is like SQL operations, having functions of storage, acquisition, deletion, and clearing.

2. A data persistent storage solution based on a web database according to claim 1, characterized in that, the cache summary in Step 3 is generated using the Murmurhash hashing algorithm, and the length of the summary information is 128 bits.

3. A data persistent storage solution based on a web database according to claim 1, characterized in that, in the data insertion method in Step 5, the inserted object uses the object data type.

4. A data persistent storage solution based on a web database according to claim 1, characterized in that, in the data update method in Step 5, if there is already exactly the same data in the space, update the latest item.

5. A data persistent storage solution based on a web database according to claim 1, characterized in that, in the data deletion method in Step 5, if there is already exactly the same data in the space, delete the latest item.

6. A data persistent storage solution based on a web database according to claim 1, wherein, the query function in step 6 has parameters of value type of String, Number, Boolean, Array or Object, and the return value is of type Array.

7. A data persistent storage solution based on a web database according to claim 1, wherein, the data storage type in step 8 is in JSON format, the key is the input name parameter, and the value includes an id field and a data field. The id value is the cache digest calculated in step 7, and the data value is the specific data value to be stored.

Citation Information

Patent Citations

  • Distributed cache server system and application method thereof, cache clients and cache server terminals

    CN102739720A

  • Universal basic storage framework and storage method

    CN107015802A