Method for cleaning cache files, electronic device, storage medium and chip
By calculating the cleanup score of cache files, infrequently used cache files in electronic devices are intelligently cleaned up, solving the problem of poor user experience in existing technologies and improving the utilization efficiency of cache space.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2023-12-29
- Publication Date
- 2026-04-21
AI Technical Summary
In existing technologies, the methods for clearing cache files on electronic devices often result in the deletion of frequently used cache files, or require manual operation by the user, leading to a poor user experience.
By obtaining attribute information of cached files, such as the last access time, file size, and number of accesses, a cleanup score is calculated, and cached files are deleted in descending order of score until the cache space meets the requirements.
It enables intelligent cleaning of cache files that users do not use frequently, improving the user experience, and maximizing the use of cache space when new files need to be cached.
Smart Images

Figure CN120281959B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a method for cleaning up cache files, an electronic device, a storage medium, and a chip. Background Technology
[0002] Electronic devices are becoming increasingly powerful, allowing users to make calls, watch videos, listen to music, and so on. To achieve fast response times for these functions, cache files related to these functions are usually cached in electronic devices.
[0003] However, electronic devices have limited storage space and cannot cache related files indefinitely. Therefore, it is necessary to clean up the cache space used to cache these files. Currently, the method usually involves cleaning up the oldest cached files based on their cache time. This method tends to delete frequently used cached files. Alternatively, when the remaining cache space is low, users are prompted to manually select cached files to clean up. This method requires user intervention and results in a poor user experience. Summary of the Invention
[0004] This application provides a method, electronic device, storage medium, and chip for cleaning up cache files, which can intelligently clean up cache files that users do not use frequently, thereby improving the user experience.
[0005] To achieve the above objectives, the first aspect of this application adopts the following technical solution:
[0006] This application provides a method for clearing cache files, including:
[0007] When the remaining space in the cache space does not meet the first condition, the attribute information of each cache file in the cache space is obtained. The attribute information of the cache file includes at least one of the following: the time when the cache file was last accessed, the file size of the cache file, and the number of times the cache file was accessed.
[0008] The cleanup score for each cache file is obtained based on its attribute information.
[0009] Delete cache files in descending order of cleanup score until the remaining space in the cache space meets the first condition.
[0010] In this application, the probability of a cache file being accessed again is determined by comprehensively considering the time of its most recent access, its file size, and the number of times it has been accessed. The higher the probability of a cache file being accessed again, the lower its cleanup score; conversely, the lower the probability of a cache file being accessed again, the higher its cleanup score. Therefore, deleting cache files in descending order of cleanup score allows the retention of cache files with a higher probability of being accessed again, while deleting cache files with a lower probability of being accessed again. This achieves intelligent cleanup of cache files that users do not frequently use, thereby improving the user experience.
[0011] As another implementation of the first aspect of this application, before determining that the remaining space of the cache space does not satisfy the first condition, the method further includes:
[0012] After receiving an instruction to cache the first cached file in the cache space, the remaining space of the cache space is obtained;
[0013] Determine whether the remaining space of the cache space satisfies the first condition;
[0014] After the remaining space in the cache file satisfies the first condition, the method further includes:
[0015] The first cached file is cached in the cache space.
[0016] This application can be configured to determine whether to clean up cached files based on the remaining space in the cache space when any cached file needs to be cached in the cache space, thereby maximizing the storage of more cached files in the cache space.
[0017] As another implementation of the first aspect of this application, before determining that the remaining space of the cache space does not satisfy the first condition, the method further includes:
[0018] During idle periods, at preset times, or at preset time cycles, obtain the remaining space of the cache space;
[0019] Determine whether the remaining space of the cache space satisfies the first condition.
[0020] This application allows setting an idle time period, a preset time, or a preset time cycle to execute the cache clearing process. Executing the process during an idle time period avoids reducing the efficiency of other processes by executing the cache clearing process while the electronic device is performing other processes. Executing the cache clearing process at a preset time or within a preset time cycle enables automatic triggering of the cache clearing process, avoiding user intervention and improving the level of intelligence.
[0021] As another implementation of the first aspect of this application, the cleanup score of each cache file is obtained based on the attribute information of each cache file, including:
[0022] The first cleanup weight score is obtained based on the time difference between the most recent access time of the cached file and the current time.
[0023] The second cleanup weight score is obtained based on the file size of the cached file;
[0024] The third cleanup weight score is obtained based on the number of times the cached file is accessed;
[0025] The cleaning score is obtained based on the first cleaning weight score, the second cleaning weight score, and the third cleaning weight score. The time difference and the cleaning score are positively correlated, the file size and the cleaning score are positively correlated, and the number of accesses and the cleaning score are inversely correlated.
[0026] In this application, different parameters can be set to correspond to different cleanup weight scores, and the final cleanup score is obtained based on the different cleanup weight scores. This method is highly scalable, and other parameters can be added as reference parameters for the cleanup score as needed.
[0027] As another implementation of the first aspect of this application, the step of obtaining a first cleanup weight score based on the time difference between the most recent access time of the cached file and the current time includes:
[0028]
[0029] in, The first cleanup weight score for the nth cache file. Let 'a' be the time difference between the most recent access time of the nth cache file and the current time, where 'a' is a time constant.
[0030] In this application, cached files that have been accessed in the last few days are more likely to be accessed again. Therefore, a time constant 'a' is set. 'a' can be set according to the situation, such as 3, 5, 7, or 10 days, so that the weight score of cached files accessed in the last few days changes at a lower rate, while the weight score of cached files accessed before the last few days changes at a higher rate.
[0031] In practical applications, "2" is just one example; it can be any other value greater than 1.
[0032] As another implementation of the first aspect of this application, the step of obtaining the second cleanup weight score based on the file size of the cached file includes:
[0033]
[0034] in, The second cleanup weight score for the nth cache file. Let be the file size of the nth cached file, and b be an estimated file size constant, which is related to the maximum cache capacity of the cache space and the estimated number of cached files.
[0035] In this application, the estimated file size constant is obtained by setting the cache size and the expected number of caches. This ensures that, based on the expected storage of a specific number of cache files, larger cache files are easier to clean up, while smaller cache files are less likely to be cleaned up; larger cache files show a higher rate of change in their weight score, while smaller cache files show a lower rate of change in their weight score. Similarly, "2" is only an example and can be any value greater than 1.
[0036] As another implementation of the first aspect of this application, the step of obtaining the third cleanup weight score based on the number of times the cached file is accessed includes:
[0037]
[0038] in, The third cleanup weight score for the nth cache file. This represents the number of times the nth cached file has been accessed.
[0039] In this application, the more times a cached file is accessed, the greater the likelihood that a user will access that cached file again later, and therefore, the higher the weight score. Thus, the third cleanup weight score is more in line with user behavior.
[0040] As another implementation of the first aspect of this application, the step of obtaining the cleaning score based on the first cleaning weight score, the second cleaning weight score, and the third cleaning weight score includes:
[0041]
[0042] in, The score for cleaning up the nth cache file. The first cleanup weight score for the nth cache file. The second cleanup weight score for the nth cache file. The third cleanup weight score for the nth cached file.
[0043] As another implementation of the first aspect of this application, the remaining space of the cache space satisfies the first condition including:
[0044] The remaining cache capacity of the cache space is obtained based on the maximum cache capacity and the used cache capacity of the cache space.
[0045] The remaining cache ratio is obtained based on the remaining cache capacity of the cache space and the maximum cache capacity;
[0046] If the remaining cache ratio is greater than the first threshold, then the remaining space of the cache space satisfies the first condition.
[0047] In this application, the method of comparing the remaining cache ratio with a threshold is more accurate than the method of directly comparing the remaining capacity with a threshold, as it is related to the maximum cache capacity of the cache space.
[0048] As another implementation of the first aspect of this application, the process of deleting cache files in descending order of cleanup scores further includes:
[0049] If a second cache file and a third cache file with the same cleanup score exist, then compare the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file;
[0050] If the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are different, then delete the cache file with the higher first cleanup weight score in the second cache file and the third cache file.
[0051] If the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are the same, then compare the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file.
[0052] If the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are different, then delete the cache file with the higher second cleanup weight score in the second and third cache files;
[0053] If the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are the same, then compare the ASCII codes of the filenames of the second cache file and the filenames of the third cache file.
[0054] Delete the cache file with the smaller ASCII code in the filename of the second and third cache files.
[0055] In this application, when multiple cache files with the same cleanup score appear, the system determines which cache file to delete based on the first cleanup weight score, the second cleanup weight score, and the file name, so that user behavior and habits are taken into account more when deleting cache files.
[0056] In a second aspect, an electronic device is provided, including a processor for calling a computer program stored in a memory to implement the method of any one of the first aspects of this application.
[0057] Thirdly, a chip is provided, including a processor coupled to a memory, the processor executing a computer program stored in the memory to implement the method of any of the first aspects of this application.
[0058] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when the computer instructions are executed on an electronic device, causes the electronic device to implement the method of any one of the first aspects of this application.
[0059] Fifthly, embodiments of this application provide a computer program product that, when run on a device, causes the device to execute the method of any one of the first aspects of this application.
[0060] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0061] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0062] Figure 2 A schematic diagram of an interface for playing video in a normal playback mode, provided as an embodiment of this application;
[0063] Figure 3 A schematic diagram of an interface for playing video using a frame-by-frame playback method, provided as an embodiment of this application;
[0064] Figure 4 A schematic diagram illustrating the playback and decoding order of a group of video frames during normal playback, as provided in an embodiment of this application;
[0065] Figure 5 A schematic diagram illustrating the playback order and decoding order of video frames after they have been re-encoded into I-frames during frame playback, as provided in the embodiments of this application;
[0066] Figure 6 This application provides a schematic diagram of a process for triggering the cleanup of cache files in an embodiment.
[0067] Figure 7 This is a schematic diagram illustrating another process for triggering the cleanup of cache files, provided in an embodiment of this application.
[0068] Figure 8 This is a schematic diagram of the process for clearing cache files provided in an embodiment of this application;
[0069] Figure 9 A schematic diagram illustrating the process of calculating the cleanup score provided in an embodiment of this application;
[0070] Figure 10 A schematic diagram illustrating the relationship between the duration and quantity of videos cached in the 5GB cache space provided in this application embodiment;
[0071] Figure 11 This is a flowchart illustrating the scenario where cache files with the same cleanup score exist, as provided in an embodiment of this application. Detailed Implementation
[0072] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limiting purposes, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details.
[0073] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0074] It should also be understood that in the embodiments of this application, "one or more" refers to one, two, or more; "and / or" describes the relationship between the associated objects, indicating that three relationships can exist; for example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following associated objects have an "or" relationship.
[0075] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," "fourth," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0076] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0077] This application provides a method for clearing cache files, which can be applied to electronic devices such as tablets, mobile phones, wearable devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application does not limit the specific type of electronic device.
[0078] Figure 1 A schematic diagram of an electronic device is shown. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 1211, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, antenna 1, antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0079] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0080] Processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors. For example, processor 110 is used to execute the method for cleaning cache files in the embodiments of this application.
[0081] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0082] Internal memory 1211 can be used to store executable program code, including instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 1211. Internal memory 1211 may include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function (such as sound playback, image playback, etc.). The data storage area may store data created during the use of electronic device 100 (such as competition data, wake-up voiceprint, etc.).
[0083] Furthermore, the internal memory 1211 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc. Cache files and other data in the embodiments of this application can be stored in the internal memory.
[0084] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.
[0085] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0086] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.
[0087] This application does not specifically limit the structure of the execution entity of the method for clearing cache files. As long as communication can be performed according to the method for clearing cache files provided by this application by running code that records the method for clearing cache files according to the embodiments of this application. For example, the execution entity of the method for clearing cache files provided by this application can be a functional module in an electronic device that can call and execute programs, or a communication device applied in an electronic device, such as a chip.
[0088] Users can use the gallery app on their electronic devices to view various photos stored on the device and play various videos stored on the device.
[0089] Reference Figure 2 This is a schematic diagram of an interface for playing videos stored on an electronic device through a gallery application, as provided in an embodiment of this application.
[0090] Reference Figure 2 (a) in the image represents the electronic device's system desktop, which includes an icon for the gallery app. Users can click on... Figure 2 The icon for the Gallery app shown in (a) is used to open the Gallery app.
[0091] Reference Figure 2 (b) is a grid of images and videos stored on an electronic device, displayed by the device's gallery application after the user opens the gallery application. The grid can display images and videos, where the cell containing a video displays the video's cover and duration, and the cell containing an image displays a thumbnail of the image.
[0092] The grid image can be the interface displayed by the Gallery app after the user clicks the Gallery app icon on the system desktop to open the Gallery app, or it can be the interface displayed by the Gallery app after the user clicks the Gallery app icon on the system desktop to open the Gallery app and triggers more steps.
[0093] When displaying images and / or videos stored on an electronic device, this grid chart can be presented in various ways, for example, Figure 2 The method shown in (b) is to display pictures and videos in reverse chronological order. In practical applications, the gallery application can also set up multiple object groups: photo group, video group, screenshot and screen recording group, etc. Users can display photos taken through the photo group in the gallery application, videos through the video group in the gallery application, and screenshots and screen recordings through the screenshot and screen recording group in the gallery application.
[0094] This application does not limit the number of user operations required from the system desktop to the display of the grid chart in the gallery application, nor does it limit the way the grid chart displays images and videos.
[0095] Reference Figure 2 (c) represents the user's click. Figure 2 Following the cover of video A in the grid diagram shown in (b), the electronic device displays the video playback interface of video A in response to the operation. The video playback interface includes a video playback area 11 and a progress display area 12.
[0096] The video playback area 11 is used to display the video frame during video playback. After entering the video playback interface from the grid interface, the control 111 is displayed in the video playback area. When the user clicks the control 111, the electronic device responds to the click operation on the control 111 and starts playing the video frame in the video playback area 11 from the 0th second. When the video is paused, the control 111 is also displayed in the video playback area 11. When the user clicks the control 111, the electronic device responds to the click operation on the control 111 and starts playing the video frame in the video playback area 11 from the current paused moment.
[0097] The progress display area 12 is used to display the video playback progress. The progress display area 12 includes a progress display frame 121 and a progress indicator line 122. The position of the progress indicator line 122 can remain unchanged. The user can drag the progress display frame 121 located below the progress indicator line 122 so that the progress display frame 121 moves left and right without moving the progress indicator line 122. Different positions of the progress display frame 121 represent different times, and the position of the progress display frame corresponding to the progress indicator line 122 represents the time pointed to by the progress indicator line 122.
[0098] Due to space limitations in the progress display area 12, only a portion of the video frames or a portion of the video frames from the progress display frame 121 can be displayed in the progress display area 12. For example... Figure 2 As shown in (c), the progress display frame 121 displayed in the progress display area 12 includes: thumbnails of three complete video frames and a partial area of a thumbnail of a video frame.
[0099] Typically, the video playback area 11 displays the video frame at the moment indicated by the progress indicator line 122 in the progress display area 12.
[0100] In a specific implementation, there is a situation where the time pointed to by the progress indicator line 122 is the time between the playback times of two adjacent video frames, that is, there is no video frame in the video file at the time pointed to by the progress indicator line 122.
[0101] As an example, in a video frame sorted by playback time (denoted as timestamp) from smallest to largest, the playback time of the i-th video frame is ti, and the playback time of the (i+1)-th video frame is t(i+1); the time t pointed to by the progress indicator line 122 is greater than ti and less than t(i+1). In this case, the video frame corresponding to the timestamp with the shortest time interval to the time t pointed to by the progress indicator line 121 can be taken as the video frame at the time pointed to by the progress indicator line 122.
[0102] Of course, in practical applications, if there are no video frames in the video file with the same timestamp and the time pointed to by the progress indicator line, the video frame preceding the time t pointed to by the progress indicator line 122 (the video frame corresponding to ti) can be used as the video frame for the time pointed to by the progress indicator line 121; or the video frame following the time t pointed to by the progress indicator line 122 (the video frame corresponding to t(i+1)) can be used as the video frame for the time pointed to by the progress indicator line 122. In practical applications, there are many ways to display the playback progress in the progress display area 12. For example, the video playback progress can be displayed using a progress bar or a progress ring. This application embodiment only uses... Figure 2 The progress display area shown in (c) serves as an example to illustrate the difference between normal playback and frame playback.
[0103] Reference Figure 2 (d) represents the user's click. Figure 2 Following control 111 in the interface shown in (c), the electronic device responds to the operation by displaying an interface diagram during the playback of video A. This interface diagram indicates that the video A has reached the 5th second, and displays the video frame corresponding to the 5th second in the video playback area 11. Simultaneously, the progress display frame 121 in the progress display area 12 moves its position so that the time corresponding to the progress indicator line 122 is the 5th second. From... Figure 2 (c) in Figure 2 The playback process shown in (d) is the normal playback process of the video.
[0104] A video file consists of multiple video frames, each with a timestamp. The timestamp records the playback time of each video frame during the video file's playback process. For example, arranged by timestamp from smallest to largest, the video frames in the file are: Video Frame 0 (timestamp 0), Video Frame 1 (timestamp 1), Video Frame 2 (timestamp 2), Video Frame 3 (timestamp 3), Video Frame 4 (timestamp 4), Video Frame 5 (timestamp 5), Video Frame 6 (timestamp 6), Video Frame 7 (timestamp 7)... Normal playback involves displaying each video frame sequentially in the playback area according to its corresponding timestamp, from smallest to largest.
[0105] As an example of a normal playback process, video frame 0 is displayed in video playback area 11 at the 0th second after playback begins; video frame 1 is displayed in video playback area 11 at the 1st second after playback begins; video frame 2 is displayed in video playback area 11 at the 2nd second after playback begins; video frame 3 is displayed in video playback area 11 at the 3rd second after playback begins; video frame 4 is displayed in video playback area 11 at the 4th second after playback begins; video frame 5 is displayed in video playback area 11 at the 5th second after playback begins; video frame 6 is displayed in video playback area 11 at the 6th second after playback begins; video frame 7 is displayed in video playback area 11 at the 7th second after playback begins, and so on.
[0106] Combination Figure 2 (c) in Figure 2 (d) shows the normal playback process of video A: starting from the 0th second of video A, each video frame is displayed sequentially according to the playback time indicated by the timestamp; Figure 2 (d) in the diagram shows the interface displaying the video frame up to the 5th second. In practical applications, video A can be played in its entirety in normal playback mode. That is, if the playback duration of video A is 15 seconds, it can be played from the 0th second to the 15th second until the normal playback of video A ends.
[0107] Reference Figure 3 This is a schematic diagram of the interface for playing frames of video A provided in an embodiment of this application.
[0108] Reference Figure 3 (a) in the text is in Figure 2 The image shown is the interface after video A has finished playing in normal mode, based on the previously shown interface. This means video A has been played completely once in normal mode.
[0109] Reference Figure 3 In (b), the user drags to the right. Figure 3 The operation of the progress display frame of the interface shown in (a) is shown.
[0110] In response to Figure 3 As shown in (b) above, the electronic device will display the corresponding screen in the video playback area when the drag operation is performed.
[0111] As an example, refer to Figure 3In (c), when the user drags the progress bar to the 2nd second, the video playback area displays the video frame corresponding to the 2nd second. The video frame corresponding to the 2nd second can be the video frame in video A with the timestamp of the 2nd second; it can also be the video frame with the timestamp closest to the 2nd second; it can also be the video frame before the 2nd second whose timestamp is closest to the 2nd second in time interval; or it can be the video frame after the 2nd second whose timestamp is closest to the 2nd second in time interval.
[0112] Reference Figure 3 As shown in (d), when the user drags the progress display frame to the 2nd second, the user lifts their finger to release the progress display frame, and the electronic device continues to display the interface corresponding to the 2nd second of the video frame.
[0113] It should be noted that, in subsequent embodiments, the specific meaning of the description method of "video frame corresponding to a certain moment" can be referred to the detailed explanation of "video frame corresponding to the 2nd second," and will not be repeated hereafter. Figure 3 (b) in Figure 3 The playback process shown in (c) is the frame playback process of the video.
[0114] As the user drags the progress display frame 121, a relative position is formed between the progress indicator line 122 and the progress display frame 121, and the position of the progress indicator line 122 on the progress display frame 121 is related to the time that the progress indicator line 122 points to.
[0115] In the specific implementation, assuming that the time indicated by the progress indicator line 122 is t1 before the user moves in the area where the progress display frame 121 is located on the screen. When the user moves left or right in the area where the progress display frame is located, the electronic device can detect the user's real-time touch position at certain time intervals. The electronic device determines the user's movement direction and distance based on the continuous real-time touch positions. The electronic device determines the time change Δt based on the user's movement distance; it determines the calculation method for real-time time t2 based on the user's movement direction. For example, if the movement direction is left, the starting time t1 is subtracted from the time change Δt to obtain the real-time time t2; if the movement direction is right, the starting time t1 is added to the time change Δt to obtain the real-time time t2. After obtaining the real-time time t2, the electronic device finds the video frame corresponding to the real-time time t2 and displays the video frame corresponding to t2 in the video playback area.
[0116] On the other hand, the electronic device determines the movement direction of the progress display frame based on the movement direction determined by the real-time touch point position, and determines the movement distance of the progress display frame based on the movement distance of the real-time touch point position. The electronic device then moves the progress display frame in the progress display area according to the movement direction and distance, so that the time indicated by the progress indicator line is t2. As another example, the electronic device also determines the movement direction (left if t2 is greater than t1, right if t2 is less than t1) and movement distance of the progress display frame based on the start time t1 and the real-time time t2. The electronic device then moves the progress display frame in the progress display area according to the movement direction and distance, so that the time indicated by the progress indicator line is t2.
[0117] It should be noted that the above process is only an example. In actual applications, there are multiple ways for the user to determine the time indicated by the progress indicator line 122, the position of the progress display frame 121, and the video frame displayed in the video playback area 11 while dragging the progress display frame 121.
[0118] Based on the above frame playback process, it can be understood that the process of the user dragging the progress to display the frame is an uncertain process. It may move to the left, it may move to the right, it may be dragged quickly, or it may be dragged slowly. Accordingly, the video frame images displayed in the video playback area 11 have randomness.
[0119] As an example, before the user moves the area where the progress display frame is located on the screen, the starting time indicated by the progress indicator line is t1. During the user's dragging of the progress display frame, the electronic device detects the user's real-time touch position at certain time intervals, thus obtaining multiple consecutive time periods corresponding to the real-time times: t2, t3, t7, t4, and t3. In the video playback area, video frames are played in the following order: starting with the video frame corresponding to time t1, the video frames corresponding to time t2, t3, t7, t4, and t3 are played sequentially. It can be understood that the process of the electronic device playing video in the video playback area triggered by the user clicking control 111 is normal playback; the process of the electronic device displaying the video frame at the time indicated by the progress indicator line in the video playback area triggered by the user dragging the progress display frame is frame playback.
[0120] In the above embodiments, whether it is normal playback or frame playback, the video frames need to be decoded before they are displayed in the video playback area. In normal playback scenarios, video frames are usually decoded in groups. A group of video frames constitutes a video frame group, and each group of video frames includes a keyframe (I-frame), at least one forward reference frame (P-frame), and at least two bidirectional reference frames (B-frames).
[0121] Reference Figure 4This is a schematic diagram illustrating the playback and decoding order of a set of video frames provided in an embodiment of this application. A set of video frames can also be referred to as a group of pictures (GOP).
[0122] Each group of video frames, in playback order, includes: I-frame, B-frame, B-frame, P-frame, B-frame, B-frame, and P-frame. I-frames, as keyframes, can be decoded to obtain a complete image, but decoding is slower. P-frames record changes relative to the previous frame (not a B-frame); information from the previous frame is required to decode the P-frame. Similarly, information from previous P-frames (which may also be I-frames) and subsequent P-frames is needed to decode the B-frame. P-frames and B-frames improve smoothness while reducing the video file size.
[0123] Whether it's an I-frame, P-frame, or B-frame, they are all video frames. When decoding a video frame at a specific moment, you don't directly decode the video frame at that moment. Instead, you decode the group of video frames that the video frame at that moment belongs to. When decoding video frames within a group of video frames, you decode them one by one in the decoding order.
[0124] As an example, if we need to decode the video frame at time t1, and the video frame at time t1 is the 6th video frame in the playback order of a group of video frames: frame B; then the decoding order is:
[0125] First decoding: the video frame played in the first playback order: I-frame;
[0126] The second decoding: the 4th video frame in playback order: P-frame;
[0127] The third decoding step: the second video frame played in the playback order: frame B;
[0128] The fourth decoding: the third video frame in playback order: frame B;
[0129] The fifth decoding: the 7th video frame in playback order: P-frame;
[0130] The sixth decoding: the 5th video frame in playback order: frame B;
[0131] The seventh decoding: the 6th video frame in playback order: frame B;
[0132] Therefore, when decoding the video frame at time t1, it is necessary to perform the seventh decoding operation to decode the video frame at time t1.
[0133] Currently, in normal playback scenarios, the video frames in each video frame group are parsed, decoded, rendered, and displayed sequentially according to the playback order. Of course, when decoding the video frames in each video frame group, the process is as follows: Figure 4The decoding order shown decodes each video frame in the video frame group sequentially. Typically, when displaying video frames from the previous video frame group, all video frames in the next video frame group have already been decoded. Therefore, in normal playback scenarios, each video frame can be displayed according to its timestamp, resulting in smooth video playback.
[0134] During normal video playback, each video frame (I-frame, P-frame, and B-frame) in each group of video frames needs to be decoded. Therefore, during normal video playback, the P-frames and B-frames decoded during normal playback can be re-encoded into I-frames. This is equivalent to re-encoding the I-frames, P-frames, and B-frames decoded during normal playback into a video frame consisting entirely of I-frames. The video frame consisting entirely of I-frames can then be stored in a cache file. The I-frames stored during normal playback can be used in frame playback scenarios.
[0135] Of course, in practical applications, during the idle time of electronic devices, each video frame of video A can be decoded to obtain the YUV data of the decoded video frames (I-frames, P-frames, and B-frames); then the YUV data of the decoded I-frames, P-frames, and B-frames can be re-encoded into I-frames, and the re-encoded I-frames can be stored in the form of cache files. The stored I-frames can be used in frame playback scenarios.
[0136] Reference Figure 5 As shown, to... Figure 4 The diagram shows the playback and decoding order of a set of video frames encoded as I-frames. The playback order remains unchanged; however, for the decoding order, since each video frame is an I-frame, it's equivalent to decoding each video frame as the first one.
[0137] In a frame playback scenario, after determining the frame playback time (the time indicated by the progress indicator line), the I-frame corresponding to the frame playback time can be obtained directly from the cache file, and then the I-frame corresponding to the frame playback time can be decoded, rendered, and displayed.
[0138] In practical applications, as more and more video files are played in normal playback mode, the number of cached files (used to cache I-frames after video files are re-encoded) in the cache space increases; similarly, as more and more video files are re-encoded through decoding during idle periods, the number of cached files in the cache space also increases.
[0139] However, the storage space in electronic devices is limited. As the number of cached files increases, the storage space of electronic devices will decrease, which will affect the normal use of electronic devices.
[0140] Therefore, this application provides a method for cleaning up cache files, which can determine which cache files to clean up based on the user's usage of cache files and the characteristics of the cache files themselves.
[0141] The timing for clearing cache files provided in the embodiments of this application is described below.
[0142] Reference Figure 6 As shown, this application provides an embodiment of a timing method for clearing cache files.
[0143] S101, the electronic device labels the stored video files with tags, the tags being related to the content of the video files.
[0144] In this embodiment, video files in an electronic device can be tagged using machine learning methods. Of course, in practical applications, users can also manually select or input tags for the video file based on its content.
[0145] As an example of a video file tag, tags can be: scenery, animals, people, furniture, animation, etc.
[0146] S102, the electronic device obtains a score for the video file based on the video file's tags.
[0147] In this embodiment of the application, the purpose of scoring the video file with tags (or assigning a tag content score) is to determine the likelihood of the user playing the video in the future. Therefore, the video file can be scored based on specific tags. For example, by statistically analyzing the tags of the video files played by the user in the past, the probability of the video file corresponding to each tag being played in the future can be determined, and the tag content score of the video file can be generated based on the probability.
[0148] As another embodiment of this application, the video files stored in the electronic device can be classified according to their tags, and the number of video files belonging to each tag can be counted. The more tags there are, the higher the user's liking for that type of tag, and the greater the probability that the video file belonging to that type of tag will be played in the future.
[0149] S103, the electronic device scores the playback frequency of a video file based on the number of times the video file is played within a certain period of time.
[0150] In this embodiment of the application, the higher the historical playback frequency of a video file, the higher the user's liking for the video file, and the greater the probability of playing the video file in the future. Therefore, the playback frequency score (or playback frequency rating) of a video file can be obtained based on the number of times the video file has been played over a historical period. For example, different playback frequency scores can be set for different number of playbacks.
[0151] As another embodiment of this application, the number of times each video file is played in an electronic device over a historical period can also be counted. After normalization processing based on the number of times each video file is played, a playback frequency score for each video file is generated based on the normalized number of times each video file is played. The playback frequency score for each video file includes the playback frequency score of the video file.
[0152] S104, the electronic device scores the video file based on its playback frequency and tag content to obtain a pre-cached score (also known as a probability score of being played) for the video file.
[0153] In this embodiment, the weights of playback frequency scoring and tag content scoring can be set. Then, based on the playback frequency and its weight, as well as the tag content scoring and its weight, a pre-cached score for the video file is obtained. This pre-cached score comprehensively considers both playback frequency and tag content, thus better representing the probability of the video file being played in subsequent frames.
[0154] S105, the electronic device determines that the pre-cached score of the first video file is greater than the score threshold.
[0155] S106, During idle periods, the electronic device pre-caches the first video file.
[0156] The idle time period can be a pre-set fixed time, such as 2:00 AM to 5:00 AM every day. Of course, the idle time period can also be determined by the electronic device based on the user's behavior habits. For example, if user A does not often use electronic device A from 11:00 AM to 5:00 AM every day, then the idle time period for electronic device A is from 11:00 AM to 5:00 AM every day; if user B does not often use electronic device B from 3:00 AM to 8:00 AM every day, then the idle time period for electronic device B is from 3:00 AM to 8:00 AM every day.
[0157] Alternatively, the idle time period can also be an idle time period determined by the electronic device based on its memory resource consumption. This application does not limit the specific meaning or specific time period of the idle time period.
[0158] The pre-caching process involves the electronic device parsing the first video file to obtain its encoding format. This application uses H.264 as an example for the encoding format of the first video file. The electronic device uses an H.264 decoder to decode the first video file, obtaining the YUV data of keyframes and the YUV data of non-keyframes. The electronic device encodes the YUV data of keyframes into keyframes and the YUV data of non-keyframes into keyframes. The electronic device then caches the re-encoded keyframes of the first video file (including re-encoded keyframes of I-frames, P-frames, and B-frames).
[0159] This application embodiment can be set after S105 and before S106, and further includes:
[0160] S107, execute the process of clearing cache files.
[0161] Reference Figure 7 As shown, this application provides another opportunity to clear cache files in accordance with its embodiments. This includes clearing cache files during normal video playback:
[0162] S201, the gallery application receives a click operation on a regular playback control.
[0163] In this embodiment of the application, the electronic device displays... Figure 2 When the user clicks on the video playback interface of video A shown in (c), Figure 2 The normal playback control in the video playback area shown in (c) can trigger the electronic device to execute the normal playback process of video A.
[0164] S202, after receiving a click operation on the normal playback control, the gallery application sends a normal playback request for video A to the decision module. The request carries the normal playback start time as second 0.
[0165] S203, after receiving the normal playback request of video A, the decision module sends a playback instruction for video A to the normal playback module. The playback instruction carries the start time of the playback as the 0th second.
[0166] S204: After receiving the playback command for video A, the normal playback module parses video A and obtains video frames in H.264 format.
[0167] S205, the normal playback module sends a video frame decoding request to the normal decoder.
[0168] In practical applications, a regular playback module can cache H.264 format video frames, and the decoding request carries the cache address. The regular decoder retrieves the H.264 format video frames from the cache address for decoding. Alternatively, the regular playback module can also carry H.264 format video frames in the decoding request, and the regular decoder decodes the received H.264 format video frames. This application does not limit the specific implementation method.
[0169] S206, a standard decoder decodes video frames to obtain decoded video data: YUV data.
[0170] The decoded video data is divided into I-frames, P-frames, and B-frames.
[0171] S207, the ordinary decoder sends the decoded YUV data to the ordinary playback module.
[0172] After receiving YUV data, the normal playback module renders and displays the YUV data on one hand, and transmits the YUV data to the caching module for re-encoding and caching on the other hand.
[0173] First, the process of rendering and displaying YUV data is described.
[0174] S208: After receiving the decoded YUV data, the normal playback module renders the YUV data to obtain the video image.
[0175] S209, the normal playback module sends the rendered video frame to the gallery application, along with the timestamp of the video frame.
[0176] S210, after receiving the video frame, the gallery application displays the received video frame in the video playback area, and at the same time updates the position of the progress display frame in the progress display area so that the time corresponding to the progress indicator line is consistent with the timestamp of the received video frame.
[0177] The following describes the process of caching YUV data after re-encoding. After S207:
[0178] S211, the normal playback module sends YUV data to the decision module. At this time, the YUV data is an I-frame, P-frame, or B-frame.
[0179] S212, after receiving the YUV data, the decision module sends the YUV data to the frame buffer playback module.
[0180] S213, after receiving the YUV data, the frame buffer playback module sends the YUV data to the buffer module.
[0181] S214, after receiving YUV data, the cache module checks the cache space and finds that the video frame corresponding to the received YUV data does not exist.
[0182] In practical applications, YUV data itself carries a timestamp. In step S118, it has been determined that the currently displayed video playback interface is for video A. Therefore, the caching module can search the cache space to see if a video frame corresponding to the timestamp carried by the YUV data of video A exists. Of course, the decision module can also carry the identification information of video A when sending YUV data to the frame buffer playback module.
[0183] S215, if the buffer module does not have a video frame corresponding to the received YUV data in the buffer space, it sends YUV data to the encoding module.
[0184] S216, the encoding module encodes the received YUV data into an H.264 format I-frame.
[0185] In practice, the YUV data received by the encoding module is the decoded data of I-frames, P-frames, and B-frames. Therefore, the encoding module also needs to re-encode the YUV data of I-frames into H.264 format I-frame data; re-encode the YUV data of P-frames into H.264 format I-frame data; and re-encode the YUV data of B-frames into H.264 format I-frame data.
[0186] S217, the encoding module sends the encoded I-frame to the buffer module.
[0187] S218, after receiving the I-frame sent by the encoding module, the buffer module buffers the received I-frame.
[0188] This application embodiment can be set after S214 and before S218, and further includes:
[0189] S219, execute the process of clearing cache files.
[0190] like Figure 6 and Figure 7 As shown, the process of clearing cache files is executed when a new video file or a new I-frame needs to be cached; of course, after the process of clearing cache files is executed, the caching process needs to continue.
[0191] As another embodiment of this application, the process of clearing cache files can also be performed when the first I-frame of the cached video is cached, and the process of clearing cache files is not performed when other I-frames of the same video are cached.
[0192] In practical applications, the cache file clearing process can also be performed at a preset time (e.g., 7 PM on a certain day), or at a fixed time during the daily idle period of the electronic device, such as 2:00 AM, 3:00 AM, or 4:00 AM. Alternatively, the cache file clearing process can be performed at a fixed time cycle, such as once a week.
[0193] The following is through Figure 8 Describe the process of clearing cache files, i.e. Figure 6 S107 or Figure 7 S219 in the middle.
[0194] S301, the electronic device traverses each cache file in the cache space and obtains the attribute information of each cache file.
[0195] In this embodiment, the attribute information includes the time of the most recent access, the file size, and the number of times it has been accessed. In a specific implementation, each time a video frame is played through the cached file is counted as one access.
[0196] The file size is the size of the cache file itself. The time of the most recent access and the number of times it was accessed are confirmed by the following example.
[0197] As an example, after a user opens the video playback interface of video file A, the system retrieves video frames from the cache file corresponding to video file A, plays the retrieved video frames using frame playback, and then exits the video playback interface of video file A. This is recorded as the cache file A of video file A being accessed once.
[0198] Of course, in practical applications, the access status of video file A can also be correlated with the access status of cached files.
[0199] As another example, after a user opens the video playback interface of video file A, plays video file A using any playback method (e.g., normal playback and / or frame playback), and then exits the video playback interface of video file A, this is recorded as the cache file A corresponding to video file A being accessed once.
[0200] As another example, if a user opens the video playback interface of video file A and then exits the video playback interface of video file A, it is recorded as video file A's cache file A being accessed once.
[0201] S302, the electronic device calculates the remaining space ratio of the cache space.
[0202] This application embodiment allows setting the maximum cache capacity of the cache space. For example, the maximum cache capacity can be set to 5GB (as an example only). In this case, the cache space can cache a maximum of 5GB of data. The cache space can cache one cache file or multiple cache files. Regardless of the number of cache files, the total data volume of the cache files is less than or equal to the maximum cache capacity.
[0203] The remaining cache capacity is: the maximum cache capacity minus the total amount of data in the cached files.
[0204] The remaining space ratio (or remaining cache ratio) is the ratio of the remaining cache capacity to the maximum cache capacity.
[0205] S303, determine whether the proportion of remaining space is greater than the first threshold.
[0206] In this embodiment of the application, the first threshold can be set to 15%, or 5%, 10%, 20%, etc.
[0207] S304 If the remaining space ratio is greater than the first threshold, the process of cleaning up cached files ends.
[0208] If the remaining space ratio is greater than the threshold, it means that the remaining cache capacity in the cache space is still relatively large, which is enough to cache new cache files.
[0209] S305. If the remaining space ratio is not greater than the threshold, calculate the cleanup score for each cache file.
[0210] If the remaining space ratio is not greater than the threshold, it means that the remaining cache capacity in the cache space is relatively small and insufficient to cache new cache files. Therefore, it is necessary to determine which cache file to delete.
[0211] In practical applications, steps S802 to S805 can be executed first, followed by steps S801, S806, and subsequent steps.
[0212] S306, the electronic device sorts each cache file according to the cleanup score.
[0213] S307, the cache file with the highest score in the electronic device deletion and cleanup.
[0214] After deleting the cache file with the highest cleanup score, the electronic device continues to execute S803 and subsequent processes until the cache file cleanup process is completed.
[0215] By using this cyclical approach, the remaining space ratio of the cache can be controlled to be above 15%, ensuring that there is enough remaining cache capacity to cache new cache files.
[0216] The following describes how the cleanup score for each cache file is calculated in S305.
[0217] In this embodiment, different video files correspond to different cache files, and the cleanup score of each cache file stored in the cache space can be calculated. This embodiment sets the cache file whose access is most likely triggered by a user's operation to have a lower cleanup score and be less likely to be cleaned. Conversely, the cache file whose access is least likely triggered by a user's operation to have a higher cleanup score and be more likely to be cleaned.
[0218] The embodiments of this application can determine the cleanup score of a cache file from aspects such as the time of the most recent access to the cache file, the file size, and the number of times it has been accessed; in specific implementation, the weight scores corresponding to the three parameters can be obtained based on the above three parameters; and then the cleanup score of the cache file can be obtained based on the weight scores corresponding to the three parameters.
[0219] As an embodiment of this application, refer to Figure 9 The cleanup score for each cache file is obtained based on its attribute information, including:
[0220] S401, the first cleanup weight score is obtained based on the time difference between the time of the most recent access to the cache file and the current time;
[0221]
[0222] in, The first cleanup weight score for the nth cache file. Let 'a' be the time difference between the last access time of the nth cached file and the current time, where 'a' is a time constant. 'a' can be set according to various conditions, such as 3, 5, 7, or 10 days. The "2" in the above formula is just an example; it can be any value greater than 1, such as 3.
[0223] Generally, the further back in time a cache file was last accessed, the less likely it is to be used again, the higher its weight in the cleanup score, and the easier it is to clean up. Similarly, the larger the time difference, the greater the weight of the last access time of the cache file, and the easier it is to clean up.
[0224] Furthermore, the weight scores of cached files accessed in the last few days change at a lower rate, while the weight scores of cached files accessed before the last few days change at a higher rate.
[0225] S402, based on the file size of the cached file, obtain the second cleanup weight score;
[0226]
[0227] in, The second cleanup weight score for the nth cache file. Let b be the file size of the nth cached file, and b be the estimated file size constant, which is related to the maximum cache capacity of the cache space and the estimated number of cached files.
[0228] In this application, the estimated file size constant is obtained by setting the maximum cache capacity of the cache space and the expected number of cached files. This ensures that, based on the expected storage of a specific number of cached files, larger cached files are easier to clean up, while smaller cached files are less likely to be cleaned up; larger cached files show a higher rate of change in their weight score, while smaller cached files show a lower rate of change in their weight score. Similarly, "2" is only an example and can be any value greater than 1.
[0229] As an example, if the maximum cache size is 5GB and the expected number of cached files is 120, then b is the quotient of 5000 (or 5120) and 120.
[0230] In the specific implementation process, the original video corresponding to the 10-second 1080P 30-frame AVC video was converted into I-frame buffer files (bitstream files) with different bitrates for comparison. The comparison was carried out through three aspects: bitstream file size, YUV file size, and MAF tool score.
[0231] The original 6-second 4K 25 AVC video was converted into I-frame buffer files (stream files) at different bitrates, and the comparison was also made in terms of three aspects: bitstream file size, YUV file size, and MAF tool score. See Table 1 for details.
[0232] Table 1 Comparison of Videos at Different Bitrates
[0233]
[0234] Generally, the higher the VMAF tool score, the closer the converted image is to the original video image. It is generally believed that the human eye cannot distinguish the difference above 93 points.
[0235] Therefore, the optimal bitrate for 1080P video is 16M. At a bitrate of 16M, the compression ratio of 1080P video is 1:63 (14.3M:906M). The optimal bitrate for 4K video is 32M, and at a bitrate of 32M, the compression ratio of 4K video is 1:130 (1.71GB:13.4M).
[0236] Based on the above, the size of the cached files after video conversion for different durations can be obtained.
[0237] For example, a 10-second 1080p@30fps video converted to a 16Mbps buffer file would have a file size of 14.3MB; similarly, a 30-second 1080p@30fps video converted to a 16Mbps buffer file would also have a file size of 14.3MB. 3 = 42.9MB. Others will not be listed individually.
[0238] Assuming a cache space of 5GB (5120MB), and combining frame extraction rules and the optimal encoding compression ratio, we can obtain the model shown in the figure: (the calculation method is 5120MB / video size of different durations).
[0239] like Figure 10 The figure shows the number of files that can be cached for videos of different durations. In practical applications, analyzing the video lengths on users' phones, videos around 30 seconds long are the most common. Therefore, we selected 120 target files as the expected number of cached files.
[0240] S403, based on the number of times the cached file is accessed, a third cleanup weight score is obtained;
[0241]
[0242] in, The third cleanup weight score for the nth cache file. This represents the number of times the nth cached file has been accessed.
[0243] In this application, the more times a cached file is accessed, the greater the likelihood that a user will access that cached file again later, and therefore, the higher the weight score. Thus, the third cleanup weight score is more in line with user behavior.
[0244] Similarly, the "2" in the formula is only for example.
[0245] S404, the cleaning score is obtained based on the first cleaning weight score, the second cleaning weight score, and the third cleaning weight score. The time difference is positively correlated with the cleaning score, the file size is positively correlated with the cleaning score, and the number of accesses is negatively correlated with the cleaning score.
[0246]
[0247] in, The score for cleaning up the nth cache file. The first cleanup weight score for the nth cache file. The second cleanup weight score for the nth cache file. The third cleanup weight score for the nth cached file.
[0248] As another embodiment of this application, in practical applications, there may be cache files with the same score that need to be cleaned up. In this case, according to Figure 11 The process shown is executed.
[0249] S501, if there are a second cache file and a third cache file with the same cleanup score, then compare the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file;
[0250] S502, if the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are different, then delete the cache file with the higher first cleanup weight score in the second cache file and the third cache file;
[0251] S503, if the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are the same, then compare the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file;
[0252] S504, if the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are different, then delete the cache file with the higher second cleanup weight score in the second cache file and the third cache file;
[0253] S505, if the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are the same, then compare the ASCII codes of the filenames of the second cache file and the filenames of the third cache file.
[0254] S506, delete the cache file with the smaller ASCII code of the filename in the second and third cache files.
[0255] In practical applications, before comparing the ASCII codes of the filenames, you can first compare the third cleanup weight score corresponding to the access count of the second cache file and the third cache file. If the third cleanup weight scores corresponding to the access counts of the second and third cache files are the same, then execute S405; otherwise, delete the cache file with the lower third cleanup weight score from the second and third cache files.
[0256] As another embodiment of this application, the method for clearing cache files includes:
[0257] When the remaining space in the cache space does not meet the first condition, the attribute information of each cache file in the cache space is obtained. The attribute information of the cache file includes at least one of the following: the time when the cache file was last accessed, the file size of the cache file, and the number of times the cache file was accessed.
[0258] The cleanup score for each cache file is obtained based on its attribute information.
[0259] Delete cache files in descending order of cleanup score until the remaining space in the cache space meets the first condition.
[0260] Before determining that the remaining space in the cache does not meet the first condition, the method further includes:
[0261] After receiving an instruction to cache the first cached file in the cache space, the remaining space of the cache space is obtained;
[0262] Determine whether the remaining space of the cache space satisfies the first condition;
[0263] After the remaining space in the cache file satisfies the first condition, the method further includes:
[0264] The first cached file is cached in the cache space.
[0265] In this application, the probability of a cache file being accessed again is determined by comprehensively considering the time of its most recent access, its file size, and the number of times it has been accessed. The higher the probability of a cache file being accessed again, the lower its cleanup score; conversely, the lower the probability of a cache file being accessed again, the higher its cleanup score. Therefore, deleting cache files in descending order of cleanup score allows the retention of cache files with a higher probability of being accessed again, while deleting cache files with a lower probability of being accessed again. This achieves intelligent cleanup of cache files that users do not frequently use, thereby improving the user experience.
[0266] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0267] This application also provides a computer-readable storage medium storing a computer program that, when run on an electronic device, can implement the steps in the above-described method embodiments.
[0268] This application also provides a computer program product that, when run on an electronic device or a wireless router, enables the electronic device to perform the steps described in the various method embodiments above.
[0269] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to the first device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0270] This application also provides a chip, which includes a processor coupled to a memory. The processor calls a computer program stored in the memory to implement the steps of any method embodiment of this application. The chip can be a single chip or a chip module composed of multiple chips.
[0271] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0272] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0273] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for clearing cache files, characterized in that, include: During the playback of the first video in normal mode or during idle time periods, the key frames and non-key frames in the first video file corresponding to the first video are decoded to obtain the first decoded data. The first decoded data is re-encoded into keyframes to obtain the first cache file corresponding to the first video, and all video frames in the first cache file are keyframes. When the first video is played in frame-by-frame format, the key frame corresponding to the frame playback time in the first cache file is decoded, and the decoded screen of the key frame corresponding to the frame playback time is displayed. When the remaining space in the cache space does not meet the first condition, the attribute information of each cache file in the cache space is obtained. The attribute information of the cache file includes at least one of the following: the time when the cache file was last accessed, the file size of the cache file, and the number of times the cache file was accessed. The cache file includes the first cache file, and the video frames in the cache file are all keyframes. The cleanup score for each cache file is obtained based on its attribute information. Delete cache files in descending order of cleanup score until the remaining space in the cache space meets the first condition.
2. The method as described in claim 1, characterized in that, Before determining that the remaining space in the cache does not meet the first condition, the method further includes: After receiving an instruction to cache the first cached file in the cache space, the remaining space of the cache space is obtained; Determine whether the remaining space of the cache space satisfies the first condition; After the remaining space in the cache file satisfies the first condition, the method further includes: The first cached file is cached in the cache space.
3. The method as described in claim 1, characterized in that, Before determining that the remaining space in the cache does not meet the first condition, the method further includes: During idle periods, at preset times, or at preset time cycles, obtain the remaining space of the cache space; Determine whether the remaining space of the cache space satisfies the first condition.
4. The method according to any one of claims 1 to 3, characterized in that, The cleanup score for each cache file is obtained based on its attribute information, including: The first cleanup weight score is obtained based on the time difference between the most recent access time of the cached file and the current time. The second cleanup weight score is obtained based on the file size of the cached file; The third cleanup weight score is obtained based on the number of times the cached file is accessed; The cleaning score is obtained based on the first cleaning weight score, the second cleaning weight score, and the third cleaning weight score. The time difference and the cleaning score are positively correlated, the file size and the cleaning score are positively correlated, and the number of accesses and the cleaning score are inversely correlated.
5. The method as described in claim 4, characterized in that, The step of obtaining the first cleanup weight score based on the time difference between the most recent access time of the cached file and the current time includes: in, The first cleanup weight score for the nth cache file. Let 'a' be the time difference between the most recent access time of the nth cache file and the current time, where 'a' is a time constant.
6. The method as described in claim 4, characterized in that, The step of obtaining the second cleanup weight score based on the file size of the cached file includes: in, The second cleanup weight score for the nth cache file. Let b be the file size of the nth cached file, and b be the estimated file size constant, which is related to the maximum cache capacity of the cache space and the estimated number of cached files.
7. The method as described in claim 4, characterized in that, The step of obtaining the third cleanup weight score based on the number of times the cached file is accessed includes: in, The third cleanup weight score for the nth cache file. This represents the number of times the nth cached file has been accessed.
8. The method according to any one of claims 5 to 7, characterized in that, The step of obtaining the cleaning score based on the first cleaning weight score, the second cleaning weight score, and the third cleaning weight score includes: in, The score for cleaning up the nth cache file. The first cleanup weight score for the nth cache file. The second cleanup weight score for the nth cache file. The third cleanup weight score for the nth cached file.
9. The method as described in claim 1, characterized in that, The remaining space in the cache space satisfies the first condition including: The remaining cache capacity of the cache space is obtained based on the maximum cache capacity and the used cache capacity of the cache space. The remaining cache ratio is obtained based on the remaining cache capacity of the cache space and the maximum cache capacity; If the remaining cache ratio is greater than the first threshold, then the remaining space of the cache space satisfies the first condition.
10. The method as described in claim 1, characterized in that, The process of deleting cache files in descending order of cleanup scores also includes: If a second cache file and a third cache file with the same cleanup score exist, then compare the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file; If the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are different, then delete the cache file with the higher first cleanup weight score in the second and third cache files; If the first cleanup weight score of the second cache file and the first cleanup weight score of the third cache file are the same, then compare the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file. If the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are different, then delete the cache file with the higher second cleanup weight score in the second and third cache files; If the second cleanup weight score of the second cache file and the second cleanup weight score of the third cache file are the same, then compare the ASCII codes of the filenames of the second cache file and the filenames of the third cache file. Delete the cache file with the smaller ASCII code in the filename of the second and third cache files.
11. An electronic device, characterized in that, The electronic device includes a processor for invoking a computer program in memory to perform the method as described in any one of claims 1-10.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1-10.
13. A chip, characterized in that, The chip includes a processor for calling a computer program in memory to perform the method as described in any one of claims 1-10.
Citation Information
Patent Citations
Application cache automatic cleaning method and related equipment
CN115237826A
Method and apparatus for using a dynamic policy to manage a file purging process
US8272026B1