A method and system for rendering unit directional update and cache coherency handling based on data dependence range
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-26
- Publication Date
- 2026-08-11
AI Technical Summary
[0006]本发明旨在解决现有技术中,内容数据变更后缓存失效与渲染更新粒度粗糙、数据库查询重复率高、服务端渲染资源消耗过大的问题
提高缓存命中率:通过对查询结果缓存进行精细化失效控制,避免因无关数据变更导致的缓存雪崩式失效;
Smart Images

Figure CN122548064A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of Internet content management systems, specifically relating to a method and system for targeted updates and cache consistency processing based on content data changes and rendering unit dependencies in a server-side rendering architecture. Background Technology
[0002] With the development of internet content management platforms, content display systems based on server-side rendering (SSR) architecture have been widely adopted. These systems typically consist of a client, a server-side rendering layer, a backend service layer, and a data storage layer. Pages are composed of multiple components or areas, and content data (such as articles and news) is usually stored in a database. Server-side rendering generates HTML pages to improve first-screen loading speed and search engine friendliness.
[0003] In existing technologies, in order to improve system response efficiency, the data query results required during the server-side rendering process are usually cached. For example, database query statements and their results are cached in memory or a distributed caching system to avoid frequent database access in high-concurrency scenarios.
[0004] When content data changes, the common handling methods mainly include the following two: The first approach relies on the natural expiration mechanism of the cache, which involves setting a fixed expiration time (TTL) in the cache. Only after the cache expires will the next request re-execute the database query. While this method is simple to implement, changes to content often take a considerable amount of time to be reflected on the page. The second approach is a unified cache invalidation mechanism. This means that when a change in content data is detected, all cached query results associated with the relevant data tables or data objects are uniformly cleared or forcibly invalidated. For example, when the content of an article changes, the system may invalidate all cached results involving the article table or related query conditions. Even if some queries only involve fields such as the article's title or publication time, they will be cleared and the database will be queried again.
[0005] However, the aforementioned existing technologies still have the following technical problems in practical applications: First, the cache invalidation granularity is too coarse. Due to the lack of fine-grained modeling of the dependencies between "data query statements - data fields - rendering units", changes to any part of the content data often lead to the invalidation of a large number of unrelated query result caches, thereby triggering unnecessary database access and server-side rendering calculations; Secondly, the controllability of content changes taking effect is poor. In scenarios using a cache natural expiration mechanism, content changes cannot take effect promptly across multiple platforms and components, affecting the timeliness and consistency of information dissemination. Secondly, database and server-side rendering resources are consumed in large quantities. In high-concurrency access scenarios, frequent global or coarse-grained query result cache invalidation will trigger a large number of repeated database queries and server-side rendering requests, significantly increasing system load and affecting system stability. Finally, when different parts of the same data object are referenced by different queries and components, there is a lack of targeted update strategies. Existing technologies struggle to differentiate which query result caches and rendering units need updating based on the specific scope of content data changes (such as changes only in metadata or changes in the main text content), resulting in update strategies that are not granular or efficient enough. Summary of the Invention
[0006] This invention aims to address the problems in existing technologies, such as cache invalidation after content data changes, coarse-grained rendering updates, high database query duplication rates, and excessive server-side rendering resource consumption. Specifically, existing technologies typically employ a uniform cache invalidation strategy or a fixed expiration time, lacking fine-grained modeling of the dependencies between "content data fields—database queries—rendering units." This results in a large number of irrelevant query result cache invalidations and full re-rendering even when only some data changes, thus affecting system performance, the timeliness of content updates, and the consistency of multi-platform display.
[0007] To achieve the above objectives, the present invention provides a method for targeted updating of rendering units based on data dependency range, characterized by comprising the following steps: A data dependency mapping relationship between content data objects and multiple rendering units is pre-established, wherein different rendering units have different data dependency ranges on the content data objects; for example, some rendering units depend only on the metadata fields in the content data objects, while other rendering units depend on both the metadata fields and the main content fields. When a change is detected in the content data object, the change processing service is invoked to determine the set of affected rendering units based on the data dependency mapping relationship. For the set of affected rendering units, the corresponding cache invalidation process is executed; when the next server-side rendering request arrives, if the corresponding cache is detected to be invalid, the data is re-acquired for server-side rendering update, so as to achieve controllable effect of content changes in different rendering units.
[0008] Furthermore, the present invention also provides a rendering unit-oriented update system based on data dependency range, the system comprising: The dependency establishment module is used to pre-establish data dependency mapping relationships between content data objects and multiple rendering units; The change processing module is used to determine the set of affected rendering units based on the data dependency mapping relationship when a change is detected in the content data object. The update processing module is used to perform corresponding cache invalidation processing for the affected set of rendering units, and when the next server-side rendering request arrives, if the corresponding cache is detected to be invalid, the data is re-acquired for server-side rendering update.
[0009] Compared with the prior art, the present invention has the following beneficial effects: Improve cache hit rate: By implementing fine-grained invalidation control on query result cache, avoid cache avalanche failures caused by irrelevant data changes; Reduce unnecessary SSR rendering: Only re-render for the affected rendering units to reduce server-side rendering pressure; Shorten the time for content changes to take effect: Supports triggering updates of relevant rendering units immediately or on demand after content changes, without having to rely entirely on the natural expiration of the cache; Reduce server load: Reduce invalid database queries and server rendering requests to improve system stability in high-concurrency scenarios; Ensure consistent display across multiple platforms and components: Based on a unified data dependency mapping model, ensure that the update behavior of the same content data in different reference locations is controllable and consistent. Attached Figure Description
[0010] Figure 1 This is a schematic diagram of the overall system architecture provided in an embodiment of the present invention, illustrating the interaction relationships between the client, the server rendering layer, the backend service layer, the data storage layer, and the caching layer.
[0011] Figure 2 This is a schematic diagram illustrating the data dependency mapping relationship between content data objects, data field ranges, and multiple rendering units in an embodiment of the present invention. The data field ranges include metadata fields and text content fields.
[0012] Figure 3 This is a flowchart of the content change processing, cache invalidation and rendering update process in an embodiment of the present invention, including process nodes such as change detection, dependency determination, cache invalidation and processing of the next server rendering request. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings.
[0014] The system architecture used in the embodiments of the present invention is as follows: Figure 1 As shown, it specifically includes: Client layer: Users access the page through a browser or other terminal devices; Server-side rendering layer: Server-side rendering (SSR) implemented based on the Nuxt framework is responsible for rendering page components into HTML and returning them to the client, while generating corresponding cache identifiers during the rendering process; Backend service layer: Business services built on NestJS, used to handle content management, data query and cache control logic; Data storage layer: PostgreSQL database can be used to store content data objects, such as articles and news. Caching layer: Redis distributed cache is used to store the execution results of database query statements, avoiding repeated database accesses for the same query conditions during server-side rendering.
[0015] In this architecture, the page consists of multiple rendering units (such as list components, detail content components, etc.). Each rendering unit initiates a specific data query request during the rendering process. The system achieves fine-grained processing of the impact of content changes by caching and invalidating these query results.
[0016] In this embodiment of the invention, the content data object is divided into two data ranges: Meta data includes descriptive fields such as title, author, publication time, channel, category, and tags, and is typically used for list displays or summary information. Content Data: refers to long text fields such as the main body of the article and rich text content.
[0017] The system pre-defines a data dependency mapping table to describe the dependency relationships between each rendering unit and the aforementioned content data fields. For example: List component: Only depends on the metadata fields of the article object (such as title and publication time); Detailed content component: It depends on both the metadata fields and content data fields of the article object.
[0018] This dependency can be established in one of the following ways: Pre-defined code approach: During component development, declare the required range of data fields through component properties or decorators; Configuration-based definition method: Maintain a mapping table in the system configuration file to record the data query conditions and field sets corresponding to each route or component.
[0019] Using the above method, the system can know the specific scope of each rendering unit's dependency on the content data object at runtime.
[0020] In a CMS backend management system, when an editor performs a content save or publish operation, the system calls the content update interface provided by the backend service layer. Before and after the database update operation is performed by this interface, the system performs field-level snapshot comparisons on the content data objects to identify the range of fields involved in the change.
[0021] Specifically, when the system detects an update operation on a content data object, before performing a persistent database write operation, it first obtains and saves the object's state before the change based on the object's unique identifier, as the old state. After the database transaction is committed, it obtains the object's state after the change, as the new state. Subsequently, the system iterates through the object fields in both the old and new states, compares the field values item by item, identifies the target fields whose values have changed, and generates a set of field differences containing the names of the changed fields.
[0022] If the changed fields only involve metadata fields (such as title, publication time, category, etc.), it is determined to be a Meta change; if the changed fields involve body content fields, it is determined to be a Content change.
[0023] After identifying the change type, the content update interface directly calls the service method provided by the change processing module, and passes the change object identifier and change type as parameters. The change processing module then continues to execute the subsequent dependency determination and cache invalidation process.
[0024] After the change processing module receives the change object identifier and change type from the content update interface, the system executes the judgment logic for the set of affected rendering units based on the preset data dependency mapping table.
[0025] Specifically, the system first identifies the content data object that has been changed based on the object identifier, and then, in conjunction with the change type (Meta change or Content change), finds all rendering units that have declared a dependency on the corresponding field range in the dependency relationship, and includes them in the set of affected rendering units.
[0026] To facilitate understanding, the following specific examples will be used to illustrate: When a meta change occurs, such as a change in the article title or publication time, the system determines that both the list component and the details content component have declared dependencies on the metadata fields in their dependencies, and therefore adds these two types of components to the set of affected rendering units. When a content change occurs, such as a change in the article's main text content, the system determines that only the details content component declares a dependency on the main text content fields, and therefore only adds that component to the set of affected rendering units.
[0027] Through the above judgment logic, the system can accurately determine the rendering units affected by this content change at the field range granularity, thereby providing accurate input parameters for subsequent cache invalidation and rendering updates.
[0028] For the identified set of affected rendering units, the system executes the following cache invalidation and rendering update strategy:
[0029] Redis Cache Key Design Rules The system uses a unified naming convention for cache keys, for example: {Tenant Identifier}:{Page Route}:{Component Unique Identifier}:{Query Parameter Hash Value} The query parameter hash value is generated by hashing the database query statement and its parameters (such as filtering conditions and sorting rules) to ensure that the same query conditions generate the same key.
[0030] Cache invalidation methods Once the set of affected rendering units is determined, the system calculates the relevant query_hash based on the query conditions corresponding to each unit in the set, and performs one of the following operations on the corresponding cache key in Redis: Immediate expiration: Directly delete the corresponding cache key; Mark dirty data: Set a dirty flag in the cache value, or append a version number / timestamp to the key to indicate that the cache has expired.
[0031] In this embodiment of the invention, a strategy combining immediate expiration with a short expiration time as a fallback is preferred.
[0032] Next SSR request processing When the client initiates another page request, the server-side rendering layer first attempts to retrieve the corresponding query result cache from Redis: If the cache exists and has not expired, the cached data will be used directly to complete the rendering. If the cache does not exist or has been marked as invalid, the database query is re-executed to retrieve the latest data, and the new query results are written to Redis, while the server-side rendering update is completed.
[0033] A fallback mechanism: To prevent caches from remaining unupdated for extended periods due to exceptional circumstances, the system sets a fallback expiration time (e.g., 5 minutes) for all query result caches. Even if cache expiration is not triggered in time under certain extreme circumstances, the cache will automatically expire after the fallback time, ensuring eventual consistency of the system.
[0034] Through the above implementation methods, the present invention effectively reduces the frequency of database access and the rendering pressure on the server side while ensuring that content changes take effect in a timely manner, thus achieving a balance between cache consistency and system performance.
Claims
1. A method for targeted updating of rendering units based on data dependency range, characterized in that, When applied to a server-side rendering architecture, the following steps are included: Dependency predefinition step: During system initialization or component loading, the page template or component definition file is parsed to pre-establish the data dependency mapping relationship between the content data object and multiple rendering units, wherein the data dependency mapping relationship defines the range of data fields of the content data object that each rendering unit depends on; Change detection and judgment steps: In the content update processing flow, when an update operation is detected on the content data object, the object status is obtained before and after the database write operation, and field-level snapshots are compared to identify and generate a dataset of field range differences involved in this change; based on the data dependency mapping relationship, the set of affected rendering units that depend on the dataset of field range differences is queried and determined. Cache-directed invalidation steps: Traverse the set of affected rendering units, extract the data query conditions corresponding to each rendering unit, generate a unique cache key based on a preset hash rule, and send an invalidation instruction for the cache key to the distributed caching system; Rendering update response steps: When the next server-side rendering request is received from the client, the server-side rendering layer first checks the status of the cached data associated with the cache key; if the cached data is found to be invalid or non-existent, the cache is bypassed and a database query is directly executed to obtain the latest data, and the latest data is used to drive the corresponding rendering unit to complete the incremental server-side rendering update.
2. The method of claim 1, wherein, The data field range includes at least the metadata field range and the text content field range; Among them, the first type of rendering unit depends only on the metadata field range, while the second type of rendering unit depends on both the metadata field range and the text content field range. The field-level snapshot comparison is specifically used for: if the changed field only involves the range of the metadata fields, it is determined to be a first type of change; if the changed field involves the range of the main text content fields, it is determined to be a second type of change.
3. The method of claim 1, wherein, The generation rule for the cache key follows: {tenant identifier}:{page route}:{component unique identifier}:{query parameter hash value}; The hash value of the query parameter is obtained by hashing the semantic structure and parameter variables of the database query statement after normalization.
4. The method of claim 1, wherein, In the cache-directed invalidation step, the invalidation instruction includes any of the following: Delete the key-value pair corresponding to the cache key directly; or write an invalidation flag bit into the key-value pair corresponding to the cache key and set a very short remaining time to live (TTL).
5. The method according to claim 1, characterized in that, In the rendering update response step, the incremental server-side rendering update is specifically manifested as follows: Only the component rendering function corresponding to the affected rendering unit set is re-executed, while other unaffected static component areas on the page are not re-rendered.
6. The method of claim 1, wherein, It also includes a safety net to ensure consistency: Set a fallback expiration time for all cached data; when the fallback expiration time is exceeded, regardless of whether the cached data has been marked as invalid, a database query will be forcibly executed to refresh the cache.
7. A data dependency range based rendering unit directed update system, comprising: include: The dependency establishment module is used to parse page templates or component definition files during system initialization or component loading phases, and pre-establish data dependency mapping relationships between content data objects and multiple rendering units. The change processing module is used in the content update process to, when receiving an edit and save request for the content data object through the content management interface, obtain a first object state snapshot before performing a database write operation, and obtain a second object state snapshot after performing a database write operation; identify and generate a dataset of field range differences involved in this change by performing a field-level comparison between the first and second object state snapshots; and query and determine the set of affected rendering units that depend on the dataset of field range differences based on the data dependency mapping relationship. The update processing module is used to traverse the set of affected rendering units, extract the data query conditions corresponding to each rendering unit to generate a cache key, and send an invalidation instruction for the cache key to the distributed caching system; and when the next server-side rendering request is received from the client, the cache data status is checked, and if it is invalid, the cache is bypassed to perform a database query, and the latest data is used to drive the corresponding rendering unit to complete the incremental server-side rendering update.