Method, apparatus and device for dynamically updating cache data, and medium
By identifying the cache key to be updated and traversing the product data interface when a scheduled update task is detected, generating and replacing the key-value names of the cache data, the problem of untimely cache data updates is solved, realizing dynamic cache updates and improving user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING QIYI CENTURY SCI & TECH CO LTD
- Filing Date
- 2023-05-30
- Publication Date
- 2026-05-19
AI Technical Summary
Existing methods for updating cached data suffer from untimely updates, causing user interfaces to time out and preventing the retrieval of updated data, thus impacting user experience.
When a scheduled update task is detected, the cache key to be updated is determined. For the cache key to be updated, the preset product data interface is traversed and processed to generate the cache data to be updated. The data is dynamically replaced and updated by changing the key-value name, so as to ensure a smooth switch without the user's perception.
It effectively avoids user access timeout issues caused by cache updates, improves user experience, and enables timely updates and smooth switching of cached data.
Smart Images

Figure CN116610689B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device and medium for dynamically updating cached data. Background Technology
[0002] Currently, e-commerce applications (Apps) typically display their product channel pages in a feed (subscription feed) format. Generally, one source of products in the feed is a product data interface. Product data is obtained by accessing this interface, but this data is dynamic, as products may sell out or become unavailable. Existing methods for updating cached data mainly involve periodically iterating through the product data interface to update the cached data. However, when the cached data is being updated, user access to the product data may result in a timeout, preventing the retrieval of updated data and leading to untimely cached data updates. Summary of the Invention
[0003] This application provides a method, apparatus, device, and medium for dynamically updating cached data, thereby achieving the purpose of smooth cache switching and dynamic cache updating, improving user experience, and solving the problem of untimely cached data updates in existing cached data update methods.
[0004] Firstly, this application provides a method for dynamically updating cached data, the method being applied to updating product data, including:
[0005] If a scheduled update task is detected, determine the cache key to be updated;
[0006] For the cache key to be updated, the preset product data interface is traversed to obtain at least one product update data, and the product update data is used as the cache value corresponding to the cache key to be updated.
[0007] Generate cache data to be updated based on the cache key to be updated and the cache value;
[0008] The key-value name of the cache key to be updated is changed so that the cache data to be updated can dynamically replace and update the original cache data.
[0009] Optionally, before determining the cache key to be updated, the method further includes:
[0010] Obtain preset scheduled task information and system time, wherein the scheduled task information includes the initial update time and update interval;
[0011] The cached data update time is obtained by performing update calculations based on the initial update time and the update interval.
[0012] Determine whether the cached data update time matches the system time;
[0013] If the cached data update time matches the system time, then the scheduled update task is determined to be triggered.
[0014] Optionally, determining the cache key to be updated includes:
[0015] Retrieve the default command line;
[0016] Using the command line, a key is created within the cache service to obtain the cache key to be updated.
[0017] Optionally, the step of iterating through a preset product data interface for the cache key to be updated to obtain at least one product update data includes:
[0018] Obtain the product identifier and determine the preset product data interface corresponding to the product identifier;
[0019] For the cache key to be updated, the product data interface is traversed to obtain the product update data corresponding to the product identifier.
[0020] Optionally, generating the cache data to be updated based on the cache key to be updated and the cache value includes:
[0021] The cache data to be updated is obtained by constructing key-value pairs based on the cache key to be updated and the cache value.
[0022] Optionally, the key-value name of the cache key to be updated is changed, including:
[0023] Extract the original cache key from the original cache data;
[0024] Determine the key name information corresponding to the original cache key;
[0025] The key name of the cache key to be updated is overwritten and changed based on the key name information.
[0026] Optionally, after changing the key-value name of the cache key to be updated, the method further includes:
[0027] Obtain the user's access request;
[0028] Based on the access request, cached data is retrieved to obtain the data to be pushed.
[0029] The data to be pushed is sent to the user terminal, and the user terminal displays product data based on the data to be pushed.
[0030] Secondly, this application provides a dynamic update device for cached data, the device being applied to updating product data, comprising:
[0031] The module for determining the cache key to be updated is used to determine the cache key to be updated when a scheduled update task is detected.
[0032] The traversal processing module is used to traverse the preset product data interface for the cache key to be updated, obtain at least one product update data, and use the product update data as the cache value corresponding to the cache key to be updated.
[0033] The cache data to be updated generation module is used to generate cache data to be updated based on the cache key to be updated and the cache value;
[0034] The key-value name change module is used to change the key-value name of the cache key to be updated, so that the cache data to be updated can dynamically replace and update the original cache data.
[0035] Thirdly, this application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0036] Memory, used to store computer programs;
[0037] When a processor executes a program stored in memory, it implements the steps of the method for dynamically updating cached data as described in any embodiment of the first aspect.
[0038] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the dynamic update method for cached data as described in any embodiment of the first aspect.
[0039] In summary, the embodiments of this application are applied to product data updates. When a timed update task is detected, a cache key to be updated is determined. For the cache key to be updated, the preset product data interface is traversed to obtain at least one product update data. The product update data is used as the cache value corresponding to the cache key to be updated. Based on the cache key to be updated and the cache value, cache data to be updated is generated. The key-value name of the cache key to be updated is changed so that the cache data to be updated dynamically replaces and updates the original cache data, thereby achieving the purpose of smooth cache switching and dynamic cache updating. This solves the problem of untimely cache data updates in existing cache data update methods. Attached Figure Description
[0040] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0041] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 A flowchart illustrating a method for dynamically updating cached data provided in an embodiment of this application;
[0043] Figure 2 This is a flowchart illustrating the steps of a method for dynamically updating cached data according to an optional embodiment of this application;
[0044] Figure 3 This is a schematic diagram of an optional embodiment of the present application providing a process for updating product data in an online store;
[0045] Figure 4 A structural block diagram of a dynamic update device for cached data provided in an embodiment of this application;
[0046] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0048] In related technologies, the data in the product data interface is usually dynamically changing. Taking the welfare products in the e-commerce app as an example, the product data update method mainly involves periodically traversing the e-commerce welfare interface every day at midnight or a fixed time period to obtain updated cached data and caching it in a sorted set structure in Redis. When a user requests data, they pass the current product identifier (id). The backend generates a product list based on the product id using the updated cached data and returns it to the e-commerce app for display. Since products may be discontinued, and the cache is not updated, the displayed products may become inaccessible. To solve the cache update problem, it is necessary to periodically traverse the e-commerce welfare interface and update the cached data. If a user is accessing the app at this time, and the cache is also being updated via the HTTP interface, a user interface timeout will occur.
[0049] To address the aforementioned issues, this application provides a method, apparatus, device, and medium for dynamically updating cached data. This method is applied to updating product data. Upon detecting a timed update task, a cache key to be updated is determined. For this cache key, a preset product data interface is traversed to obtain at least one updated product data. This updated product data is then used as the cache value corresponding to the cache key to be updated. Updated cache data is generated based on the cache key and the cache value. The key-value name of the cache key to be updated is changed, allowing the updated cache data to dynamically replace and update the original cache data. This achieves smooth cache switching and dynamic cache updates, effectively avoiding the impact of data interface timeouts caused by cache updates when users access the feed, improving user experience, and solving the problem of untimely cache data updates in existing cached data update methods.
[0050] To facilitate understanding of the embodiments of this application, further explanations and descriptions will be provided below in conjunction with the accompanying drawings and specific embodiments. These embodiments do not constitute a limitation on the embodiments of this application.
[0051] Figure 1 This is a flowchart illustrating a method for dynamically updating cached data according to an embodiment of this application. In specific implementations, the method for dynamically updating cached data provided in this application can be applied to product data update scenarios, such as updating welfare product data in e-commerce apps. This application does not impose any limitations on this. Figure 1 As shown, the dynamic update method for cached data provided in this application embodiment may specifically include the following steps:
[0052] Step 110: If a scheduled update task is detected, determine the cache key to be updated.
[0053] Specifically, the cache key to be updated can be a key in the cache data. The cache data can be divided into cache data to be updated and original cache data that has not been updated. The cache data can exist in the form of key-value pairs. The cache key to be updated can be a key in the cache data to be updated, which is named New-Key. This application embodiment does not limit this.
[0054] In a specific implementation, this embodiment can preset a timed update task. The timed update task can have a corresponding update frequency, such as real-time update and timed update. Real-time update can be triggered in real time to dynamically update the cached data. Timed update can be set with a corresponding update time interval. The timed update task is triggered periodically to dynamically update the cached data. Of course, timed update can also be set with a fixed update time point, such as morning, noon, or early morning. This embodiment does not limit this.
[0055] As an example, taking scheduled updates with a set update interval as an example, the trigger time of the scheduled update task can be dynamically adjusted in advance according to actual needs, precisely controlling the cache update time. Specifically, the update time of the cached data can be determined based on the set update interval. Then, the system time can be obtained to determine whether the system time has reached the update time. If the update time has been determined, the scheduled update task can be triggered. Subsequently, a cache New-Key can be created as the cache key to be updated.
[0056] It should be noted that the dynamic update method for cached data in this embodiment can be applied not only to the update of welfare product data in e-commerce apps, but also to other apps that need to update cached data, such as messaging apps and audio apps. This application embodiment does not limit this.
[0057] Step 120: For the cache key to be updated, traverse the preset product data interface to obtain at least one product update data, and use the product update data as the cache value corresponding to the cache key to be updated.
[0058] Specifically, the product data interface can be used to obtain product update data. In this embodiment, product update data can be obtained by accessing the product data interface. The cached value can be used as the value in a key-value pair, forming a key-value pair with the cache key to be updated. This embodiment does not impose any restrictions on this.
[0059] Specifically, in this embodiment, for the cache key to be updated, each product data interface can be traversed and accessed to obtain product update data from each product data interface. Then, the product update data can be used as the cache value corresponding to the cache key to be updated, i.e., Value.
[0060] Step 130: Generate cache data to be updated based on the cache key to be updated and the cache value.
[0061] In a specific implementation, embodiments of this application can generate cache data to be updated using the cache key and cache value to be updated. For example, the cache value can be cached as Value in New-Key, and the cache data to be updated is obtained after the data in New-Key is completely updated.
[0062] Step 140: Change the key-value name of the cache key to be updated so that the cache data to be updated can dynamically replace and update the original cache data.
[0063] In a specific implementation, the original cached data can be unupdated cached data, which can consist of the original cache key and the original cache value. This application embodiment does not impose any restrictions on this.
[0064] In practical implementation, the key-value name of the cache key to be updated can be changed to the name of the original cache key. This allows for a smooth transition from the cache data to the cache data, enabling dynamic updates of the original cache data using the cache data to be updated. For users, they consistently access the original cache key corresponding to the original cache data, thus achieving a smooth switch to dynamic cache updates without being aware of data changes. This does not impact the user experience and solves the problem of untimely cache data updates in existing cache data update methods.
[0065] As an example, taking the original cache key as Old-Key, when a user accesses data, they typically access the data within Old-Key, i.e., retrieve the value corresponding to Old-Key. After determining the cache data to be updated, the New-Key within the cache data to be updated can be renamed to Old-Key. This way, the user only needs to access the data within Old-Key to obtain the updated cache data, achieving smooth cache switching and dynamic updates.
[0066] As can be seen, this embodiment of the application determines the cache key to be updated when a timed update task is detected, iterates through the preset product data interface for the cache key to be updated to obtain at least one product update data, and uses the product update data as the cache value corresponding to the cache key to be updated. Based on the cache key to be updated and the cache value, cache data to be updated is generated, and the key-value name of the cache key to be updated is changed so that the cache data to be updated can dynamically replace and update the original cache data, thereby achieving the purpose of smooth cache switching and dynamic cache updating, and solving the problem of untimely cache data updates in existing cache data update methods.
[0067] Reference Figure 2 This illustration shows a flowchart of a method for dynamically updating cached data according to an optional embodiment of this application. In specific implementations, the method for dynamically updating cached data provided in this embodiment can be applied to product data update scenarios, such as updating welfare product data in e-commerce apps. This embodiment does not impose any limitations on this. The method may specifically include the following steps:
[0068] Step 210: If a scheduled update task is detected, determine the cache key to be updated.
[0069] In its implementation, this embodiment can pre-set a scheduled update task. This scheduled update task can be triggered in real time or at regular intervals; this embodiment does not impose any restrictions on this. Taking a scheduled update task as an example, refer to... Figure 3 At this point, the scheduled update task can include, but is not limited to, the last cached data update time and update interval. The next cached data update time can be determined based on the last cached data update time and update interval. Subsequently, the system time can be obtained to determine whether the system time has reached the next cached data update time. If it is determined that the system time has reached the next cached data update time, the scheduled update task is triggered.
[0070] In an optional embodiment, before determining the cache key to be updated, this application embodiment may further include: obtaining preset scheduled task information and system time, wherein the scheduled task information includes an initial update time and an update interval; performing update calculations based on the initial update time and the update interval to obtain a cache data update time; determining whether the cache data update time matches the system time; and if the cache data update time matches the system time, determining that the scheduled update task is triggered. The initial update time can be the previous cache data update time, and the cache data update time can be the next cache data update time; this application embodiment does not impose any limitations on this.
[0071] Specifically, embodiments of this application can determine whether the system time is the same as the next cached data update time. If it is determined that the system time is the same as the next cached data update time, the cached data update time is determined to match the system time.
[0072] In one optional implementation, the present application embodiment determines the cache key to be updated, which may specifically include: obtaining a preset command line; using the command line to create a key within the cache service to obtain the cache key to be updated.
[0073] Specifically, the embodiments of this application can pre-build a cache data update system, and developers can preset command lines within the cache data update system. These command lines can be used to create cache keys to be updated, and the embodiments of this application do not impose any restrictions on this.
[0074] In specific implementations, the embodiments of this application can create the cache key to be updated using the command line before the scheduled update task is triggered, or they can create the cache key to be updated using the command line after the scheduled update task is triggered. This application example does not limit this.
[0075] As an example, refer to Figure 3 This example uses Redis as a cache to update the database. The default command line can be any Redis key insertion command; this example does not restrict this. You can use Redis key insertion commands to create a cached New-Key in Redis to serve as the key for the cache to be updated.
[0076] Step 220: Obtain the product identifier and determine the preset product data interface corresponding to the product identifier.
[0077] Specifically, the product identifier can be a product ID or product name, etc., and this application embodiment does not limit this.
[0078] In specific implementations, a product identifier can correspond to a product data interface. That is, when obtaining product data through the product data interface corresponding to a product identifier, all the obtained product data can belong to that product identifier. This application embodiment does not impose any restrictions on this. Of course, the product data interface can also be used to obtain product data for different product identifiers. When obtaining product data, the product identifier can be used to obtain only the product data corresponding to that product identifier from the product data interface.
[0079] Step 230: For the cache key to be updated, perform product data traversal on the product data interface to obtain the product update data corresponding to the product identifier.
[0080] Specifically, the product update data may include one or more product data, which can be used to display on the product app page. This application embodiment does not limit this.
[0081] Specifically, in this embodiment, each product data interface can be traversed for the cache key to be updated. Then, all data can be obtained from the product data interface. Subsequently, the obtained data can be filtered using the product identifier to obtain the data corresponding to the product identifier, which can then be used as the product update data. Alternatively, data can be directly filtered from the product data interface using the product identifier to obtain the product update data corresponding to the product identifier.
[0082] As an example, refer to Figure 3 If a shopping app includes VIP benefit products, and one of the product data sources in the app's feed is a VIP benefit product, this VIP benefit product can be obtained through the shopping app's benefit HTTP interface. When dynamically updating cached data, a scheduled task can be used to iterate through the shopping app's benefit HTTP interface, filtering the interface data by product identifier to obtain the updated product data.
[0083] Step 240: Construct key-value pairs based on the cache key to be updated and the cache value to obtain the cache data to be updated.
[0084] In a specific implementation, this embodiment of the application can construct the cache data to be updated in the form of key-value pairs, using the cache key to be updated and the cache value as the key and value, respectively. For example, the key-value pair format can be cache key to be updated: cache value; this example does not limit this. Therefore, when updating the cache, simply modifying the name of the cache key to be updated can achieve a smooth cache switching, improving the user experience.
[0085] Step 250: Change the key-value name of the cache key to be updated so that the cache data to be updated can dynamically replace and update the original cache data.
[0086] Optionally, the above-mentioned key-value name change for the cache key to be updated may specifically include the following sub-steps:
[0087] Sub-step 2501: Extract the original cache key from the original cache data.
[0088] Specifically, the original cache data may include the original cache key and the original cache value corresponding to the original cache key, but this application embodiment does not limit this.
[0089] In a specific implementation, the embodiments of this application can extract the original cache key from the original cache data, thereby determining the name of the original cache key so that the cache key to be updated can be renamed subsequently.
[0090] Sub-step 2502: Determine the key name information corresponding to the original cache key.
[0091] Specifically, the key name information can be the key name of the original cache key, such as Old-Key. This example does not impose any restrictions on this.
[0092] Sub-step 2503: Based on the key name information, overwrite and change the key name of the cache key to be updated.
[0093] In a specific implementation, this application embodiment can preset a key name change command to rename the key name of the cache key to be updated. Specifically, after determining the cache data to be updated and the key name of the original cache key, the key name change command can be executed to modify the key name of the cache key to be updated to the key name of the original cache key. Since the key name of the cache key to be updated has been modified, when accessing cache data, it is still only necessary to access the key name of the original cache key to obtain the latest cache data. This achieves the purpose of dynamically replacing and updating the original cache data with the cache data to be updated, effectively combining the features of Redis's rename command, flexibly updating the cache on a timed basis, solving the problem of data interface timeout caused by cache updates, and improving user experience.
[0094] As an example, refer to Figure 3 When New-Key is the name of the cache key to be updated, and Old-Key is the name of the original cache key, the updated product data obtained through iteration is cached as the value in the Redis service by creating a new New-Key. After the data in New-Key is completely updated, the name of New-Key is changed to the name of Old-Key using the Redis rename command. This achieves the dynamic replacement of the original cache data with the cache data to be updated. The user always accesses the data in Old-Key. The entire access process is transparent, without any lag or missing data, and achieves the goal of smooth cache switching and dynamic cache updates.
[0095] Step 260: Obtain the user's access request.
[0096] Specifically, the access request may carry an access key name, which can be the same as the key name corresponding to the original cached value; that is, the access key name can be an Old-Key, so that the access request can access the corresponding cached data through the access key name. This application embodiment does not impose any limitations on this. Of course, in specific implementations, the access request may also carry other information, such as, but not limited to, product identifiers, user identifiers, authentication information, etc. This application embodiment does not impose any limitations on this, to achieve functions such as data retrieval, user identification, and authentication.
[0097] Step 270: Based on the access request, retrieve cached data to obtain the data to be pushed.
[0098] Specifically, the data to be pushed may include product data to be pushed and displayed, but this application embodiment does not limit this.
[0099] In this implementation, the access key name can be extracted from the access request, such as Old-Key. Then, using the access key name, the cache key with the same name as the access key can be retrieved from the various cache keys included in the Redis caching service. The value corresponding to this cache key is then used as the data to be pushed. In this way, the client always accesses the corresponding cached data through the Old-Key key name. When the cached data is being updated, there is no need to wait for the cached data to be fully updated, and there is no lag issue.
[0100] Step 280: Push the data to be pushed to the user terminal, and the user terminal displays product data based on the data to be pushed.
[0101] Specifically, in this embodiment of the application, the user terminal can extract product data from the data to be pushed, and then display the product data through page rendering, thereby eliminating the need to wait for cached data to be updated and improving the user experience.
[0102] In summary, this application embodiment determines the cache key to be updated when a scheduled update task is detected, then obtains the product identifier and determines the preset product data interface corresponding to the product identifier. For the cache key to be updated, the product data interface is traversed to obtain the product update data corresponding to the product identifier. Key-value pairs are constructed based on the cache key to be updated and the cache value to obtain the cache data to be updated. The key-value name of the cache key to be updated is changed so that the cache data to be updated dynamically replaces and updates the original cache data. This flexible scheduled cache update solves the problem of data interface timeout caused by cache updates, thus solving the problem of untimely cache data updates in existing cache data update methods. When a user accesses data, the access request from the user is obtained, and cache data is retrieved based on the access request to obtain the data to be pushed. The data to be pushed is then pushed to the user, and the product data is displayed on the user's end. The user always accesses data through the same key name and will not perceive any lag caused by cache updates, effectively improving the user experience.
[0103] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of actions. However, those skilled in the art should know that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps may be performed in other orders or simultaneously.
[0104] like Figure 4 As shown, this application embodiment also provides a dynamic update device 400 for cached data, applied to product data updates, including:
[0105] The cache key to be updated determination module 410 is used to determine the cache key to be updated when a timed update task is detected to be triggered.
[0106] The traversal processing module 420 is used to traverse the preset product data interface for the cache key to be updated, obtain at least one product update data, and use the product update data as the cache value corresponding to the cache key to be updated.
[0107] The cache data generation module 430 is used to generate cache data to be updated based on the cache key to be updated and the cache value;
[0108] The key-value name changing module 440 is used to change the key-value name of the cache key to be updated, so that the cache data to be updated can dynamically replace and update the original cache data.
[0109] Optionally, the dynamic update device 400 for the cached data further includes:
[0110] The acquisition module is used to acquire preset timed task information and system time, wherein the timed task information includes the initial update time and update interval;
[0111] An update calculation module is used to perform update calculations based on the initial update time and the update interval to obtain the cached data update time.
[0112] The judgment module is used to determine whether the update time of the cached data matches the system time;
[0113] The triggering module is used to determine when the cached data update time matches the system time to trigger the scheduled update task.
[0114] Optionally, the cache key determination module 410 to be updated includes:
[0115] The command-line retrieval submodule is used to retrieve preset command lines;
[0116] The key creation submodule is used to create keys within the cache service using the command line to obtain the cache key to be updated.
[0117] Optionally, the traversal processing module 420 includes:
[0118] The product identifier acquisition submodule is used to acquire product identifiers and determine the preset product data interface corresponding to the product identifiers;
[0119] The traversal submodule is used to traverse the product data interface for the cache key to be updated, and obtain the product update data corresponding to the product identifier.
[0120] Optionally, the cache data generation module 430 is specifically used to construct key-value pairs based on the cache key to be updated and the cache value to obtain the cache data to be updated.
[0121] Optionally, the key-value name changing module 440 includes:
[0122] The original cache key extraction submodule is used to extract the original cache key from the original cache data;
[0123] The key name information determination submodule is used to determine the key name information corresponding to the original cache key;
[0124] The overwrite change submodule is used to overwrite the key name of the cache key to be updated based on the key name information.
[0125] Optionally, the dynamic update device 400 for the cached data further includes:
[0126] The access request acquisition module is used to acquire access requests from the user's client.
[0127] The retrieval module is used to retrieve cached data based on the access request to obtain the data to be pushed.
[0128] The push module is used to push the data to be pushed to the user terminal, and the user terminal displays product data based on the data to be pushed.
[0129] It should be noted that the dynamic update device for cached data provided in the embodiments of this application can execute the dynamic update method for cached data provided in any embodiment of this application, and has the corresponding functions and beneficial effects of executing the dynamic update method for cached data.
[0130] In a specific implementation, the aforementioned dynamic update device for cached data can be integrated into the device. This allows the device to determine the cache key to be updated and its corresponding cache value upon detecting a timed update task, thereby determining the cache data to be updated and changing the key-value name of the cache key to be updated. This enables the cache data to dynamically replace and update the original cache data, thus achieving smooth cache switching and dynamic cache updates as an electronic device. This electronic device can consist of two or more physical entities, or it can consist of a single physical entity. For example, an electronic device can be a personal computer (PC), a computer, a server, etc. This application embodiment does not impose specific limitations in this regard.
[0131] like Figure 5As shown, this application embodiment provides an electronic device including a processor 111, a communication interface 112, a memory 113, and a communication bus 114. The processor 111, communication interface 112, and memory 113 communicate with each other via the communication bus 114. The memory 113 stores computer programs. The processor 111, when executing the program stored in the memory 113, implements the steps of the dynamic update method for cached data provided in any of the aforementioned method embodiments. For example, the steps of the dynamic update method for cached data may include the following: upon detecting a timed update task trigger, determining a cache key to be updated; for the cache key to be updated, traversing a preset product data interface to obtain at least one product update data, and using the product update data as the cache value corresponding to the cache key to be updated; generating cached data to be updated based on the cache key to be updated and the cache value; changing the key name of the cache key to be updated so that the cached data to be updated dynamically replaces and updates the original cached data.
[0132] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the dynamic update method for cached data as provided in any of the foregoing method embodiments.
[0133] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0134] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for dynamically updating cached data, characterized in that, The method is applied to updating product data, and the method includes: If a scheduled update task is detected, determine the cache key to be updated; For the cache key to be updated, the preset product data interface is traversed to obtain at least one product update data, and the product update data is used as the cache value corresponding to the cache key to be updated. Generate cache data to be updated based on the cache key to be updated and the cache value; The key-value name of the cache key to be updated is changed so that the cache data to be updated can dynamically replace and update the original cache data; Changing the key-value name of the cache key to be updated includes: Extract the original cache key from the original cache data; Determine the key name information corresponding to the original cache key; The key name of the cache key to be updated is overwritten and changed based on the key name information; After changing the key-value name of the cache key to be updated, the process also includes: Obtain the user's access request; Based on the access request, cached data is retrieved to obtain the data to be pushed. The data to be pushed is pushed to the user terminal, and the user terminal displays product data based on the data to be pushed. The process of generating cache data to be updated based on the cache key to be updated and the cache value includes: The cache data to be updated is obtained by constructing key-value pairs based on the cache key to be updated and the cache value.
2. The method according to claim 1, characterized in that, Before determining the cache key to be updated, the process also includes: Obtain preset scheduled task information and system time, wherein the scheduled task information includes the initial update time and update interval; The cached data update time is obtained by performing update calculations based on the initial update time and the update interval. Determine whether the cached data update time matches the system time; If the cached data update time matches the system time, then the scheduled update task is determined to be triggered.
3. The method according to claim 1, characterized in that, The process of determining the cache key to be updated includes: Retrieve the default command line; Using the command line, a key is created within the cache service to obtain the cache key to be updated.
4. The method according to claim 1, characterized in that, The step involves iterating through a preset product data interface for the cache key to be updated to obtain at least one product update data, including: Obtain the product identifier and determine the preset product data interface corresponding to the product identifier; For the cache key to be updated, the product data interface is traversed to obtain the product update data corresponding to the product identifier.
5. A device for dynamically updating cached data, characterized in that, The device is used for updating product data and includes: The module for determining the cache key to be updated is used to determine the cache key to be updated when a scheduled update task is detected. The traversal processing module is used to traverse the preset product data interface for the cache key to be updated, obtain at least one product update data, and use the product update data as the cache value corresponding to the cache key to be updated. The cache data to be updated generation module is used to generate cache data to be updated based on the cache key to be updated and the cache value; The key-value name change module is used to change the key-value name of the cache key to be updated, so that the cache data to be updated can dynamically replace and update the original cache data. Changing the key-value name of the cache key to be updated includes: Extract the original cache key from the original cache data; Determine the key name information corresponding to the original cache key; The key name of the cache key to be updated is overwritten and changed based on the key name information; After changing the key-value name of the cache key to be updated, the process also includes: Obtain the user's access request; Based on the access request, cached data is retrieved to obtain the data to be pushed. The data to be pushed is pushed to the user terminal, and the user terminal displays product data based on the data to be pushed. The process of generating cache data to be updated based on the cache key to be updated and the cache value includes: The cache data to be updated is obtained by constructing key-value pairs based on the cache key to be updated and the cache value.
6. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the dynamic update method for cached data as described in any one of claims 1-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the dynamic update method for cached data as described in any one of claims 1-4.