File cleaning method, device, storage medium and equipment
By obtaining the reference records of each file in the file directory, determining the target file and cleaning it, the problem of unreasonable file cleaning in the existing technology is solved, and more efficient file management and resource utilization is achieved.
Patent Information
- Application Number
- CN202010675536.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-14
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2040-07-14
AI Technical Summary
The existing file cleaning solution deletes files at inappropriate time, resulting in re-downloading or synthesis when the file is used again, increasing the waiting time, consuming traffic and computing resources, resulting in waste of resources.
By detecting file cleaning events, obtain the reference records of each file in the file directory, including the historical reference of the file, determine the target file and clean it up.
Reasonable file cleaning according to the citation of the file, avoid unnecessary resource waste, and improve file management efficiency and resource utilization.
Smart Images

Figure CN113934692B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a file cleaning method, apparatus, storage medium, and device. Background Art
[0002] In the current software development process, due to the limitations of the disk space of mobile devices or the capacity of storage media such as memory cards, when the application is running, for files such as dynamic resource files generated from the network or during operation, they are generally cleared after use or the user actively chooses to clear them. However, the above files may be used again in the subsequent program operation. If the above clearing strategy is adopted, the files may be deleted at an inappropriate time, and the deleted files may be used again. When they are used again, they may need to be downloaded or synthesized again, which increases the waiting time, consumes traffic and more computing resources, and causes resource waste. Therefore, the existing file cleaning solutions are not perfect and need to be improved. Summary of the invention
[0003] The embodiments of the present disclosure provide a file cleaning method, apparatus, storage medium and device, which can optimize the existing file cleaning solution.
[0004] In a first aspect, an embodiment of the present disclosure provides a file cleaning method, comprising:
[0005] When it is detected that a file cleanup event corresponding to a first preset file directory is triggered, obtaining reference records of each file in the first preset file directory, wherein the reference records include historical references of the files;
[0006] Determine the target file according to the reference record;
[0007] The target file is cleared.
[0008] In a second aspect, an embodiment of the present disclosure provides a file cleaning device, comprising:
[0009] A reference record acquisition module, configured to acquire reference records of each file in the first preset file directory when a file cleanup event corresponding to the first preset file directory is detected to be triggered, wherein the reference records include historical references of the files;
[0010] A target file determination module, used for determining the target file according to the reference record;
[0011] The file clearing module is used to clear the target file.
[0012] In a third aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a file cleaning method as provided in an embodiment of the present disclosure.
[0013] In a fourth aspect, an embodiment of the present disclosure provides a mobile device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a file cleaning method as provided in an embodiment of the present disclosure is implemented.
[0014] The file cleaning solution provided in the embodiment of the present disclosure detects that the file cleaning event corresponding to the first preset file directory is triggered, obtains the reference records of each file in the first preset file directory, determines the target file according to the reference record, and performs cleaning on the target file. By adopting the above technical solution, when it is necessary to clean up a file directory, the historical citation situation of the file is obtained by obtaining the reference record of each file in the file directory, and then the files that can be cleaned are determined according to the citation situation, and the citation situation can reflect the importance of the file, so that the file cleaning can be performed more reasonably. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of a file cleaning method provided by an embodiment of the present disclosure;
[0016] Figure 2 A flowchart of another file cleaning method provided by an embodiment of the present disclosure;
[0017] Figure 3 A schematic diagram of a preset file directory provided in an embodiment of the present disclosure;
[0018] Figure 4 A structural block diagram of a file cleaning device provided in an embodiment of the present disclosure;
[0019] Figure 5 A structural block diagram of a mobile device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0020] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0021] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0022] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0023] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0024] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0025] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0026] In the following embodiments, each embodiment provides both optional features and examples. The various features recorded in the embodiments can be combined to form multiple optional solutions. Each numbered embodiment should not be regarded as only one technical solution.
[0027] Figure 1 The present invention provides a flowchart of a file cleaning method provided in an embodiment of the present invention. The method can be executed by a file cleaning device, wherein the device can be implemented by software and / or hardware and can generally be integrated in a mobile device. The mobile device can be, for example, a mobile phone, a tablet computer, a laptop computer, a personal digital assistant, and the like. Figure 1 As shown, the method includes:
[0028] Step 101: When it is detected that a file cleanup event corresponding to a first preset file directory is triggered, obtain reference records of each file in the first preset file directory.
[0029] The reference record includes the historical references of the file.
[0030] Exemplarily, the first preset file directory may be any file directory in the mobile device, or a pre-specified file directory. The files in the first preset file directory may be files of any type, or files of a specified type, such as dynamic resource files. Dynamic resource files may include files that need to occupy storage space on the mobile device, files from the network, files generated during the running of the application, etc.
[0031] For example, the triggering condition of the file cleaning event corresponding to the first preset file directory can be preset, such as timed triggering, triggering when receiving a trigger instruction from the user, or triggering when the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold. The preset threshold can be set according to actual conditions, such as the application type corresponding to the first preset file directory or the type of files stored therein, etc.
[0032] Exemplarily, the reference records of files can be centrally stored in one or more reference record files. The storage location of the reference record files is not limited. When there are multiple reference record files, a preset file directory can contain a reference record file. In this case, the reference record file can contain reference records corresponding to all files or some files in the preset file directory. When there is a reference record file, the reference record file can be stored in a specified location in a database or a mobile device. In this case, the reference record file can contain reference records of all files in the mobile device that have reference records. Optionally, the reference record can also exist in the corresponding file. For example, the reference record can be stored by rewriting the header information of the file, that is, the reference record of the file is stored in the header information of the file.
[0033] Optionally, the reference record may include the time when the file was referenced, the number of times it was referenced, or the frequency of being referenced, etc., and may also include the number of times the file was not referenced or the frequency of being not referenced, etc. Reference can also be understood as using, calling, occupying or performing file operations. Among them, not being referenced can be not being referenced under preset conditions, and the preset conditions can be set based on the running status of the application to which the file belongs. Exemplarily, taking the number of times it was not referenced as an example, it can be the number of times the file was not referenced after each startup of the application to which it belongs (it can also be a process or thread, or a business module). For example, after file a in application A is generated, application A is started 10 times, of which file a was referenced after 6 startups and file a was not referenced after 4 startups, then the number of times file a was not referenced is 4 times.
[0034] Step 102: Determine the target file according to the reference record.
[0035] Exemplarily, as described above, the information contained in the reference record can reflect the citation status of the file. Generally, the farther the reference time is from the current time, the fewer the number of references, the lower the frequency of reference, the more the number of non-references or the higher the frequency of non-reference, the lower the importance of the file. Therefore, files with low importance can be determined as target files. The probability of files with low importance being cited again is generally low, so they can be cleared first. While ensuring that important files are not cleared, the storage space of the mobile device is saved, the operation of re-downloading or synthesizing files is reduced, and system resources are saved.
[0036] Step 103: clear the target file.
[0037] In the disclosed embodiment, the specific method of clearing processing is not limited. For example, the target file can be transferred or cut to the recycle bin (wherein the files in the recycle bin can be deleted using certain strategies, such as scheduled deletion), or the target file can be directly deleted.
[0038] The file cleaning method provided in the embodiment of the present disclosure detects that the file cleaning event corresponding to the first preset file directory is triggered, obtains the reference records of each file in the first preset file directory, determines the target file according to the reference record, and performs cleaning on the target file. By adopting the above technical solution, when it is necessary to clean up a file directory, the reference status of each file in the file directory is obtained to obtain the reference status of the file, and then the files that can be cleaned are determined according to the reference status, and the reference status can reflect the importance of the file, so that the file cleaning can be performed more reasonably.
[0039] In some embodiments, before the file cleanup event corresponding to the first preset file directory is detected to be triggered, it also includes: detecting that a first preset type file is generated in the first preset file directory; counting the references of the first preset type file, and updating the reference record corresponding to the first preset type file according to the statistical results. The advantage of this setting is that after the file is generated, the references of the file are counted, and the reference record corresponding to the file is updated in time, ensuring that the target file can be determined based on accurate reference records when the file cleanup event is triggered. Among them, the preset type can be set according to actual needs, and can be determined based on the file format (such as video format or picture format, etc.) or the source of the file (such as downloaded from the Internet or generated during the operation of the application, etc.).
[0040] In some embodiments, the first preset file directory is included in the file directory of the first application, and the first preset file directory corresponds to the first business module of the first application. The advantage of such a setting is that the file directory of the application can be divided according to the business to obtain multiple preset file directories, each preset file directory corresponds to a business module, which is convenient for storing, managing and cleaning files according to the business. Taking the recommendation engine application (Application, APP) as an example, news and videos can be recommended in the APP, and news pages and video pages can be displayed in the APP interface. The news page corresponds to a business module, and the video page corresponds to a business module. A preset file directory can be set for storing files corresponding to the news page, and a preset file directory can be set for storing files corresponding to the video page.
[0041] In some embodiments, the reference record includes a reference count. The reference count can specifically be the number of times it has been referenced or the number of times it has not been referenced. Exemplarily, the reference count is the number of times it has not been referenced. The advantage of such a setting is that if the scheme of the number of times it has been referenced is adopted, there is no reference record for files that have not been referenced, so it is necessary to traverse all the files in the preset file directory to determine the target file, while if the scheme of the number of times it has not been referenced is adopted, there is a reference record for files that have not been referenced, so the target file can be directly and accurately determined without scanning all the files.
[0042] In some embodiments, the statistics of the references of the first preset type file are collected, and the reference records corresponding to the first preset type file are updated according to the statistical results, including: after detecting that the first business module is started, the reference count corresponding to the first preset type file is increased by 1; if the first preset type file is referenced before the first business module ends, the reference count corresponding to the first preset type file is reduced by 1. The advantage of such a setting is that the reference count can be counted more accurately. After the first business module corresponding to the first preset file directory in the application is started, it is assumed that the files in the first preset file directory are not referenced at this time, so the reference count corresponding to the file is increased by 1, and during the operation of the first business module, if the first preset type file is referenced, the corresponding reference count is reduced by 1, and the reference counts corresponding to other unreferenced files, such as the second preset type file, will be increased by 1 due to the startup of the first business module.
[0043] In some embodiments, the reference record includes a reference count, and the reference count indicates the number of times it has not been referenced. The determining the target file according to the reference record includes: determining the file with the largest reference count corresponding to the first preset file directory as the target file. The advantage of such a setting is that the target file can be determined quickly and reasonably. Among them, the number of times a file in the first preset file directory has not been referenced can refer to the application corresponding to the first preset file directory or the business module in the corresponding application, and the number of times the file has not been referenced in each operation process after the file is generated. Exemplarily, the reference count corresponding to the first file in the first preset file directory can be obtained in the following manner: after the first file is generated, the reference count corresponding to the first file is initialized to 0, after detecting that the first application or the first business module corresponding to the first preset file directory is started, the reference count corresponding to the first file is increased by 1, and if the first file is referenced before the first application or the first business module ends its operation, the reference count corresponding to the first file is reduced by 1. Among them, the first file can be any file in the first preset file directory.
[0044] In some embodiments, the target file can also be comprehensively determined in combination with the last use time. Optionally, when there are multiple files with the largest reference count corresponding to the first preset file directory, the file with the last reference time farthest from the current time can be determined as the target file. Optionally, if none of the files with the largest reference count have been referenced, the file with the generation time farthest from the current time can be determined as the target file. Optionally, the reference count and the difference between the last reference time and the current time can be weighted summed, and the target file can be determined based on the weighted summation result. For example, the reference count is recorded as N, the difference between the last reference time and the current time is recorded as T, and the weighted summation result is recorded as S, then S=k1*N+k2*T, where k1 and k2 represent weight coefficients, and the specific values can be set according to the actual situation. Generally, k1 can be greater than k2, and a file with the largest S value or a specified number of files with larger S values can be determined as the target file.
[0045] In some embodiments, the file with the largest reference count corresponding to the first preset file directory is determined as the target file, including: determining the file with the largest reference count corresponding to the first preset file directory as a candidate file; if it is determined that the candidate file meets the preset cleaning condition, the candidate file is determined as the target file, wherein the preset cleaning condition includes at least one of not being referenced, not being in the preset whitelist, and not being referenced after the first business module is started. The advantage of such a setting is that it can effectively prevent important files from being accidentally deleted. If the candidate file is in use, deleting the candidate file may cause program errors; if the candidate file is in the preset whitelist, it means that the candidate file is a file that needs to be protected; if the candidate file has been referenced after the first business module is started, it means that it may be referenced again in the near future and needs to be temporarily deleted. If the candidate file is not being referenced, is not in the preset whitelist, and has not been referenced after the first business module is started, it can be determined as the final target file. Among them, the preset whitelist can exist in the form of a file path list, and the files included in the preset whitelist can be set according to the specific needs of the application or business module, such as files such as built-in special effects, startup animations, or opening screen videos of the application, which need to be included in the preset whitelist. In addition, it is also possible to support the user to independently set a preset whitelist. Optionally, if it is determined that the candidate file does not meet the preset cleaning condition, the candidate file can be re-determined. For example, after reducing the reference count corresponding to the current candidate file by 1, the file with the largest reference count in the first preset file directory is selected as the candidate file.
[0046] In some embodiments, determining whether the candidate file is not being referenced includes: attempting to obtain a lease for the candidate file, and if the attempt is successful, determining that the candidate file is not being referenced. The advantage of such a setting is that it can accurately determine whether the file is being referenced, that is, more accurately determine the file status of the candidate file.
[0047] In the prior art, if an application needs to determine the file status in a certain process during operation, such as determining whether a file is being used by other processes or threads, a solution based on file locks is generally used. The solution based on file locks requires the file user to explicitly call the lock method to construct a file lock (FileLock) at each place where the file is used (such as reading, writing, opening or deleting, etc.), and call the release method to release the file lock after the file is used. When the application needs to determine the file status, it tries to obtain the file lock. If it is obtained, it means that the file status is not occupied, otherwise it means that the file status is occupied. This solution has the following problems. If the file user does not actively lock, then the application will get an incorrect result when determining the file status, and if no other process or thread needs to determine the file status, it will cause the file user's locking operation to become meaningless and waste resources. In the embodiment of the present disclosure, the process or thread of the application does not need to acquire the file lock when it needs to determine the current status of a file. Instead, it directly determines the current status of the file accurately through the result of the attempt to acquire the lease of the file. Moreover, when the file needs to be used, there is no need to lock the file, thereby saving system resources. In the existing file lock-based solution, the party using the file can be understood as the production end, and the party wanting to determine the file status can be understood as the consumer end. When the production end wants to operate the file, it needs to actively lock the file, and the production end also needs to obtain the file lock before operating the file, that is, both the production end and the consumer end have operations. If the production end forgets to actively add the file lock or forgets to release the file lock after use, it will cause the consumer end to be unable to obtain the accurate file status; and the solution in the embodiment of the present disclosure is equivalent to the production end having no additional file locking operation, but only needs to try to obtain the file lease when acting as a consumer end, that is, the file user does not need to care about whether the file will be judged in the use status in other processes or threads, and can unilaterally judge whether the file is occupied only at the place of use. The file system adds the lease status to the file being used (accessed) by default, and the logic of judging the lease can be added at the place of use. If no judgment is needed, no work needs to be done. This solution is imperceptible to the file user, and only the module for judging the file status needs to be processed. The file status can be accurately obtained without adding any business logic code, thereby reducing unnecessary operations and saving system resources.
[0048] Exemplarily, a lease is also called a lease. In the file system of an operating system such as Linux, there is a lease mechanism for file system management. The file system here may include, for example, a fourth-generation extended file system (Fourth Extended Filesystem, EXT4) or EXT3, etc. Exemplarily, the operating system loaded in the mobile device in the present disclosure may be a Linux system, or a system based on Linux, etc. For example, the kernel of the Android operating system is implemented based on Linux, and the file system used is the EXT4 system of Linux, so there is also a lease mechanism. In the lease mechanism, when a file is operated, the file system will mark the status of obtaining the lease in an area of the file header. The marking process is usually implemented in the kernel layer. At this time, if another process tries to obtain the lease, it will fail. In the embodiment of the present disclosure, the lease mechanism already existing in the operating system can be used to achieve the purpose of determining the file status. Therefore, when it is necessary to determine whether the candidate file is not being referenced, try to obtain the lease of the candidate file.
[0049] Exemplarily, the mobile device in the embodiments of the present disclosure may be loaded with a Linux-based operating system, such as an Android operating system.
[0050] Exemplarily, attempting to obtain the lease of the candidate file includes failing to obtain the lease of the candidate file if the lease identifier in the file header of the candidate file is read through a preset interface. The advantage of such a setting is that it is possible to accurately determine whether the attempt is successful. Among them, the preset interface can be a Java Native Interface (JNI). If the lease identifier (added by the file system) in the file header of the candidate file can be read through the JNI interface, it can be considered that the file system has given the lease of the candidate file to other processes or threads, and obtaining the lease has failed. Optionally, if the lease identifier in the file header of the candidate file is not read through the preset interface, the attempt to obtain the lease of the candidate file is successful.
[0051] In some embodiments, the detection that the file cleanup event corresponding to the first preset file directory is triggered includes: when it is detected that the size of the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold, it is determined that the file cleanup event corresponding to the first preset file directory is detected to be triggered. The advantage of such a setting is that different preset thresholds can be set for different preset file directories to trigger file cleanup events in a targeted manner. For example, the application includes a player module and a shooting module, which correspond to directory 1 and directory 2 respectively. The preset threshold corresponding to directory 1 is 100M, and the preset threshold corresponding to directory 2 is 300M. Then, when the storage space occupied by directory 1 reaches 100M, the corresponding file cleanup event is triggered, and the corresponding file cleanup event is triggered only when the storage space occupied by directory 2 reaches 300M.
[0052] Figure 2 A flowchart of another file cleaning method provided for an embodiment of the present disclosure is provided. The embodiment of the present disclosure is optimized based on the various optional schemes in the above embodiments. Taking the first application as an example, the file directory of the first application is divided into multiple preset file directories, and each preset file directory corresponds to a business module in the first application. Taking the first preset file directory as an example, the first preset file directory corresponds to the first business module. Similarly, the second preset file directory corresponds to the second business module. Other preset file directories also correspond to corresponding business modules, which are not listed here. Each preset file directory corresponds to a preset threshold. When the storage space occupied by the preset file directory reaches or exceeds the corresponding preset threshold, the file cleaning event corresponding to the preset file directory is triggered. The reference count is reflected by the number of times it has not been referenced. Figure 3 A schematic diagram of a preset file directory provided in an embodiment of the present disclosure, such as Figure 3 As shown, the first application is divided into n business modules ( Figure 3 Only the preset file directories corresponding to the first business module and the nth business module are shown in the figure). The preset file directory stores reference record files, which store reference counts corresponding to the files in the directory. Taking directory 1 as an example, the reference count of file 1 (file1) is 6, the reference count of file 2 (file2) is 3, and the reference count of file 3 (file3) is 4.
[0053] The following description is made by taking the first preset file directory as an example. Specifically, the method may include the following steps:
[0054] Step 201: Detect that the first service module is started.
[0055] Before step 201, the method may further include detecting that a first preset type file is generated in a first preset file directory, and initializing a reference count corresponding to the first preset type file to 0. The preset type file may be a dynamic resource file, and the first preset type file may be any dynamic resource file generated in the first preset file directory.
[0056] Step 202: For each file in the first preset file directory corresponding to the first business module, increase the corresponding reference count by 1.
[0057] In this step, after the process corresponding to the first business module is started, each directory resource (that is, each file) in the first preset file directory corresponding to the first business module is traversed and the reference count is increased once, that is, the number of unreferenced times for each file is increased by one by default.
[0058] Step 203: For each file in the first preset file directory, if it is determined that the current file is referenced before the first business module ends running, the corresponding reference count is reduced by 1.
[0059] That is, in this step, it is determined whether each file is used during the execution of the program corresponding to the first business module. If used, the number of times it is not referenced is reduced by 1. If not used, the reference count may remain unchanged.
[0060] Step 204, determine whether the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold, if so, execute step 205; otherwise, end the process.
[0061] Step 205: Determine the file with the largest reference count in the first preset file directory as a candidate file.
[0062] Step 206 , determine whether the candidate file meets the preset cleaning condition, if so, execute step 208 ; otherwise, execute step 207 .
[0063] Exemplarily, it is possible to first determine whether the candidate file is in use. If so, execute step 207. If not, continue to determine whether the candidate file is in a preset whitelist. If so, execute step 207. If not, continue to determine whether it has been used since the current process was started (that is, the first business module was started this time). If it has been used, execute step 207. If it has not been used, execute step 208.
[0064] Optionally, when there are multiple candidate files, that is, when there are multiple files with the largest reference counts, some of the candidate files may meet the preset cleaning conditions, that is, there are candidate files that can become the target files. In this case, step 208 can be executed directly (or step 207 can be executed first, the reference count corresponding to the candidate files that do not meet the preset cleaning conditions can be reduced by 1, and then step 208 can be executed), the candidate files that meet the preset cleaning conditions can be determined as target files, the target files can be cleared, and then the process returns to step 204.
[0065] Step 207 , reduce the reference count corresponding to the candidate file by 1, and return to execute step 205 .
[0066] Generally, if a candidate file does not meet the preset cleaning conditions, it will continue to fail to meet the preset cleaning conditions in the subsequent determination process. Therefore, it can also be excluded when re-determining the candidate files. In other words, this step can also be to clear the reference count corresponding to the preferred file, which can further improve the file cleaning efficiency.
[0067] Step 208 : determine the candidate file as the target file, clear the target file, and return to step 204 .
[0068] For example, after the target file is cleared, since the file size of the target file is uncertain, it is possible that the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold. Therefore, the process may return to step 204 to continue judging. If this situation still exists, the target file may continue to be determined and cleared until the storage space occupied by the first preset file directory is less than the preset threshold.
[0069] The file cleaning method provided by the disclosed embodiment divides the file directory of the application into multiple preset file directories, each preset file directory corresponds to a business module in the first application, and each preset file directory corresponds to a preset threshold. When the storage space occupied by the preset file directory reaches or exceeds the corresponding preset threshold, the file cleaning event corresponding to the preset file directory is triggered, and the target file is determined based on the number of times it has not been referenced and cleaned up until the size of the occupied storage space is less than the corresponding preset threshold. The above scheme does not require each business module to clean up the file every time, and a single resource file can be retained until the next program or module is started and used, without the need to download or synthesize again, and even if the file cleaning is triggered, the cleaned target file has a large number of times it has not been referenced, which means that it is less important and has a lower probability of being used again, that is, the least commonly used or completely unused resources are deleted, which greatly improves resource utilization.
[0070] Figure 4This is a structural block diagram of a file cleaning device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware, and can generally be integrated in a mobile device, and can perform file cleaning by executing a file cleaning method. Figure 4 As shown, the device comprises:
[0071] The reference record acquisition module 401 is used to acquire the reference records of each file in the first preset file directory when it is detected that the file cleaning event corresponding to the first preset file directory is triggered, wherein the reference record includes the historical reference status of the file;
[0072] A target file determination module 402, configured to determine a target file according to the reference record;
[0073] The file clearing module 403 is used to clear the target file.
[0074] The file cleaning device provided in the embodiment of the present disclosure detects that the file cleaning event corresponding to the first preset file directory is triggered, obtains the reference records of each file in the first preset file directory, determines the target file according to the reference record, and performs cleaning on the target file. By adopting the above technical solution, when it is necessary to clean up a file directory, the reference status of each file in the file directory is obtained by obtaining the reference record, and then the files that can be cleaned are determined according to the reference status, and the reference status can reflect the importance of the file, so that the file cleaning can be performed more reasonably.
[0075] Optionally, the device may further include:
[0076] A file generation detection module, used for detecting a preset type of file generated in the first preset file directory before the file cleaning event corresponding to the first preset file directory is detected to be triggered;
[0077] The reference record updating module is used to collect statistics on the references of the first preset type file after detecting that the first preset type file is generated in the first preset file directory, and update the reference record corresponding to the first preset type file according to the statistical result.
[0078] Optionally, the first preset file directory is included in a file directory of a first application, and the first preset file directory corresponds to a first business module of the first application; the reference record includes a reference count;
[0079] The counting of the cited status of the first preset type file and updating the reference record corresponding to the first preset type file according to the statistical result includes:
[0080] After detecting that the first service module is started, adding 1 to the reference count corresponding to the first preset type file;
[0081] If the first preset type file is referenced before the first business module ends running, the reference count corresponding to the first preset type file is reduced by 1.
[0082] Optionally, the reference record includes a reference count, where the reference count indicates the number of times the file has not been referenced, and determining the target file according to the reference record includes:
[0083] The file with the largest reference count in the first preset file directory is determined as the target file.
[0084] Optionally, determining the file with the largest reference count in the first preset file directory as the target file includes:
[0085] Determine the file with the largest reference count in the first preset file directory as a candidate file;
[0086] If it is determined that the candidate file meets the preset cleaning condition, the candidate file is determined as the target file, wherein the preset cleaning condition includes at least one of not being referenced, not being in a preset whitelist, and not being referenced after the first business module is started.
[0087] Optionally, determining whether the candidate file is not being referenced includes:
[0088] An attempt is made to obtain a lease for the candidate file. If the attempt is successful, it is determined that the candidate file is not being referenced.
[0089] Optionally, the detecting that a file cleanup event corresponding to the first preset file directory is triggered includes:
[0090] When it is detected that the size of the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold, it is determined that a file cleaning event corresponding to the first preset file directory is detected to be triggered.
[0091] Reference below Figure 5 , which shows a schematic diagram of the structure of a mobile device 500 suitable for implementing the embodiment of the present disclosure. The mobile device in the embodiment of the present disclosure may include, but is not limited to, mobile devices such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5The mobile device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0092] like Figure 5 As shown, the mobile device 500 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the mobile device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0093] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the mobile device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The mobile device 500 is shown with various devices, but it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have instead.
[0094] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0095] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0096] The computer-readable medium may be included in the mobile device, or may exist independently without being installed in the mobile device.
[0097] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the mobile device, the mobile device: when detecting that a file cleaning event corresponding to a first preset file directory is triggered, obtains reference records of each file in the first preset file directory; determines the target file according to the reference record; and clears the target file.
[0098] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0099] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0100] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, a file clearing module may also be described as a "module for clearing the target file".
[0101] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0102] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0103] According to one or more embodiments of the present disclosure, a file cleaning method is provided, comprising:
[0104] When it is detected that a file cleanup event corresponding to a first preset file directory is triggered, obtaining reference records of each file in the first preset file directory;
[0105] Determine the target file according to the reference record;
[0106] The target file is cleared.
[0107] Furthermore, before the file cleaning event corresponding to the first preset file directory is detected to be triggered, the method further includes:
[0108] It is detected that a file of a first preset type is generated in a first preset file directory;
[0109] Statistics are collected on the citation status of the first preset type file, and the citation record corresponding to the first preset type file is updated according to the statistical result.
[0110] Further, the first preset file directory is included in the file directory of the first application, and the first preset file directory corresponds to the first business module of the first application; the reference record includes a reference count;
[0111] The counting of the cited status of the first preset type file and updating the reference record corresponding to the first preset type file according to the statistical result includes:
[0112] After detecting that the first service module is started, adding 1 to the reference count corresponding to the first preset type file;
[0113] If the first preset type file is referenced before the first business module ends running, the reference count corresponding to the first preset type file is reduced by 1.
[0114] Further, the reference record includes a reference count, the reference count indicates the number of times it has not been referenced, and determining the target file according to the reference record includes:
[0115] The file with the largest reference count in the first preset file directory is determined as the target file.
[0116] Further, determining the file with the largest reference count in the first preset file directory as the target file includes:
[0117] Determine the file with the largest reference count in the first preset file directory as a candidate file;
[0118] If it is determined that the candidate file meets the preset cleaning condition, the candidate file is determined as the target file, wherein the preset cleaning condition includes at least one of not being referenced, not being in a preset whitelist, and not being referenced after the first business module is started.
[0119] Further, determining whether the candidate file is not being referenced includes:
[0120] An attempt is made to obtain a lease for the candidate file. If the attempt is successful, it is determined that the candidate file is not being referenced.
[0121] Further, the detecting that a file cleaning event corresponding to the first preset file directory is triggered includes:
[0122] When it is detected that the size of the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold, it is determined that a file cleaning event corresponding to the first preset file directory is detected to be triggered.
[0123] According to one or more embodiments of the present disclosure, a file cleaning device is provided, comprising:
[0124] A reference record acquisition module, configured to acquire reference records of each file in a first preset file directory when detecting that a file cleanup event corresponding to the first preset file directory is triggered;
[0125] A target file determination module, used for determining the target file according to the reference record;
[0126] The file clearing module is used to clear the target file.
[0127] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0128] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0129] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A file cleaning method, characterized in that: include: It is detected that a first preset type file is generated in a first preset file directory, wherein the first preset type file is any dynamic resource file generated in the first preset file directory, the first preset file directory is included in a file directory of a first application, and the first preset file directory corresponds to a first business module of the first application; Statistics are collected on the citation status of the first preset type file, and a reference record corresponding to the first preset type file is updated according to the statistical result, wherein the reference record includes a reference count, and the reference count indicates the number of times the file is not referenced, and the number of times a file in the first preset file directory is not referenced is the number of times the file is not referenced in each operation process of the first business module after the file is generated; When it is detected that a file cleanup event corresponding to a first preset file directory is triggered, obtaining reference records of each file in the first preset file directory; According to the reference record, determining a file in the first preset file directory with the largest reference count and not being referenced as a target file; Clearing the target file; The step of collecting statistics on the citation status of the first preset type file and updating the citation record corresponding to the first preset type file according to the statistical result includes: After detecting that the first service module is started, adding 1 to the reference count corresponding to the first preset type file; If the first preset type file is referenced before the first business module ends running, the reference count corresponding to the first preset type file is reduced by 1.
2. The method according to claim 1, characterized in that The step of determining the file in the first preset file directory with the largest reference count and not being referenced as the target file includes: Determine the file in the first preset file directory that has the largest reference count and is not being referenced as a candidate file; If it is determined that the candidate file meets a preset cleaning condition, the candidate file is determined as a target file, wherein the preset cleaning condition includes not being in a preset whitelist.
3. The method according to claim 2, characterized in that Determining whether the candidate file is not being referenced includes: An attempt is made to obtain a lease for the candidate file. If the attempt is successful, it is determined that the candidate file is not being referenced.
4. The method according to any one of claims 1 to 3, characterized in that: The detecting that a file cleaning event corresponding to the first preset file directory is triggered includes: When it is detected that the size of the storage space occupied by the first preset file directory reaches or exceeds the corresponding preset threshold, it is determined that a file cleaning event corresponding to the first preset file directory is detected to be triggered.
5. A file cleaning device, characterized in that: include: A file generation detection module, used to detect a preset type file generated in a first preset file directory, wherein the first preset type file is any dynamic resource file generated in the first preset file directory, the first preset file directory is included in a file directory of a first application, and the first preset file directory corresponds to a first business module of the first application; a reference record updating module, used to count the references of the first preset type of file, and update the reference record corresponding to the first preset type of file according to the statistical result, wherein the reference record includes a reference count, the reference count indicates the number of times the file has not been referenced, and the number of times a file in the first preset file directory has not been referenced is the number of times the file has not been referenced in each operation process of the first business module after the file is generated; A reference record acquisition module, configured to acquire reference records of each file in a first preset file directory when detecting that a file cleanup event corresponding to the first preset file directory is triggered; A target file determination module, configured to determine, according to the reference record, a file in the first preset file directory that has the largest reference count and is not being referenced as a target file; A file clearing module, used for clearing the target file; Among them, the target file determination module is used to: after detecting that the first business module is started, add 1 to the reference count corresponding to the first preset type file; if the first preset type file is referenced before the first business module ends running, then reduce 1 to the reference count corresponding to the first preset type file.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
7. A mobile device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
File cleaning method, device and terminal
CN104317840A
Application program management method and device, storage medium and terminal
CN109033247A