A method, device and storage medium for managing cached data
By generating target cache files based on cache paths, the problem of DiskLruCache technology being unable to manage multi-level cache data is solved, the size and number of cache files are reduced, the pressure on local storage space is alleviated, and the functionality of cache data management is expanded.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-30
- Publication Date
- 2026-04-14
AI Technical Summary
The existing DiskLruCache technology cannot manage multi-level cached data, and the cached files in the index directory occupy a large amount of space, which increases the caching pressure on local storage space.
By generating target cache files based on cache paths, the target cache data is stored in the index directory of the local storage space. Whether it is single-level or multi-level cache data, a target cache file is generated in the index directory, reducing the file size and number.
It broadens the business scope of cache data management methods, reduces the caching pressure on local storage space, and improves the management capabilities of multi-level cache data.
Smart Images

Figure CN116303298B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for managing cached data. Background Technology
[0002] A client application is an application that provides local services to users, corresponding to a server, and can run on smart terminals. To improve data retrieval efficiency when a user accesses data on a server using a client, a common method is to cache the data accessed by the user in local storage. When the user accesses the same data again, the data is retrieved directly from local storage.
[0003] With the rapid development of smartphones and mobile internet, client-side functions are becoming increasingly sophisticated. Smart terminals store a large amount of cached data in their local storage space. Currently, DiskLruCache technology is mainly used to manage this cached data. The file format of the cached files in the index directory of DiskLruCache technology is key-value pair format.
[0004] In the process of realizing this invention, at least the following technical problems were found in the prior art:
[0005] Because the cached files in the index directory of DiskLruCache technology are generated based on the data content of the data to be cached, DiskLruCache technology can only manage single-level cached data (such as a single image) and does not have the ability to manage multi-level cached data (such as a folder containing multiple images). Furthermore, the cached files in the index directory also occupy a large amount of cache space. Summary of the Invention
[0006] This invention provides a method, apparatus, device, and storage medium for managing cached data, in order to solve the problem that existing methods for managing cached data cannot generate cache files based on multi-level cached data, reduce the space occupied by cached files in the index directory of the local cache space, and alleviate the cache pressure on the local storage space.
[0007] According to an embodiment of the present invention, a method for managing cached data is provided, the method comprising:
[0008] In response to detecting a data caching instruction sent by the client, the target cached data and cache name corresponding to the data caching instruction are obtained;
[0009] The target cache data is stored in a cache directory in the local storage space, and the cache path of the target cache data in the cache directory is obtained;
[0010] Based on the cache name and the cache path, a target cache file is generated and stored in the index directory of the local storage space.
[0011] According to another embodiment of the present invention, a management device for cached data is provided, the device comprising:
[0012] The target cache data acquisition module is used to acquire the target cache data and cache name corresponding to the data cache instruction in response to the detection of a data cache instruction sent by the client.
[0013] The cache path acquisition module is used to store the target cache data in a cache directory in the local storage space and acquire the cache path of the target cache data in the cache directory.
[0014] The target cache file storage module is used to generate a target cache file based on the cache name and the cache path, and store the target cache file in an index directory in the local storage space.
[0015] According to another embodiment of the present invention, an electronic device is provided, the electronic device comprising:
[0016] At least one processor; and
[0017] A memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the cache data management method according to any embodiment of the present invention.
[0019] According to another embodiment of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions, the computer instructions being used to cause a processor to execute and implement the cache data management method described in any embodiment of the present invention.
[0020] The technical solution of this invention, in response to the detection of a data caching instruction sent by a client, stores the target cache data corresponding to the data caching instruction in a cache directory in the local storage space. Based on the cache name corresponding to the data caching instruction and the cache path of the target cache data in the cache directory, a target cache file is generated and stored in an index directory in the local storage space. This ensures that regardless of whether the target cache data is single-level or multi-level cache data, a target cache file will be generated and stored in the index directory. This solves the problem that existing cache data management methods cannot generate cache files based on multi-level cache data, broadening the business scope of cache data management methods. Furthermore, since the target cache file in this embodiment is generated based on the cache path, compared to existing technical solutions that generate target cache files based on target cache data, the file size and number of target cache files in this embodiment are significantly reduced, alleviating the caching pressure on the local storage space.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 A flowchart illustrating a method for managing cached data according to an embodiment of the present invention;
[0024] Figure 2 This is a schematic diagram of a caching architecture in a local storage space provided in an embodiment of the present invention;
[0025] Figure 3 A flowchart illustrating another method for managing cached data provided in one embodiment of the present invention;
[0026] Figure 4 A flowchart illustrating a method for generating historical records files according to an embodiment of the present invention;
[0027] Figure 5 This is a schematic diagram illustrating the format of a historical record file provided in one embodiment of the present invention;
[0028] Figure 6This is a schematic diagram of the structure of a cache data management device provided in one embodiment of the present invention;
[0029] Figure 7 This is a schematic diagram of the structure of an electronic device provided in one embodiment of the present invention. Detailed Implementation
[0030] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] Figure 1 This is a flowchart illustrating a cached data management method according to an embodiment of the present invention. This embodiment is applicable to situations where a smart terminal manages the cache of data accessed by a client. The method can be executed by a cached data management device, which can be implemented in hardware and / or software and can be configured within the smart terminal. Figure 1 As shown, the method includes:
[0033] S110. In response to detecting a data caching instruction sent by the client, obtain the target cached data and cache name corresponding to the data caching instruction.
[0034] In one specific embodiment, when the client detects a data access instruction, it is determined whether the access link corresponding to the data access instruction is a first-time access link. If so, a data caching instruction is generated based on the target cached data corresponding to the data access instruction, and the data caching instruction is sent to the cached data management device.
[0035] Specifically, the target cached data includes single-level cached data and / or multi-level cached data. Single-level cached data can be used to represent a single piece of data, the smallest unit of measurement. For example, single-level cached data includes, but is not limited to, a single image, a single video, or a single script. Multi-level cached data can be used to represent directory data at least two levels. For example, multi-level cached data can be a directory folder containing one or more single-level cached data, such as directory folder 1 containing image a and image b, or directory folder 2 containing image a and video b. Of course, multi-level cached data can also be a directory folder containing one or more subdirectories. For example, A / B / C / a.jpg indicates that directory folder A contains first-level subdirectory folder B, second-level subdirectory folder B contains third-level subdirectory folder C, and third-level subdirectory folder C contains image a. It is easy to understand that a directory folder and each level of subdirectory folder can contain one or more single-level cached data and / or one or more subdirectory folders. The specific data architecture of multi-level cached data is not limited here.
[0036] Specifically, in response to detecting a data caching instruction from the client, the cache name in the data caching instruction is retrieved, or a cache name corresponding to the data caching instruction is generated. For example, the cache name can be generated using a message digest algorithm, a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value to ensure the integrity and consistency of transmitted information. The algorithm used to generate the cache name is not limited here.
[0037] S120. Store the target cache data in the cache directory of the local storage space, and obtain the cache path of the target cache data in the cache directory.
[0038] For example, the cache directory can be a "cache" folder, which can be defined in the local storage space using the DiskLruCache class provided by the operating system. The DiskLruCache class is a class that manages disk cache, and the folder name for the cache directory is not limited here. Of course, the cache directory can contain one or more directory folders, each of which can be a single-level or multi-level folder.
[0039] In one specific embodiment, storing the target cache data in a cache directory within local storage space includes: storing the target cache data in the cache directory within local storage space based on the cache name. When storing the target cache data in the cache directory within local storage space, it is typically necessary to create a new cache folder. In this embodiment, the folder name of the newly created cache folder under the cache directory is the cache name.
[0040] Specifically, the cache path can be used to represent the cache location of the target cache data in the cache directory. The cache path includes the folder path of the cache folder generated based on the target cache data and the directory path of the cache folder in the cache directory. For example, assuming that the folder name of the cache folder created in the cache directory based on the target cache data is aa, and the directory path of the cache folder in the cache directory is files / cache, then the storage path of the target cache data is files / cache / aa.
[0041] S130. Based on the cache name and cache path, generate the target cache file and store the target cache file in the index directory of the local storage space.
[0042] In this embodiment, the target cache file is in key-value pair format. The cache key of the target cache file is generated based on the cache name, and the cache value of the target cache file is generated based on the cache path. In a specific embodiment, generating the target cache file based on the cache name and cache path includes: using the cache name as the cache key of the target cache file and the cache path as the cache value of the target cache file.
[0043] In one specific embodiment, the index directory can be a peer, parent, or child of the cache directory. For example, when the index directory and the cache directory are peers, assuming the cache directory's path is files / cache, the index directory's path is files / index; when the index directory is a parent of the cache directory, assuming the index directory's path is files / index, the cache directory's path is files / index / cache; when the index directory is a child of the cache directory, assuming the cache directory's path is files / cache, the index directory's path is files / cache / index. The hierarchical relationship between the index directory and the cache directory is not limited here.
[0044] Figure 2 This is a schematic diagram illustrating a caching architecture in local storage space according to an embodiment of the present invention. Specifically, Figure 2 Taking the index directory and cache directory at the same level as an example, Figure 2In this context, "cache" refers to the cache directory. "08a46cc34850" and "260d6a155e7d" in the cache directory represent the cache folders generated when the target cache data is stored in the cache directory. Cache data 1 under the "08a46cc34850" cache folder includes the "js" folder and the vendors.js file. Cache data 2 under the "260d6a155e7d" cache folder includes the "js" folder and the index.html file. Figure 2 In the index, "index" represents the index directory. "08a46cc34850" in the index directory represents cache file 1 generated based on cache data 1. The cache key of cache file 1 is cache / 08a46cc34850. "260d6a155e7d" represents cache file 2 generated based on cache data 2. The cache key of cache file 2 is cache / 260d6a155e7d.
[0045] Specifically, in the existing methods for managing cached data, since the target cache file is generated based on the target cache data, if the target cache data is single-level cache data, such as a 500K image A, then the file size of the target cache file will be around 500K; if the target cache data is multi-level cache data, such as a directory folder containing a 500K image A and a 600K image B, then two target cache files will be generated in the index directory, with target cache file 1 having a file size of around 500K and target cache file 2 having a file size of around 600K.
[0046] However, since the target cache file in this embodiment of the invention is generated based on the cache path, regardless of whether the target cache data is single-level cache data or multi-level cache data, only one target cache file will be generated and stored in the index directory, and the file size of the target cache file will be much smaller than the file size of the target cache file generated based on the target cache data.
[0047] The technical solution of this embodiment, in response to the detection of a data caching instruction sent by the client, stores the target cache data corresponding to the data caching instruction in a cache directory in the local storage space. Based on the cache name corresponding to the data caching instruction and the cache path of the target cache data in the cache directory, a target cache file is generated and stored in an index directory in the local storage space. This ensures that regardless of whether the target cache data is single-level or multi-level cache data, a target cache file will be generated and stored in the index directory. This solves the problem that existing cache data management methods cannot generate cache files based on multi-level cache data, thus broadening the business scope of cache data management methods. Furthermore, since the target cache file in this embodiment is generated based on the cache path, compared with the existing technical solutions that generate target cache files based on target cache data, the file size and number of target cache files in this embodiment are greatly reduced, alleviating the caching pressure on the local storage space.
[0048] Based on the above embodiments, specifically, the method further includes: in response to detecting a data query instruction sent by the client, obtaining a query name corresponding to the data query instruction; using the target cache file corresponding to the query name in the index directory as a query cache file; obtaining query cache data from the cache directory based on the cache path corresponding to the query cache file, and sending the query cache data to the client.
[0049] In one specific embodiment, when the client detects a data access instruction, it is determined whether the access link corresponding to the data access instruction is a first-time access link. If not, a data query instruction is generated based on the query name corresponding to the data access instruction, and the data query instruction is sent to the management device of cached data.
[0050] Specifically, the algorithm for generating the query name is the same as the algorithm for generating the cache name. For example, the query name can be generated using a message digest algorithm. No limitation is made to the algorithm used to generate the query name here.
[0051] Based on the above Figure 2 For example, assuming the query name is "260d6a155e7d", the query cache file found in the index directory based on the query name will be: Figure 2 The cache file 2 in the cache directory is used to find query cache data, including the "js" folder and the index.html file, based on the cache path cache / 260d6a155e7d in cache file 2. This query cache data is then sent to the client.
[0052] The advantage of this setup is that it increases the ability of the cache data management device to query multi-level cache data, further expanding the business scope of the cache data management method.
[0053] Based on the above embodiments, specifically, the method further includes: in response to detecting a data modification instruction sent by the client, obtaining the modification name and data modification parameters corresponding to the data modification instruction; using the target cache file corresponding to the modification name in the index directory as the modification cache file, and obtaining the modification cache data from the cache directory based on the cache path corresponding to the modification cache file; performing a modification operation on the modification cache data based on the data modification parameters, and storing the modified modification cache data in the cache directory.
[0054] For example, data modification parameters include, but are not limited to, modifying the replacement name of cached data and modifying the replacement data corresponding to the cached data in the cached data, etc. Correspondingly, modification operations include, but are not limited to, modifying the data name of the cached data and modifying the cached data in the cached data, etc. The data modification parameters are not limited here.
[0055] Specifically, the algorithm for generating the modified name is the same as the algorithm for generating the cache name. For example, the modified name can be generated using a message digest algorithm. No limitation is made to the algorithm used to generate the modified name here.
[0056] Based on the above Figure 2 For example, assuming the name is changed to "260d6a155e7d", the change cache file found in the index directory based on the name change will be: Figure 2 In cache file 2, based on the cache path cache / 260d6a155e7d in cache file 2, the modified cache data found in the cache directory includes the "js" folder and the index.html file. Based on the data modification parameters, the modified cache data is modified and the modified cache data is stored in the cache directory.
[0057] The advantage of this setup is that it increases the ability of the cache data management device to modify multi-level cache data, further broadening the business scope of the cache data management method.
[0058] Based on the above embodiments, specifically, the method further includes: in response to detecting a data deletion instruction, obtaining the deletion name corresponding to the data deletion instruction; using the target cache file corresponding to the deletion name in the index directory as the deletion cache file, and obtaining the deletion cache data from the cache directory based on the cache path corresponding to the deletion cache file; deleting the deletion cache file from the index directory in the local storage space, and deleting the deletion cache data from the cache directory in the local storage space.
[0059] In one specific embodiment, the data deletion instruction can be sent by the client or generated by the cached data management device.
[0060] Specifically, the algorithm for generating deleted names is the same as the algorithm for generating cached names. For example, deleted names can be generated using a message digest algorithm. No limitation is made here regarding the algorithm for generating deleted names.
[0061] Based on the above Figure 2 For example, assuming the deleted name is "260d6a155e7d", the deleted cache file found in the index directory based on the deleted name will be: Figure 2 The cache file 2 in the index directory was searched based on the cache path cache / 260d6a155e7d in cache file 2. The cached data found included the "js" folder and the index.html file. Cache file 2 was then removed from the index directory, and the "260d6a155e7d" cache folder was also removed from the cache directory.
[0062] The advantage of this setup is that it increases the ability of the cache data management device to delete multi-level cache data, further expanding the business scope of the cache data management method.
[0063] Figure 3 This is a flowchart illustrating another method for managing cached data according to an embodiment of the present invention. The embodiments of the present invention further refine the cached data management method described in the above embodiments. For example... Figure 3 As shown, the method includes:
[0064] S210. In response to detecting a data caching instruction sent by the client, obtain the target cached data and cache name corresponding to the data caching instruction.
[0065] S220. Store the target cache data in the cache directory of the local storage space, and obtain the cache path of the target cache data in the cache directory.
[0066] S230: Based on the cache name and cache path, generate the target cache file and store the target cache file in the index directory of the local storage space.
[0067] Based on the above embodiments, specifically, generating a target cache file based on the cache name and cache path includes: generating a target key based on the cache name and a first encryption algorithm, and generating a target value based on the cache path and a second encryption algorithm; using the target key as the cache key of the target cache file, and using the target value as the cache value of the target cache file.
[0068] Specifically, the cached data management device provides an encryption interface, through which any encryption algorithm can be connected. For example, when the cached data management device initializes, it obtains a first encryption algorithm and a second encryption algorithm through the encryption interface. Specifically, the first encryption algorithm and the second encryption algorithm can be the same or different.
[0069] For example, the first encryption algorithm or the second encryption algorithm includes, but is not limited to, the International Data Encryption Algorithm (IDEA), the Digital Signature Algorithm (DSA), and the Advanced Encryption Standard (AES), etc. There is no limitation on the first encryption algorithm and the second encryption algorithm here.
[0070] Correspondingly, when searching for, modifying, or deleting cache files in the index directory of the local storage space, it is necessary to first perform a decryption operation on the cache key of each target cache file in the index directory, and then perform the search operation. Alternatively, after finding, modifying, or deleting a cache file, it is necessary to perform a decryption operation on the cache key of the cache file, and then retrieve the query cache data from the cache directory based on the cache path obtained from the decryption operation.
[0071] The advantage of this setup is that existing methods for managing cached data do not have encryption capabilities. This embodiment of the invention adds encryption functionality to the cached data management device, further expanding the business scope of the cached data management method.
[0072] S240. In response to detecting a preset operation command sent by the client, obtain the operation identifier, operation name, and occupied space corresponding to the preset operation command.
[0073] In this embodiment, the preset operation instruction is a data caching instruction, a data query instruction, a data modification instruction, or a data deletion instruction. Specifically, when the preset operation instruction is a data caching instruction, the operation identifier is the cache identifier and the operation name is the cache name; when the preset operation instruction is a data query instruction, the operation identifier is the query identifier and the operation name is the query name; when the preset operation instruction is a data modification instruction, the operation identifier is the modification identifier and the operation name is the modification name; and when the preset operation instruction is a data deletion instruction, the operation identifier is the deletion identifier and the operation name is the deletion name.
[0074] For example, the operation identifier can be composed of at least one of the following: text, numbers, special characters, uppercase letters, and lowercase letters. There is no limitation on the operation identifier here. For instance, the cache identifier is represented by "STORE", the query identifier by "READ", the modification identifier by "MODIFY", and the delete identifier by "CLEAN".
[0075] In this embodiment, the occupied space includes the file space occupied by the operation cache file corresponding to the preset operation instruction and / or the data space occupied by the operation cache data.
[0076] Specifically, when the preset operation instruction is a data caching instruction, the operation cache file is the target cache file, and the operation cache data is the target cache data; when the preset operation instruction is a data query instruction, the operation cache file is the query cache file, and the operation cache data is the query cache data; when the preset operation instruction is a data modification instruction, the operation cache file is the modification cache file, and the operation cache data is the modification cache data; when the preset operation instruction is a data deletion instruction, the operation cache file is the deletion cache file, and the operation cache data is the deletion cache data.
[0077] S250: Based on the operation identifier, operation name, and space occupied, generate a history file and store the history file in the index directory.
[0078] Specifically, the history file records operation records consisting of an operation identifier, operation name, and occupied space. These operation records can be storage records, query records, modification records, or deletion records. In one specific embodiment, the history file uses a linked list to store the operation records. Specifically, a new operation record is inserted at the head of the linked list. When target cached data is accessed, the operation record corresponding to the target cached data is moved to the head of the linked list. When the linked list is full, the operation record at the tail of the linked list is deleted.
[0079] Figure 4 This is a flowchart illustrating a method for generating a history file according to an embodiment of the present invention. Specifically, in response to detecting a data caching instruction sent by a client, the target cache data corresponding to the data caching instruction is saved in a cache directory, a target cache file is generated based on the cache name and the storage path of the target cache data in the cache directory, the cache file is stored in an index directory, and a storage record generated based on the cache identifier, cache name, and occupied space is added to the history file.
[0080] Specifically, in response to detecting a data query command sent by the client, the system obtains the cache path of the query cache file in the index directory based on the query name corresponding to the data query command, retrieves the query cache data from the cache directory based on the cache path, sends the query cache data to the client, and adds the query record generated based on the query identifier, query name, and occupied space to the history file.
[0081] Specifically, in response to detecting a data deletion command sent by the client, the system retrieves the deletion cache file in the index directory based on the deletion name corresponding to the data deletion command, retrieves the deletion cache data from the cache directory based on the cache path corresponding to the deletion cache file, deletes the deletion cache file from the index directory, deletes the deletion cache data from the cache directory, and adds the deletion record generated based on the deletion identifier, deletion name, and occupied space to the history file.
[0082] Specifically, in response to detecting a data modification command sent by the client, the system obtains the cache path of the modification cache file in the index directory based on the modification name corresponding to the data modification command, retrieves the modification cache data from the cache directory based on the cache path, performs modification operations on the modification cache data based on the data modification parameters, and adds the modification record generated based on the modification identifier, modification name, and occupied space to the history file.
[0083] Figure 5 This is a schematic diagram illustrating the format of a history file according to an embodiment of the present invention. Specifically, each operation record in the history file sequentially includes an operation identifier, an operation name, file space occupied, and data space occupied.
[0084] Based on the above embodiments, specifically, after storing the target cache file in the index directory of the local storage space, the method further includes: determining the cache parameters corresponding to the local storage space based on the operation identifier and operation name in the history file; if the cache parameters do not meet the preset parameter conditions, using a preset cache replacement algorithm to generate a data deletion instruction; wherein, the cache parameters include at least one of the number of files corresponding to the index directory, the index space occupied by the index directory, and the cache space occupied by the cache directory.
[0085] Specifically, based on the operation identifier and operation name in the history file, the cache parameters corresponding to the local storage space are determined, including: based on the cache identifier, deletion identifier, cache name, and deletion name in the history table, the cache parameters corresponding to the local storage space are determined. Specifically, the cache identifier and cache name constitute the cache dataset. A filtering operation is performed on the cache dataset based on the deletion identifier and deletion name. The data volume corresponding to the filtered cache dataset is the number of files corresponding to the index directory.
[0086] Specifically, the index space represents the sum of the file space occupied by each target cache file under the index directory, and the cache space represents the sum of the data space occupied by each reference cache data file under the cache directory. The reference cache data includes target cache data, modified cache data, and query cache data.
[0087] Specifically, the preset parameter conditions include at least one of the following: the number of files meets a preset range, the index space occupancy meets a preset index space occupancy range, and the cache space occupancy meets a preset cache space occupancy range. For example, the preset number range is [0 10000], the preset index space occupancy range is [0 20M], and the preset cache space occupancy range is [0 10G]. Here, there are no limitations on the preset number range, the preset index space occupancy range, and the preset cache space occupancy range.
[0088] For example, the preset cache replacement algorithms include, but are not limited to, the Least Recently Used (LRU) algorithm or the Least Recently Used (LRU) algorithm. The LRU algorithm is used to indicate the deletion of target cache files that have not been accessed within a certain period, while the LRU algorithm is used to indicate the deletion of target cache files that have been accessed the fewest times within a certain period. No limitation is placed on the preset cache replacement algorithm used here.
[0089] The advantage of this setting is that it allows for timely cleanup of local cache space, avoiding putting operational pressure on smart terminal devices.
[0090] The technical solution of this embodiment, in response to the detection of a preset operation instruction sent by the client, obtains the operation identifier, operation name, and occupied space corresponding to the preset operation instruction, generates a history file based on the operation identifier, operation name, and occupied space, and stores the history file in an index directory. The preset operation instruction is a data caching instruction, a data query instruction, a data modification instruction, or a data deletion instruction. The occupied space includes the file occupied space of the operation cache file corresponding to the preset operation instruction and / or the data occupied space of the operation cache data. This solves the problem that existing cache data management methods cannot manage cache files or cache data based on occupied space, and further broadens the business scope of cache data management methods.
[0091] Figure 6 This is a schematic diagram of a cached data management device provided in one embodiment of the present invention. Figure 6 As shown, the device includes: a target cache data acquisition module 310, a cache path acquisition module 320, and a target cache file storage module 330.
[0092] Among them, the target cache data acquisition module 310 is used to acquire the target cache data and cache name corresponding to the data cache instruction in response to the detection of the data cache instruction sent by the client;
[0093] The cache path acquisition module 320 is used to store the target cache data in the cache directory in the local storage space and to obtain the cache path of the target cache data in the cache directory.
[0094] The target cache file storage module 330 is used to generate a target cache file based on the cache name and cache path, and store the target cache file in an index directory in the local storage space.
[0095] The technical solution of this embodiment, in response to the detection of a data caching instruction sent by the client, stores the target cache data corresponding to the data caching instruction in a cache directory in the local storage space. Based on the cache name corresponding to the data caching instruction and the cache path of the target cache data in the cache directory, a target cache file is generated and stored in an index directory in the local storage space. This ensures that regardless of whether the target cache data is single-level or multi-level cache data, a target cache file will be generated and stored in the index directory. This solves the problem that existing cache data management methods cannot generate cache files based on multi-level cache data, thus broadening the business scope of cache data management methods. Furthermore, since the target cache file in this embodiment is generated based on the cache path, compared with the existing technical solutions that generate target cache files based on target cache data, the file size and number of target cache files in this embodiment are greatly reduced, alleviating the caching pressure on the local storage space.
[0096] Based on the above embodiments, specifically, the device further includes:
[0097] The cached data query module is used to respond to the detection of a data query command sent by the client and obtain the query name corresponding to the data query command.
[0098] Use the target cache file in the index directory that corresponds to the query name as the query cache file;
[0099] Based on the cache path corresponding to the query cache file, retrieve the query cache data from the cache directory and send the query cache data to the client.
[0100] Based on the above embodiments, specifically, the device further includes:
[0101] The cached data modification module is used to respond to the detection of a data modification command sent by the client and obtain the modification name and data modification parameters corresponding to the data modification command.
[0102] The target cache file corresponding to the modified name in the index directory is used as the modification cache file, and the modification cache data is obtained from the cache directory based on the cache path corresponding to the modification cache file;
[0103] The modified cache data is modified based on the data modification parameters, and the modified cache data is stored in the cache directory.
[0104] Based on the above embodiments, specifically, the device further includes:
[0105] The cached data deletion module is used to obtain the deletion name corresponding to the data deletion command in response to the detection of a data deletion command.
[0106] The target cache file corresponding to the deletion name in the index directory is used as the deletion cache file, and the deletion cache data is obtained from the cache directory based on the cache path corresponding to the deletion cache file;
[0107] Delete cached files from the index directory in the local storage space, and delete cached data from the cache directory in the local storage space.
[0108] Based on the above embodiments, specifically, the device further includes:
[0109] The history file generation module is used to respond to the detection of a preset operation command sent by the client, and to obtain the operation identifier, operation name and space occupied corresponding to the preset operation command;
[0110] Based on the operation identifier, operation name, and space occupied, a history file is generated and stored in the index directory;
[0111] The preset operation instructions are data caching instructions, data query instructions, data modification instructions, or data deletion instructions. The space occupied includes the file space occupied by the operation cache file corresponding to the preset operation instructions and / or the data space occupied by the operation cache data.
[0112] Based on the above embodiments, specifically, the device further includes:
[0113] The data deletion instruction generation module is used to determine the cache parameters corresponding to the local storage space based on the operation identifier and operation name in the history file after storing the target cache file in the index directory of the local storage space.
[0114] If the cache parameters do not meet the preset parameter conditions, the preset cache replacement algorithm is used to generate a data deletion instruction;
[0115] The cache parameters include at least one of the following: the number of files corresponding to the index directory, the index space occupied by the index directory, and the cache space occupied by the cache directory.
[0116] Based on the above embodiments, specifically, the target cache file storage module 330 is used for:
[0117] Based on the cache name and the first encryption algorithm, generate the target key, and based on the cache path and the second encryption algorithm, generate the target value.
[0118] Use the target key as the cache key of the target cache file, and use the target value as the cache value of the target cache file.
[0119] The cache data management device provided in the embodiments of the present invention can execute the cache data management method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0120] Figure 7 This is a schematic diagram of an electronic device provided according to one embodiment of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device 10 may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown in this embodiment, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0121] like Figure 7As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor 11. The processor 11 can perform various appropriate actions and processes based on the computer programs stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0122] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0123] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as methods for managing cached data.
[0124] In some embodiments, the method for managing cached data may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the cached data management method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the cached data management method by any other suitable means (e.g., by means of firmware).
[0125] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0126] Embodiment 5 of the present invention also provides a computer-readable storage medium storing computer instructions for causing a processor to execute a cache data management method, the method comprising:
[0127] In response to the detection of a data caching command sent by the client, obtain the target cached data and cache name corresponding to the data caching command;
[0128] Store the target cache data in the cache directory in the local storage space, and obtain the cache path of the target cache data in the cache directory;
[0129] Based on the cache name and cache path, a target cache file is generated and stored in an index directory in the local storage space.
[0130] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0131] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0132] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0133] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0134] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0135] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for managing cached data, characterized in that, include: In response to detecting a data caching instruction sent by a client, the system obtains the target cache data and cache name corresponding to the data caching instruction; wherein, the target cache data includes multi-level cache data, which is used to represent at least two levels of directory data, and the cache name is the folder name of the cache folder newly created under the cache directory for the target cache data; The target cache data is stored in a cache directory in the local storage space, and the cache path of the target cache data in the cache directory is obtained; Based on the cache name and the cache path, a target cache file is generated and stored in the index directory of the local storage space; Wherein, the target cache file is in key-value pair format, the cache key of the target cache file is the cache name, and the cache value of the target cache file is the cache path; or, the cache key of the target cache file is obtained by encrypting the cache name using a first encryption algorithm, and the cache value of the target cache file is obtained by encrypting the cache path using a second encryption algorithm. The method further includes: In response to detecting a preset operation command sent by the client, the operation identifier, operation name, and space occupied corresponding to the preset operation command are obtained; Based on the operation identifier, the operation name, and the space occupied, a history record file is generated and stored in the index directory; The preset operation instruction is a data caching instruction, a data query instruction, a data modification instruction, or a data deletion instruction. The occupied space includes the file space occupied by the operation cache file corresponding to the preset operation instruction and the data space occupied by the operation cache data.
2. The method according to claim 1, characterized in that, The method further includes: In response to detecting a data query command sent by the client, obtain the query name corresponding to the data query command; Use the target cache file corresponding to the query name in the index directory as the query cache file; Based on the cache path corresponding to the query cache file, query cache data is retrieved from the cache directory and sent to the client.
3. The method according to claim 1, characterized in that, The method further includes: In response to detecting a data modification instruction sent by the client, the modification name and data modification parameters corresponding to the data modification instruction are obtained; The target cache file corresponding to the modified name in the index directory is used as the modification cache file, and the modification cache data is obtained from the cache directory based on the cache path corresponding to the modification cache file; Based on the data modification parameters, the modification cache data is modified, and the modified cache data is stored in the cache directory.
4. The method according to claim 1, characterized in that, The method further includes: In response to the detection of a data deletion command, obtain the deletion name corresponding to the data deletion command; The target cache file corresponding to the deleted name in the index directory is used as the deleted cache file, and the deleted cache data is obtained from the cache directory based on the cache path corresponding to the deleted cache file; The cache file is deleted from the index directory in the local storage space, and the cache data is deleted from the cache directory in the local storage space.
5. The method according to claim 1, characterized in that, After storing the target cache file in an index directory in local storage space, the method further includes: Based on the operation identifier and operation name in the historical record file, determine the cache parameters corresponding to the local storage space; If the cache parameters do not meet the preset parameter conditions, a preset cache replacement algorithm is used to generate a data deletion instruction; The cache parameters include at least one of the following: the number of files corresponding to the index directory, the index space occupied by the index directory, and the cache space occupied by the cache directory.
6. The method according to claim 1, characterized in that, The step of generating the target cache file based on the cache name and the cache path includes: Based on the cache name and the first encryption algorithm, a target key is generated, and based on the cache path and the second encryption algorithm, a target value is generated. The target key is used as the cache key of the target cache file, and the target value is used as the cache value of the target cache file.
7. A management device for cached data, characterized in that, include: The target cache data acquisition module is used to acquire the target cache data and cache name corresponding to the data cache instruction in response to the detection of a data cache instruction sent by the client; wherein, the target cache data includes multi-level cache data, the multi-level cache data is used to represent at least two levels of directory data, and the cache name is the folder name of the cache folder newly created under the cache directory of the target cache data; The cache path acquisition module is used to store the target cache data in a cache directory in the local storage space and acquire the cache path of the target cache data in the cache directory. The target cache file storage module is used to generate a target cache file based on the cache name and the cache path, and store the target cache file in an index directory in the local storage space; Wherein, the target cache file is in key-value pair format, the cache key of the target cache file is the cache name, and the cache value of the target cache file is the cache path; or, the cache key of the target cache file is obtained by encrypting the cache name using a first encryption algorithm, and the cache value of the target cache file is obtained by encrypting the cache path using a second encryption algorithm. The history record file generation module is used to obtain the operation identifier, operation name, and space occupied corresponding to the preset operation instruction in response to the detection of the preset operation instruction sent by the client. Based on the operation identifier, the operation name, and the space occupied, a history record file is generated and stored in the index directory; The preset operation instruction is a data caching instruction, a data query instruction, a data modification instruction, or a data deletion instruction. The occupied space includes the file space occupied by the operation cache file corresponding to the preset operation instruction and the data space occupied by the operation cache data.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the method for managing cached data according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method for managing cached data as described in any one of claims 1-6.
Citation Information
Patent Citations
Index storage method and device, file searching method and device, electronic equipment and medium
CN114676096A