Data processing method, device, electronic device and storage medium
By using IndexDB as the browser cache mechanism, the functional limitations and flexibility of the existing cache mechanism are solved, efficient multi-type data storage and persistent cache are achieved, and the browser usage efficiency and user experience are improved.
Patent Information
- Application Number
- CN202111129273.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-26
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2041-09-26
AI Technical Summary
Existing browser caching mechanisms such as Application Cache and LocalStorage have problems such as limited functions, poor flexibility, not supporting multiple types of data storage, and inability to read data in privacy mode, resulting in inefficiency of the browser.
IndexDB is used as the browser cache mechanism, by judging the validity of cached data and directly returning cached data when it is not invalidated, server requests are reduced, multi-type data storage is supported, and persistent cache is provided when the network environment is poor.
Improve browser efficiency, reduce server dependence, reduce loading time, improve user experience, support multiple data types to store and read cached data in privacy mode.
Smart Images

Figure CN113806655B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method, device, electronic device, and storage medium. Background Art
[0002] In related technologies, browsers can use Application Cache and LocalStorage caching mechanisms to cache front-end data. Among them, Application Cache is a caching mechanism first provided by HyperText Markup Language 5 (HTML5) technology. It can set the resources that the browser needs to cache by configuring the manifest file, so that the network (Web) application can run offline; in other words, when the user is offline (that is, the client where the browser is installed is not connected to the network), even if the user clicks the refresh button of the browser, the Web application can be loaded and run normally. Compared with Application Cache, LocalStorage is a new feature proposed by HTML5 technology for local storage. Using the caching mechanism of LocalStorage, the browser can create a long-term cache file for each website. The cache file can be saved locally on the client in text form, thereby solving the problem of browser cookies occupying bandwidth and insufficient storage space.
[0003] However, in related technologies, the browser's cache mechanism still needs to be optimized. Summary of the Invention
[0004] To solve related technical problems, the embodiments of the present application provide a data processing method, device, electronic device and storage medium.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present invention provides a data processing method, including:
[0007] Obtain a first request for a front-end page; the first request is used to request to obtain first data from a target server;
[0008] Determine whether there is unexpired first cache data in an index database (IndexDB); the first cache data corresponds to the first data;
[0009] If there is unexpired first cache data in the IndexDB, returning the first cache data to the front-end page;
[0010] In a case where there is no undated first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
[0011] In the above solution, the step of determining whether there is any unexpired first cached data in IndexDB includes:
[0012] Using a first identifier corresponding to the first data, determining whether the first cache data exists in the IndexDB, and obtaining a first determination result;
[0013] When the first judgment result indicates that the first cached data exists in the IndexDB, at least one second identifier corresponding to the first request is used to determine whether the first cached data is invalid to obtain a second judgment result; the second identifier indicates the data version corresponding to the first request.
[0014] In the above solution, the determining whether the first cached data is invalid by using at least one second identifier corresponding to the first request includes:
[0015] Obtaining at least one third identifier corresponding to the first cached data from the IndexDB; the third identifier represents a data version corresponding to the first cached data;
[0016] comparing the at least one second identifier with the at least one third identifier;
[0017] When the at least one second identifier is consistent with the at least one third identifier, determining that the first cached data is not invalid;
[0018] When the at least one second identifier is inconsistent with the at least one third identifier, it is determined that the first cache data is invalid.
[0019] In the above solution, obtaining the first data from the target server includes:
[0020] Injecting first configuration information into the first request through a first function to obtain a second request; the first configuration information includes at least one second identifier; the second identifier represents the data version corresponding to the first request; the second request is used to request to obtain the first data;
[0021] The second request is sent to the target server; and the first data returned by the target server based on the second request is received.
[0022] In the above solution, when returning the first data to the front-end page, the method further includes:
[0023] If the first cache data does not exist in the IndexDB, generating first cache data using the first data;
[0024] or,
[0025] In a case where the first cache data is invalid, the first cache data is updated using the first data.
[0026] In the above solution, the step of generating first cache data by using the first data includes:
[0027] performing a first processing on the first data based on a first preset rule, so that the first data after the first processing meets a first preset condition;
[0028] First cache data is generated using the first data after the first processing.
[0029] In the above solution, the front-end page is in the first working mode; the method further includes:
[0030] Determining whether the current network environment meets the second preset condition, and determining whether the front-end page meets the third preset condition;
[0031] When the current network environment does not satisfy the second preset condition, and / or when the front-end page does not satisfy the third preset condition, controlling the front-end page to enter the first working mode;
[0032] When the current network environment satisfies the second preset condition and the front-end page satisfies the third preset condition, the front-end page is controlled to enter the second working mode; wherein,
[0033] When the front-end page is in the second working mode, all data requested by the front-end page is obtained from the IndexDB.
[0034] The present application also provides a data processing device, including:
[0035] An acquiring unit, configured to acquire a first request from a front-end page; the first request is used to request first data from a target server;
[0036] A processing unit is used to determine whether there is unexpired first cache data in IndexDB; the first cache data corresponds to the first data; if there is unexpired first cache data in the IndexDB, the first cache data is returned to the front-end page; if there is no unexpired first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
[0037] An embodiment of the present application further provides an electronic device, comprising: a processor and a memory for storing a computer program that can be run on the processor,
[0038] The processor is configured to execute the steps of any of the above methods when running the computer program.
[0039] An embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0040] The data processing method, device, electronic device and storage medium provided in the embodiment of the present application obtain a first request for a front-end page; the first request is used to request the first data of the target server; it is determined whether there is first cached data that has not expired in IndexDB; the first cached data corresponds to the first data; if there is first cached data that has not expired in the IndexDB, the first cached data is returned to the front-end page; if there is first cached data that has not expired in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page. The solution of the embodiment of the present application uses IndexDB to save the cached data of the browser. When the browser requests data from the server, if the corresponding cached data has not expired, the corresponding cached data is directly returned to the front-end page without having to obtain data from the server. In this way, the number of requests sent by the browser to the server can be reduced, thereby reducing the dependence of the front-end application (i.e., Web application) on the server, and reducing the loading time of the front-end page, thereby improving the efficiency of the browser. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a flow chart of a data processing method according to an embodiment of the present application;
[0042] Figure 2 This is a schematic diagram of the data processing flow of the data processing system of the application embodiment of the present application;
[0043] Figure 3 This is a flow chart of intercepting Hypertext Transfer Protocol (HTTP) requests by a data processing system according to an embodiment of the present application;
[0044] Figure 4 This is a schematic diagram of the persistent data structure of the application embodiment of this application;
[0045] Figure 5 This is a schematic diagram of the process of generating persistent data in an embodiment of the present application;
[0046] Figure 6 A schematic diagram of the workflow for providing data caching services for IndexDB, an application example of this application;
[0047] Figure 7 This is a structural diagram of a data processing device according to an embodiment of the present application;
[0048] Figure 8 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0049] The present application will be described in further detail below with reference to the accompanying drawings and embodiments.
[0050] In related technologies, although browsers can use Application Cache and LocalStorage caching mechanisms to cache front-end data, both mechanisms have drawbacks. Specifically, the Application Programming Interface (API) associated with Application Cache is poorly designed, supports limited functionality, and is not updated promptly. It lacks support for JavaScript-based data refinement (i.e., classifying data to meet specific granularity requirements). Furthermore, using these APIs requires strict adherence to pre-set rules, resulting in poor flexibility and usability, and uncertainty.
[0051] As for the LocalStorage caching mechanism, this technology only supports a single data type, and the browser needs to convert the data type when using other types of data. For example, if the data type supported by LocalStorage is limited to string type in advance, when the browser needs to use JavaScript Object Notation (JSON) type data, the String type data needs to be converted to JSON type data. In addition, LocalStorage does not support data reading in the browser's privacy mode, that is, the browser cannot load cached data in privacy mode.
[0052] Based on this, in various embodiments of the present application, IndexDB is used to store the browser's cached data. When the browser requests data from the server, the corresponding cached data is directly returned to the front-end page if the corresponding cached data has not expired, without having to obtain the data from the server again. In this way, the number of requests sent by the browser to the server can be reduced, thereby reducing the dependence of the front-end application (i.e., Web application) on the server and reducing the loading time of the front-end page, thereby improving the efficiency of the browser. At the same time, compared with the caching mechanism of Application Cache, the relevant API of IndexDB supports more functions, has better flexibility and usability, and is less uncertain. Compared with the caching mechanism of LocalStorage, IndexDB has a capacity advantage, which allows the cached data in IndexDB to be stored for a longer time. In other words, IndexDB can be used to achieve cached data persistence; and IndexDB can store diverse data, that is, it supports multiple types of data storage at the same time. The browser does not need to convert the data type when loading data, which can further reduce the loading time of the front-end page; In addition, IndexDB has no usage restrictions. Even if the browser is in privacy mode, the cached data in IndexDB can be read.
[0053] The present application provides a data processing method, which is applied to electronic devices, such as mobile phones, computers, etc., which have browser clients installed. Figure 1 As shown, the method includes:
[0054] Step 101: Get the first request of the front-end page;
[0055] Here, the first request is used to request to obtain first data from the target server;
[0056] Step 102: Determine whether there is any first cached data that has not expired in IndexDB;
[0057] Here, the first cache data corresponds to the first data, in other words, the first cache data is generated using the first data;
[0058] Step 103: If there is any first cached data that has not expired in the IndexDB, return the first cached data to the front-end page;
[0059] Step 104: If there is no undated first cache data in the IndexDB, obtain the first data from the target server and return the first data to the front-end page.
[0060] In actual application, the data processing method provided in the embodiment of the present application can be implemented by an application developed using JavaScript technology and asynchronous JavaScript and XML (AJAX, Asynchronous Javascript And XML) technology.
[0061] In actual application, the data type of the first cache data can be set according to demand. In other words, the data type supported by the IndexDB can be set according to demand, such as JSON, Binary Large Object (BLOB), etc.
[0062] In step 101, in actual application, the first request is used to request first data from the target server, which can be understood as information sent to the target server; accordingly, obtaining the first request can be understood as intercepting the first request before it is sent. Here, the method of intercepting the first request can be set based on the communication method between the front-end page and the target server (such as HTTP communication).
[0063] In actual application, the first request can be intercepted by a first function. The first function can also be called a request interceptor, HTTP interceptor, etc. The embodiment of this application does not limit the name of the first function, as long as the function of the first function can be realized.
[0064] In step 102, in actual application, the data stored on the target server may be updated. In other words, the data stored on the target server may undergo a version change. Once the data version changes, the corresponding cached data in IndexDB will become invalid. Therefore, the data version corresponding to the data requested by the first request, i.e., the data version corresponding to the first data, can be used to determine whether there is any first cached data in IndexDB that has not expired.
[0065] Based on this, in one embodiment, determining whether there is any unexpired first cache data in IndexDB may include:
[0066] Using a first identifier corresponding to the first data, determining whether the first cache data exists in the IndexDB, and obtaining a first determination result;
[0067] When the first judgment result indicates that the first cached data exists in the IndexDB, at least one second identifier corresponding to the first request is used to determine whether the first cached data is invalid to obtain a second judgment result; the second identifier indicates the data version corresponding to the first request.
[0068] In actual applications, the first identifier can be a tag generated by the target server for the first data, such as an ETagID. The ETagID refers to a parameter automatically carried during the interaction between the browser and the target server, including the ETag in the response header and the If-None-Match in the request header. Here, the method for obtaining the first identifier corresponding to the first data can be determined based on business needs and is not limited by the embodiments of this application.
[0069] In actual application, the use of the first identifier corresponding to the first data to determine whether the first cached data exists in the IndexDB can be understood as: determining whether the first identifier exists in the IndexDB. If the first identifier exists in the IndexDB, it can be determined that the first judgment result indicates that the first cached data exists in the IndexDB; if the first identifier does not exist in the IndexDB, it can be determined that the first judgment result indicates that the first cached data does not exist in the IndexDB, thereby determining that there is no unexpired first cached data in the IndexDB.
[0070] In actual application, the second identifier represents the data version corresponding to the first request, which can be understood as the second identifier representing the version of the data packet requested by the first request, that is, the data version corresponding to the first data. Here, the second identifier can be a version number, a request timestamp, a cache expiration time, etc. The number of second identifiers and the method for determining the second identifier can be determined according to business needs, and are not limited by the comparison of the embodiments of this application.
[0071] In one embodiment, the determining whether the first cached data is invalid by using at least one second identifier corresponding to the first request may include:
[0072] Obtaining at least one third identifier corresponding to the first cached data from the IndexDB; the third identifier represents a data version corresponding to the first cached data;
[0073] comparing the at least one second identifier with the at least one third identifier;
[0074] When the at least one second identifier is consistent with the at least one third identifier, determining that the first cached data is not invalid;
[0075] When the at least one second identifier is inconsistent with the at least one third identifier, it is determined that the first cache data is invalid.
[0076] Here, the number of the second identifiers is the same as the number of the third identifiers, and the specific value can be set according to business requirements.
[0077] In actual application, the first cache data is generated using the first data, that is, before the first request, the front-end page requested the first data from the target server, generated the first cache data using the first data, and generated at least one third identifier using the data version corresponding to the first data.
[0078] In step 104, in actual application, after the first request is intercepted by the first function, the at least one second identifier can be injected into the first request, and the processed request is sent to the target server to obtain the first data.
[0079] Based on this, in one embodiment, obtaining the first data from the target server may include:
[0080] Injecting first configuration information into the first request through a first function to obtain a second request; the first configuration information includes at least one second identifier; the second identifier represents the data version corresponding to the first request; the second request is used to request to obtain the first data;
[0081] The second request is sent to the target server; and the first data returned by the target server based on the second request is received.
[0082] Here, the first configuration information may further include the first identifier.
[0083] In actual application, the first function may specifically inject the first configuration information into the Request Header of the first request.
[0084] In actual application, after the first data is obtained from the target server, in order to provide data cache support for the next request, the first data can be cached or updated to the IndexDB.
[0085] Based on this, in one embodiment, when returning the first data to the front-end page, the method may further include:
[0086] If the first cache data does not exist in the IndexDB, generating first cache data using the first data;
[0087] or,
[0088] In a case where the first cache data is invalid, the first cache data is updated using the first data.
[0089] In actual application, using the first data to generate the first cache data, or using the first data to update the first cache data, can enable the IndexDB to provide data cache support for the next request, thereby improving the efficiency of users using the browser, that is, improving the user-friendliness of using the browser.
[0090] In actual application, in order to enable the IndexDB to provide better data cache support, when the first data is used to generate the first cache data, the first data may be subjected to specific processing, such as filtering, classification, etc.
[0091] Based on this, in one embodiment, generating first cache data using the first data may include:
[0092] performing a first processing on the first data based on a first preset rule, so that the first data after the first processing meets a first preset condition;
[0093] First cache data is generated using the first data after the first processing.
[0094] In actual application, the first preset rule and the first preset condition can be set according to business needs. For example, the first processing can be filtering processing, data classification processing, etc., and the first preset condition can be a condition related to data granularity. The embodiment of this application does not limit this.
[0095] In actual application, when generating the first cache data, second configuration information corresponding to the first cache data may also be generated and saved in the IndexDB. The second configuration information may include the first identifier and the at least one third identifier.
[0096] In actual application, the browser can include multiple working modes. When the network environment is poor (for example, the network speed is lower than the first threshold, which can be set according to business needs) or the network is disconnected, the browser may not interact with the target server and directly read the required data from the IndexDB.
[0097] Based on this, in one embodiment, the front-end page may be in a first working mode; the method may further include:
[0098] Determining whether the current network environment meets the second preset condition, and determining whether the front-end page meets the third preset condition;
[0099] When the current network environment does not satisfy the second preset condition, and / or when the front-end page does not satisfy the third preset condition, controlling the front-end page to enter the first working mode;
[0100] When the current network environment satisfies the second preset condition and the front-end page satisfies the third preset condition, the front-end page is controlled to enter the second working mode; wherein,
[0101] When the front-end page is in the second working mode, all data requested by the front-end page is obtained from the IndexDB.
[0102] In actual application, when the front-end page is in the first working mode, the first function is used to intercept the first request and determine whether there is any first cached data that has not expired in the IndexDB; if there is any first cached data that has not expired in the IndexDB, the first cached data is returned to the front-end page; if there is no first cached data that has not expired in the IndexDB, the first data is obtained from the target server and returned to the front-end page. Here, it can be understood that the first working mode is a working mode in which the front-end page negotiates (i.e., there is communication) the cache with the target server.
[0103] In actual application, the second and third preset conditions can be set according to business needs. For example, the second preset condition can indicate that the corresponding client is not connected to the network, or that the current network speed is lower than the first threshold; the third preset condition can indicate that the IndexDB cache has all the data required to load the front-end page.
[0104] The data processing method provided in the embodiment of the present application obtains the first request of the front-end page; the first request is used to request the first data of the target server; it is determined whether there is an unexpired first cached data in the IndexDB; the first cached data corresponds to the first data; if there is an unexpired first cached data in the IndexDB, the first cached data is returned to the front-end page; if there is no unexpired first cached data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page. The solution of the embodiment of the present application uses IndexDB to save the cached data of the browser. When the browser requests data from the server, the corresponding cached data is directly returned to the front-end page when the corresponding cached data is not expired, without the need to obtain data from the server again. In this way, the number of requests sent by the browser to the server can be reduced, thereby reducing the dependence of the front-end application (i.e., Web application) on the server, and reducing the loading time of the front-end page, thereby improving the efficiency of the browser. At the same time, compared with the caching mechanism of Application Cache, the relevant API of IndexDB supports more functions, has better flexibility and availability, and is less uncertain. Compared with the caching mechanism of LocalStorage, IndexDB has a capacity advantage, which allows the cached data in IndexDB to be stored for a longer period of time. In other words, IndexDB can be used to achieve cached data persistence. Moreover, IndexDB can store diverse data, that is, it supports multiple types of data storage at the same time. The browser does not need to convert data types when loading data, which can further reduce the loading time of the front-end page. In addition, IndexDB has no restrictions on usage conditions. Even if the browser is in privacy mode, you can read the cached data in IndexDB.
[0105] The present application will be described in further detail below in conjunction with application examples.
[0106] This application embodiment provides a data processing system, such as Figure 2As shown, the system includes: a request interceptor (i.e., the first function mentioned above), a cache adapter, and a response interceptor; the cache adapter includes an enhanced adapter. When a user browses the front-end page, the front-end page will initiate an HTTP request (i.e., the first request mentioned above), and the browser will execute (i.e., call) the request interceptor to intercept the HTTP request, and perform dispatch request processing (which can be expressed as dispatchRequest in English) and transform request data (which can be expressed as transformData in English) on the intercepted HTTP request. Afterwards, the browser uses (i.e., calls) the cache adapter to process the HTTP request and determine whether the cache data corresponding to the HTTP request (i.e., the first cache data mentioned above) exists in IndexDB; if the corresponding cache data exists in IndexDB, then determine whether the corresponding cache data is expired (i.e., determine whether the corresponding cache data is invalid); if the corresponding cache data is not expired, then return the corresponding cache data as the response object of the HTTP request, and execute the subsequent process, i.e., the browser executes the response interceptor, and the response interceptor transforms the response data (i.e., the response object). If the cached data corresponding to the HTTP request does not exist in IndexDB, the browser uses the enhanced adapter to send an HTTP request to the backend server (i.e., the target server) and saves the response object returned by the browser based on the request. At the same time, the saved response object is returned to the front-end page to execute the subsequent process. In addition, if the corresponding cached data has expired, the browser will also use the enhanced adapter to send an HTTP request to the backend server and save the response object returned by the browser based on the request (i.e., use the response object to update the corresponding cached data in IndexDB). At the same time, the saved response object is returned to the front-end page to execute the subsequent process.
[0107] In this application embodiment, the "enhancement" of the enhanced adapter can be understood as coordinating the data storage and usage functions of IndexDB in the underlying logic of the application. The data processing system provided by this application embodiment uses IndexDB to save the browser's cached data. Since IndexDB has a capacity advantage, this enables the cached data in IndexDB to be saved for a longer period of time. In other words, IndexDB can be used to achieve persistence of cached data, that is, IndexDB is used to provide the browser with reliable persistent cached data, reducing the front-end application's dependence on the server and improving the efficiency of the Web front-end. In addition, when the corresponding cached data has expired, that is, when the cached data has a version change, the data synchronization function can be improved, and the response object returned by the server can be asynchronously synchronized to IndexDB. In other words, while providing normal data display to the browser user, the same data is stored (i.e. updated) to IndexDB using a multi-threaded method, providing cached data for subsequent requests, thereby improving the user's browsing experience.
[0108] The functions of the various modules included in the data processing system of this application embodiment are described in detail below.
[0109] First, the data processing system of this application embodiment provides an interception service for HTTP requests.
[0110] Specifically, in this application embodiment, in order to achieve the effect of front-end data persistence, HTTP requests need to be uniformly processed before they are issued. In the related art, a unified request function is usually encapsulated to uniformly add information such as a token (which can be expressed as "token" in English) to each HTTP request. However, if it is necessary to set a cache time for certain GET requests or control the call frequency of certain requests later, the request function needs to be continuously modified to expand the corresponding functionality. If the response is also considered to be uniformly processed, the request function will become increasingly large and difficult to maintain. To this end, a new solution is needed to interrupt HTTP. Since the HTTP protocol communicates based on a request and response model, HTTP interruption can be achieved through an HTTP interceptor. The interceptor can include a request interceptor and a response interceptor, which are used to process HTTP requests and HTTP responses, respectively. The function of the request interceptor is to uniformly perform certain operations before the HTTP request is sent, such as adding a token field to the request header. The function of the response interceptor is to uniformly perform certain operations after receiving the server response, such as automatically jumping to the login page when the response status code is 401.
[0111] In this application embodiment, if Figure 3 As shown, the HTTP request mainly includes the following processes:
[0112] 1) Process the request configuration object. Specifically, if the front end initiates an HTTP request, the browser will start the HTTP interception service, that is, use the request interceptor to intercept the current HTTP request, and inject configuration information (that is, the above-mentioned first configuration information) into the request header of the request; the configuration information may include the request version number, request timestamp, cache expiration time, EtagID, etc. Here, the configuration information can be understood as an identifier set, and EtagID is equivalent to the above-mentioned first identifier; the request version number, request timestamp, and cache expiration time are equivalent to the above-mentioned second identifier or third identifier; the request timestamp and cache expiration time are only used to reflect the data version, and are not used to calculate whether the cache is expired. In actual application, the type of intercepted HTTP request can be set according to business needs, such as GET, POST, PUT, DELETE, etc.
[0113] 2) Initiate an HTTP request. This process may include dispatching request processing and converting request data. Furthermore, if the cache adapter determines that the corresponding cache data is in normal working order (i.e., the corresponding cache data has not expired) by comparing the configuration information injected into the HTTP request (i.e., the first configuration information) with the configuration information corresponding to the corresponding cache data in IndexDB (i.e., the second configuration information), then the cache adapter reads the corresponding cache data from IndexDB instead of requesting the corresponding data from the server.
[0114] 3) Processing the response data object. This process may include executing the response interceptor and transforming the response data through the response interceptor. Specifically, the corresponding cached data or the data returned by the server can be processed again (such as filtering, classification, etc.) to enable users to perform unified operations on the data.
[0115] Secondly, the data processing system of this application embodiment provides a persistent data generation service.
[0116] Specifically, persistent data generation services rely on the implementation of a cache. In computing, a cache is a high-speed data storage layer that stores subsets of data, usually temporarily, so that subsequent requests for that data are faster than accessing the primary storage location. Caching allows for efficient reuse of previously retrieved or calculated data. In this application embodiment, the persistent data generation service is provided through the following APIs:
[0117] 1) indexDB.get(key) is used to obtain the value corresponding to the specified key from the cached data in IndexDB;
[0118] 2) indexDB.delete(key), used to delete the value corresponding to the specified key from the cached data in IndexDB;
[0119] 3) indexDB.clear(), used to clear cached data;
[0120] 4) indexDB.set(key, value, maxAge) is used to save key-value pairs and supports setting the maximum cache time (i.e., the maximum effective duration) maxAge. The unit of maxAge can be milliseconds.
[0121] For example, in this application embodiment, if Figure 5 As shown, the process of generating persistent data may include the following steps:
[0122] 1) Create or open a database in IndexDB;
[0123] 2) Create an object store (objectStore) in the database;
[0124] 3) Set the data retrieval type of the response interceptor to BLOB;
[0125] 4) Initialize database transactions;
[0126] 5) Cache the BLOB data in the database.
[0127] Third, the data processing system of this application embodiment provides a data caching service based on IndexDB, and the data caching service includes two working modes: a negotiated cache working mode (ie, the first working mode mentioned above) and a forced cache working mode (ie, the second working mode mentioned above).
[0128] Among them, such as Figure 6 As shown, in the negotiated cache working mode, the cache adapter determines whether there is cache data corresponding to the current HTTP request in IndexDB; if not, it means that the browser is implementing the cache service for the data requested by the HTTP request for the first time, and it is necessary to obtain the response data from the server through the enhanced adapter, refine the response data (that is, classify the data so that the granularity of the data meets specific conditions), and write the refined data into IndexDB to provide cache data for the next request. If there is cache data corresponding to the current HTTP request in IndexDB, a data synchronization manager is generated through the enhanced adapter, and the data synchronization manager is used to register cache changes (i.e., cache updates) and perform configuration information comparison management through the comparison management unit of the enhanced adapter, that is, compare the configuration information of the request (i.e., the above-mentioned first configuration information) and the configuration information corresponding to the cache data returned by the last request in IndexDB (i.e., the above-mentioned second configuration information) to see if they are consistent; if they are consistent, there is no need to update the cache; if they are inconsistent, the corresponding cache data needs to be updated according to the update logic preset by the comparison management unit, that is, the response data is obtained from the server through the enhanced adapter, and the asynchronous synchronization task is triggered. While presenting the response data to the user, the response data is used to update the corresponding cache data in IndexDB. Here, it can be understood that the enhanced adapter includes: a comparison management unit, a data synchronization manager, and a data refinement processing unit.
[0129] In the case of a poor client network environment (e.g., a network outage), the data processing system enters a forced cache mode. In this mode, the IndexDB cache service provides all requested data from the front end, and reads the refined cache data in the IndexDB cache service based on the configuration information corresponding to each request.
[0130] The solution provided by this application embodiment has the following advantages:
[0131] 1) Based on the HTTP interceptor, configuration information is injected into HTTP requests. Based on the enhanced adapter and IndexDB, persistent caching of front-end data is achieved. When the cached data in IndexDB is not invalidated, the browser can directly use the cached data without initiating a request to obtain the data from the server. This not only reduces the number of HTTP requests, but also reduces the time users wait for page loading, thereby improving the user experience.
[0132] 2) The IndexDB cache service can intelligently update cached data. When cached data has expired, it can directly send a request to the backend server and save the returned data to IndexDB after fine-tuning it, providing data caching support for the next request, thereby improving the user-friendliness of the browser.
[0133] In order to implement the method of the embodiment of the present application, the embodiment of the present application also provides a data processing device, such as Figure 7 As shown, the device includes:
[0134] The acquisition unit 701 is configured to acquire a first request from a front-end page; the first request is configured to request first data from a target server;
[0135] Processing unit 702 is used to determine whether there is unexpired first cache data in IndexDB; the first cache data corresponds to the first data; if there is unexpired first cache data in the IndexDB, the first cache data is returned to the front-end page; if there is no unexpired first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
[0136] In one embodiment, the processing unit 702 is specifically configured to:
[0137] Using a first identifier corresponding to the first data, determining whether the first cache data exists in the IndexDB, and obtaining a first determination result;
[0138] When the first judgment result indicates that the first cached data exists in the IndexDB, at least one second identifier corresponding to the first request is used to determine whether the first cached data is invalid to obtain a second judgment result; the second identifier indicates the data version corresponding to the first request.
[0139] In one embodiment, the processing unit 702 is specifically configured to:
[0140] Obtaining at least one third identifier corresponding to the first cached data from the IndexDB; the third identifier represents a data version corresponding to the first cached data;
[0141] comparing the at least one second identifier with the at least one third identifier;
[0142] When the at least one second identifier is consistent with the at least one third identifier, determining that the first cached data is not invalid;
[0143] When the at least one second identifier is inconsistent with the at least one third identifier, it is determined that the first cache data is invalid.
[0144] In one embodiment, the processing unit 702 is further configured to:
[0145] Injecting first configuration information into the first request through a first function to obtain a second request; the first configuration information includes at least one second identifier; the second identifier represents the data version corresponding to the first request; the second request is used to request to obtain the first data;
[0146] The second request is sent to the target server; and the first data returned by the target server based on the second request is received.
[0147] In one embodiment, when returning the first data to the front-end page, the processing unit 702 is further configured to:
[0148] If the first cache data does not exist in the IndexDB, generating first cache data using the first data;
[0149] or,
[0150] In a case where the first cache data is invalid, the first cache data is updated using the first data.
[0151] In one embodiment, the processing unit 702 is further configured to:
[0152] performing a first processing on the first data based on a first preset rule, so that the first data after the first processing meets a first preset condition;
[0153] First cache data is generated using the first data after the first processing.
[0154] In one embodiment, the front-end page is in the first working mode; the processing unit 702 is further configured to:
[0155] Determining whether the current network environment meets the second preset condition, and determining whether the front-end page meets the third preset condition;
[0156] When the current network environment does not satisfy the second preset condition, and / or when the front-end page does not satisfy the third preset condition, controlling the front-end page to enter the first working mode;
[0157] When the current network environment satisfies the second preset condition and the front-end page satisfies the third preset condition, the front-end page is controlled to enter the second working mode; wherein,
[0158] When the front-end page is in the second working mode, all data requested by the front-end page is obtained from the IndexDB.
[0159] In actual application, the acquisition unit 701 and the processing unit 702 can be implemented by a processor in a data processing device.
[0160] It should be noted that the data processing device provided in the above embodiments is merely illustrated by the division of the aforementioned program modules when processing data. In actual applications, the aforementioned processing can be distributed among different program modules as needed, i.e., the internal structure of the device can be divided into different program modules to complete all or part of the aforementioned processing. Furthermore, the data processing device provided in the above embodiments and the data processing method embodiments are based on the same concept. The specific implementation process is detailed in the method embodiments and will not be repeated here.
[0161] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiment of the present application, the embodiment of the present application also provides an electronic device, such as Figure 8 As shown, the electronic device 800 includes:
[0162] Communication interface 801, capable of exchanging information with other electronic devices;
[0163] A processor 802 is connected to the communication interface 801 to implement information exchange with other electronic devices, and is used to execute the methods provided by one or more of the above technical solutions when running a computer program;
[0164] The memory 803 stores computer programs that can be run on the processor 802 .
[0165] Specifically, the processor 802 is configured to:
[0166] Obtaining a first request for a front-end page; the first request is used to request obtaining first data from a target server;
[0167] Determine whether there is unexpired first cache data in IndexDB; the first cache data corresponds to the first data;
[0168] If there is unexpired first cache data in the IndexDB, returning the first cache data to the front-end page;
[0169] In a case where there is no undated first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
[0170] In one embodiment, the processor 802 is specifically configured to:
[0171] Using a first identifier corresponding to the first data, determining whether the first cache data exists in the IndexDB, and obtaining a first determination result;
[0172] When the first judgment result indicates that the first cached data exists in the IndexDB, at least one second identifier corresponding to the first request is used to determine whether the first cached data is invalid to obtain a second judgment result; the second identifier indicates the data version corresponding to the first request.
[0173] In one embodiment, the processor 802 is specifically configured to:
[0174] Obtaining at least one third identifier corresponding to the first cached data from the IndexDB; the third identifier represents a data version corresponding to the first cached data;
[0175] comparing the at least one second identifier with the at least one third identifier;
[0176] When the at least one second identifier is consistent with the at least one third identifier, determining that the first cached data is not invalid;
[0177] When the at least one second identifier is inconsistent with the at least one third identifier, it is determined that the first cache data is invalid.
[0178] In one embodiment, the processor 802 is further configured to:
[0179] Injecting first configuration information into the first request through a first function to obtain a second request; the first configuration information includes at least one second identifier; the second identifier represents the data version corresponding to the first request; the second request is used to request to obtain the first data;
[0180] The second request is sent to the target server; and the first data returned by the target server based on the second request is received.
[0181] In one embodiment, when returning the first data to the front-end page, the processor 802 is further configured to:
[0182] If the first cache data does not exist in the IndexDB, generating first cache data using the first data;
[0183] or,
[0184] In a case where the first cache data is invalid, the first cache data is updated using the first data.
[0185] In one embodiment, the processor 802 is further configured to:
[0186] performing a first processing on the first data based on a first preset rule, so that the first data after the first processing meets a first preset condition;
[0187] First cache data is generated using the first data after the first processing.
[0188] In one embodiment, the front page is in the first working mode; the processor 802 is further configured to:
[0189] Determining whether the current network environment meets the second preset condition, and determining whether the front-end page meets the third preset condition;
[0190] When the current network environment does not satisfy the second preset condition, and / or when the front-end page does not satisfy the third preset condition, controlling the front-end page to enter the first working mode;
[0191] When the current network environment satisfies the second preset condition and the front-end page satisfies the third preset condition, the front-end page is controlled to enter the second working mode; wherein,
[0192] When the front-end page is in the second working mode, all data requested by the front-end page is obtained from the IndexDB.
[0193] It should be noted that: the specific process of the processor 802 performing the above operations is detailed in the method embodiment, which will not be repeated here.
[0194] Of course, in actual application, the various components in the electronic device 800 are coupled together through the bus system 804. It is understood that the bus system 804 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 804 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 8 Various buses are labeled as bus system 804 .
[0195] The memory 803 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device 800. Examples of such data include: any computer program used to operate on the electronic device 800.
[0196] The methods disclosed in the above embodiments of the present application can be applied to or implemented by the processor 802. The processor 802 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by an integrated logic circuit of the hardware in the processor 802 or by instructions in the form of software. The above processor 802 may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 802 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 803. The processor 802 reads the information in the memory 803 and completes the steps of the above method in combination with its hardware.
[0197] In an exemplary embodiment, the electronic device 800 can be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers (MCUs), microprocessors, or other electronic components to perform the aforementioned method.
[0198] It is understood that the memory 803 of the embodiment of the present application can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a magnetic disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus random access memory (DRRAM).The memories described in the embodiments of this application are intended to include, but are not limited to, these and any other suitable types of memories.
[0199] In an exemplary embodiment, the present application also provides a storage medium, namely, a computer storage medium, specifically a computer-readable storage medium, including, for example, a memory 803 storing a computer program. The computer program can be executed by a processor 802 of an electronic device 800 to perform the steps of the aforementioned method. The computer-readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, or CD-ROM.
[0200] It should be noted that: "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0201] In addition, the technical solutions described in the embodiments of the present application can be arbitrarily combined without conflict.
[0202] The above description is merely a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application.
Claims
1. A data processing method, characterized in that: Applied to an electronic device, the electronic device being a client with a browser installed, the method includes: intercepting the first request before the first request of the front-end page is sent; the first request is used to request to obtain first data from the target server; Determine whether there is unexpired first cache data in the index database IndexDB; the first cache data corresponds to the first data; If there is unexpired first cache data in the IndexDB, returning the first cache data to the front-end page; In a case where there is no undated first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
2. The method according to claim 1, characterized in that The determining whether there is any unexpired first cache data in IndexDB includes: Using a first identifier corresponding to the first data, determining whether the first cache data exists in the IndexDB, and obtaining a first determination result; When the first judgment result indicates that the first cached data exists in the IndexDB, at least one second identifier corresponding to the first request is used to determine whether the first cached data is invalid to obtain a second judgment result; the second identifier indicates the data version corresponding to the first request.
3. The method according to claim 2, characterized in that The determining whether the first cached data is invalid by using at least one second identifier corresponding to the first request includes: Obtaining at least one third identifier corresponding to the first cached data from the IndexDB; the third identifier represents a data version corresponding to the first cached data; comparing the at least one second identifier with the at least one third identifier; When the at least one second identifier is consistent with the at least one third identifier, determining that the first cached data is not invalid; When the at least one second identifier is inconsistent with the at least one third identifier, it is determined that the first cache data is invalid.
4. The method according to any one of claims 1 to 3, characterized in that The acquiring the first data from the target server includes: Injecting first configuration information into the first request through a first function to obtain a second request; the first configuration information includes at least one second identifier; the second identifier represents the data version corresponding to the first request; the second request is used to request to obtain the first data; The second request is sent to the target server; and the first data returned by the target server based on the second request is received.
5. The method according to any one of claims 1 to 3, characterized in that When returning the first data to the front-end page, the method further includes: If the first cache data does not exist in the IndexDB, generating first cache data using the first data; or, In a case where the first cache data is invalid, the first cache data is updated using the first data.
6. The method according to claim 5, characterized in that The generating first cache data by using the first data includes: performing a first processing on the first data based on a first preset rule, so that the first data after the first processing meets a first preset condition; First cache data is generated using the first data after the first processing.
7. The method according to any one of claims 1 to 3, characterized in that The front-end page is in a first working mode; the method further includes: Determining whether the current network environment meets the second preset condition, and determining whether the front-end page meets the third preset condition; When the current network environment does not satisfy the second preset condition, and / or when the front-end page does not satisfy the third preset condition, controlling the front-end page to enter the first working mode; When the current network environment satisfies the second preset condition and the front-end page satisfies the third preset condition, the front-end page is controlled to enter the second working mode; wherein, When the front-end page is in the second working mode, all data requested by the front-end page is obtained from the IndexDB.
8. A data processing device, characterized in that: The device is provided on an electronic device, which is a client having a browser installed thereon, and includes: An acquisition unit, configured to intercept the first request before the first request of the front-end page is issued; the first request is used to request to acquire first data from a target server; A processing unit is used to determine whether there is unexpired first cache data in IndexDB; the first cache data corresponds to the first data; if there is unexpired first cache data in the IndexDB, the first cache data is returned to the front-end page; if there is no unexpired first cache data in the IndexDB, the first data is obtained from the target server and the first data is returned to the front-end page.
9. An electronic device, characterized in that: include: a processor and a memory for storing a computer program capable of being executed on the processor, Wherein, when the processor is used to run the computer program, it executes the steps of the method according to any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data access method, device, computer equipment and storage medium
CN110471939A