本发明的实施方式Embodiments of the invention
以下描述中，为了说明而不是为了限定，提出了诸如特定系统结构、技术之类的具体细节，以便透彻理解本申请实施例。然而，本领域的技术人员应当清楚，在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中，省略对众所周知的系统、装置、电路以及方法的详细说明，以免不必要的细节妨碍本申请的描述。In the following description, for the purpose of explanation rather than limitation, specific details such as a specific system structure and technology are provided in order to thoroughly understand the embodiments of the present application. However, it should be clear to a person skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary details.
为了说明本申请所述的技术方案，下面通过具体实施例来进行说明。In order to explain the technical solution described in this application, the following description is made through specific embodiments.
图1示出了本申请实施例一提供的图片缓存清理方法的实现流程图，详述如下：FIG. 1 shows an implementation flowchart of a method for cleaning a picture cache provided in Embodiment 1 of the present application, which is detailed as follows:
S101，当图片缓存总量大于预设的内存阈值时，基于当前未加载显示的缓存图片分别对应的收藏标记值、未加载时长以及总加载时长确定各缓存图片的优先级，收藏标记值用于标示缓存图片是否存在于收藏列表，未加载时长为缓存图片最近一次被终端设备加载显示时间距离当前时间的时长，总加载时长为缓存图片被终端设备历史加载显示的时长总和。S101. When the total picture cache is larger than a preset memory threshold, the priority of each cached picture is determined based on the favorite tag value, the unloaded duration, and the total loaded duration of the currently unloaded and displayed cached picture respectively. The favorite tag value is used for Indicates whether the cached picture exists in the favorites list. The unloaded time is the time when the cached picture was last loaded by the terminal device. The total display time is the sum of the length of the cached picture displayed by the terminal device ’s history.
当缓存图片的占用内存过大时，开始对缓存图片进行清理，以保证用户对图片的正常浏览等操作。由于不同的缓存图片对用户的重要程度差异可能较大，如有些可能对用户非常重要，有些则可能对用户而言并没有什么作用，因此，若直接按照现有技术对所有缓存图片进行无差别清理，会导致对用户重要图片的一并误清理，从而使得用户正常操作容易受到影响。因此，为了实现对缓存图片的精准清理，以避免缓存图片清理对用户正常操作的影响，本申请实施例中会对每张缓存图片对用户的重要程度进行识别和优先级排序，再基于优先级顺序来进行后续的处理操作。When the memory occupied by the cached picture is too large, the cached picture is cleared to ensure that the user can browse the picture normally. Because the importance of different cached pictures to users may vary greatly, some may be very important to users, and some may not have much effect on users. Therefore, if all cached pictures are directly made according to the existing technology, there is no difference. Cleaning up will cause the user's important pictures to be mistakenly cleaned up together, thus making the normal operation of the user vulnerable. Therefore, in order to achieve accurate cleaning of cached images to avoid the impact of the cleaning of cached images on the normal operations of users, in the embodiment of the present application, the importance of each cached image to the user is identified and prioritized, and then based on the priority Perform subsequent processing operations sequentially.
其中，考虑到实际情况中当缓存图片对人们较为重要时，人们往往会在浏览缓存图片时进行收藏标记，同时人们对较为的喜欢缓存图片的浏览显示的时长以及频率等，也均明显高于其他缓存图片。因此，为了实现对缓存图片对用户重要程度的评估，本申请实施例中会综合缓存图片对应的收藏标记值、未加载时长以及总加载时长三方面因素，来对每张缓存图片对用户的重要程度进行识别和优先级排序及清理。其中具体的根据收藏标记值、未加载时长和总加载时长来进行优先度排序的具体方法此处不予限定，可由技术人员根据需求自行设定，包括但不限于如本申请实施例二的方法。Among them, considering that when cached pictures are more important to people, people tend to mark collections as they browse cached pictures. At the same time, the length and frequency of browsing and display of cached pictures that are more like are also significantly higher than Other cached pictures. Therefore, in order to evaluate the importance of the cached picture to the user, in the embodiment of the present application, the three factors of the bookmark value corresponding to the cached picture, the unloaded time and the total loaded time are combined to determine the importance of each cached picture to the user. Degree of identification and prioritization and cleanup. The specific method of prioritizing according to the bookmark value, the unloaded time, and the total loaded time is not limited here, and can be set by a technician according to requirements, including but not limited to the method as in the second embodiment of the present application. .
其中，内存阈值的具体值可由技术人员根据终端设备的实际内存情况，或者终端设备为应用程序分配的实际可使用内存情况来进行设置，但内存阈值应当小于或等于内存警告对应的内存阈值，以保证对缓存图片的有效清理。The specific value of the memory threshold can be set by a technician based on the actual memory of the terminal device or the actual available memory allocated by the terminal device for the application. However, the memory threshold should be less than or equal to the memory threshold corresponding to the memory warning. Effective cleaning of cached images is guaranteed.
S102，利用替换图片替换优先级低于预设级别的缓存图片，并将该缓存图片对应的图片链接与替换图片关联存储，替换图片根据该缓存图片对应的图片名确定。S102. Use a replacement picture to replace a cache picture with a priority lower than a preset level, and store a link to the picture corresponding to the cache picture with the replacement picture. The replacement picture is determined according to the picture name corresponding to the cache picture.
在确定出每张缓存图片对应的优先级顺序之后，开始对缓存图片进行清理。在本申请实施例中，首先会对优先级较低的一些缓存图片进行优先清理，由于优先级较低意味着这些缓存图片对用户而言较为不重要，用户再次操作使用这些缓存图片的概率也相对较小，因此优先对这些缓存图片进行清理，可以最大限度地减小对用户正常操作影响的可能性，防止用户操作异常情况的出现。其中预设级别对应的具体优先级级别，可由技术人员根据实际情况进行设定。After determining the priority order corresponding to each cached picture, cleaning up the cached picture is started. In the embodiment of the present application, some cached pictures with a lower priority are first cleaned first. Because the lower priority means that these cached pictures are less important to the user, the probability that the user operates the cached pictures again is also Relatively small, so cleaning these cached images first can minimize the possibility of affecting the normal operation of the user and prevent the occurrence of abnormal operation by the user. The specific priority level corresponding to the preset level can be set by a technician according to the actual situation.
其中，考虑到瀑布式布局中每张图片都是紧密相连排布的，在对其中的缓存图片进行清理时若直接删除缓存图片，会使得布局中出现图片位置空位，从而会使得布局中的图片产生位移，而位移又会导致用户在浏览图片时图片位置不断更变，进而使得用户无法正常进行图片浏览等操作。因此，为了保证缓存图片清理时用户对图片的正常浏览等操作，本申请实施例中采用了图片替换的方式，利用替换图片来对缓存图片进行替换，从而使得清理后的缓存图片对应位置仍有替换图片存在，不会出现图片空位和位移的情况。Among them, considering that each picture in the waterfall layout is closely connected, if the cached picture is directly deleted when the cached picture is cleaned up, it will make the picture position vacant in the layout, which will make the picture in the layout Displacement occurs, and the displacement will cause the user to constantly change the picture position when browsing the picture, which will prevent the user from performing normal operations such as picture browsing. Therefore, in order to ensure that the user can browse the pictures normally when the cached pictures are cleaned up, the embodiment of the present application uses a picture replacement method to replace the cached pictures with the replacement pictures, so that the corresponding positions of the cleaned up cached pictures still remain. The replacement picture exists, and there will be no vacancy and displacement of the picture.
本申请实施例在对缓存图片进行替换后，缓存图片原位置处会出现一张对应的替换图片，考虑到实际情况中用户极有可能会上下拉动滚动条或滚动滑轮以浏览图片，从而可能会浏览到替换图片，此时若替换图片不包含任何原缓存图片的相关信息，用户会无法正常获取到原缓存图片的任何信息，从而使得用户无法对原缓存图片进行任何操作。为了保证用户对替换图片的正常浏览等操作，本申请实施例在生成替换图片时，会记录其对应的原缓存图片的相关信息，如将原缓存图片的图片名或图片名中的关键字词记录显示至替换图片中，从而使得用户在看到替换图片时即可知道其对应的原缓存图片的图片名，同时还会将原缓存图片对应的本地图片或网络图片的图片链接与替换图片管理存储，从而用户不仅能知道替换图片对应的原缓存图片的相关信息，还能进一步地获取到其对应的图片文件，以满足用户进一步的对图片文件的操作需求，以保证在对缓存图片进行清理时用户对缓存图片的正常操作。In the embodiment of the present application, after the cached picture is replaced, a corresponding replacement picture will appear at the original position of the cached picture. Considering that the user is likely to pull up or down the scroll bar or the scroll wheel to browse the picture in the actual situation. Browse to the replacement picture. At this time, if the replacement picture does not contain any information about the original cached picture, the user will not be able to obtain any information about the original cached picture normally, so that the user cannot perform any operation on the original cached picture. In order to ensure the user's normal browsing and other operations on the replacement picture, when the replacement picture is generated, the related information of the original cached picture will be recorded, such as the picture name of the original cached picture or the keyword in the picture name. The record is displayed in the replacement picture, so that when the user sees the replacement picture, the user can know the picture name of the corresponding original cache picture, and at the same time, the picture link of the local cache or network picture corresponding to the original cache picture and the replacement picture management Storage, so that the user can not only know the relevant information of the original cached picture corresponding to the replacement picture, but also further obtain its corresponding picture file to meet the user's further operation requirements for the picture file to ensure that the cached picture is cleaned up The user's normal operation of the cached picture.
应当说明地，本申请实施例中虽然未对替换图片的具体生成方法进行限定，但由上述说明可知，由于替换图片在本申请实施例中同时具有着节省内存、提供原缓存图片相关信息以及保障用户图片浏览时不出现图片位移等作用，即本申请实施例中生成的替换图片至少应具有以下几个特征：1、替换图片占用内存相对原缓存图片占用内存更小，2、替换图片中包含原缓存图片的相关信息，3、使用替换图片替换后的瀑布式布局图片浏览中不会出现图片空位和位移的情况，因此，在对替换图片生成方法进行选取或设定时，需保证生成的替换图片至少能同时满足上述三个特征要求。It should be noted that although the specific generation method of the replacement picture is not limited in the embodiment of the present application, it can be known from the above description that the replacement picture also has the advantages of saving memory, providing information about the original cached picture, and guarantee in the embodiment of the present application. The user's picture does not appear to have effects such as picture displacement, that is, the replacement picture generated in the embodiment of the present application should have at least the following characteristics: 1. The replacement picture occupies less memory than the original cache picture, 2. The replacement picture contains Information about the original cached image. 3. There will be no picture gaps and displacements in the waterfall layout picture replacement after replacing with the replacement image. Therefore, when selecting or setting the replacement image generation method, you must ensure that the generated The replacement picture can at least meet the above three feature requirements at the same time.
作为本申请的一个实施例，优选地，为了保证替换图片同时满足上述三个特征要求，在对原缓存图片生成对应的替换图片时，本申请实施例中首先会读取原缓存图片的分辨率、在瀑布式布局中的缩略图尺寸以及对应的图片名或图片名中的关键字词，再生成尺寸与原缓存图片在瀑布式布局中的缩略图尺寸相同，但分辨率小于原缓存图片的分辨率的空白的替换图片，最后将原缓存图片的图片名或图片名中的关键字词填充至空白的替换图片之中，得到最终的原缓存图片生成对应的替换图片。由于实际应用中缩略图尺寸均小等于原缓存图片的原始尺寸，同时替换图片的分辨率更小，因此生成的替换图片的文件体积必定小于对应的原缓存图片，即占用内存更小，同时由于在瀑布式布局中预览展示时都是以缩略图进行布局展示的，因此保证了替换图片替换原缓存图片后，瀑布式布局图片浏览中每张替换图片占用的位置和大小都是与原缓存图片完全相同，因此不会出现图片空位和位移的情况。其中，初始图片的具体分辨率可由技术人员自行设定，如可以设定为一个较低的固定值，或者设置为原缓存图片分辨率的n%，n小于100等。As an embodiment of the present application, preferably, in order to ensure that the replacement picture simultaneously meets the above three characteristic requirements, when generating a corresponding replacement picture for the original cache picture, the embodiment of the present application first reads the resolution of the original cache picture , The thumbnail size in the waterfall layout and the corresponding picture name or keyword in the picture name, the regenerated size is the same as the thumbnail size of the original cached picture in the waterfall layout, but the resolution is smaller than the original cached picture The blank replacement picture with the resolution, and finally the picture name of the original cache picture or the keyword words in the picture name are filled into the blank replacement picture to obtain the final original cache picture and generate a corresponding replacement picture. Because the size of the thumbnails in the actual application is equal to the original size of the original cached picture and the resolution of the replacement picture is smaller, the file size of the generated replacement picture must be smaller than the corresponding original cached picture, that is, it takes up less memory. The preview display in the waterfall layout is displayed in thumbnails, so it is guaranteed that after the replacement image replaces the original cached image, the position and size occupied by each replacement image in the waterfall layout image browsing are the same as the original cached image. Exactly the same, so there will be no gaps or displacements in the picture. The specific resolution of the initial picture can be set by the technicians, for example, it can be set to a lower fixed value, or set to n% of the original cached picture resolution, n is less than 100, and so on.
S103，若完成替换操作后图片缓存总量大于内存阈值，按照优先级从低到高的顺序依次对缓存图片进行清理，直至图片缓存总量小于或等于内存阈值。S103. If the total picture cache is larger than the memory threshold after the replacement operation is completed, the cache pictures are cleaned up in order from the lowest to the highest priority until the total picture cache is less than or equal to the memory threshold.
若图片替换完成后缓存图片的占用内存仍过大，说明还需对缓存图片进行进一步的清理。由于优先等级越高缓存图片对用户的重要程度越高，在本申请实施例中，为了尽可能地减小缓存图片清理对用户正常操作的影响，会尽可能地先清理对用户较为不重要的缓存图片，并在每次对单个优先级的缓存图片清理完成后，检测缓存图片的占用内存是否满足内存阈值的要求，若满足则停止对缓存图片的清理，不满足则再继续对更高一级优先级的缓存图片的清理。If the memory occupied by the cached picture is still too large after the picture replacement is completed, it means that the cached picture needs further cleaning. Because the higher the priority level, the more important the cached picture is to the user. In the embodiment of the present application, in order to minimize the impact of the clearing of the cached picture on the normal operation of the user, the less important to the user will be cleared first. Cache pictures, and after each time a single priority cache picture is cleaned, check whether the occupied memory of the cache picture meets the requirements of the memory threshold. If it is satisfied, stop cleaning the cache picture. If it is not satisfied, continue to the higher one. High-priority cache image cleaning.
作为本申请的一个实施例，在S102之后，还包括：若完成替换操作后图片缓存总量不大于内存阈值，停止对缓存图片的清理。As an embodiment of the present application, after S102, the method further includes: if the total picture cache is not greater than the memory threshold after completing the replacement operation, stopping the cleaning of the cache picture.
为了尽可能地避免缓存图片清理对用户正常图片操作造成影响，在本申请实施例中仅对没有加载显示的缓存图片进行了清理，而对用户当前正在加载显示的缓存图片不进行清理操作。其中，采用了多级清理策略对未加载显示的缓存图片进行清理，并在每次清理完成之后及时检测缓存图片占用内存是否过大，在占用内存没有达到内存阈值时及时停止对缓存图片的清理，从而实现了在对未加载显示的缓存图片及时有效的清理，且不会对用户当前浏览的缓存图片进行任何清理，保证了用户的正常操作。具体而言，首先根据用户对缓存图片的操作以及缓存图片的未加载时长和总加载时长来对当前未加载显示的缓存图片进行优先级排序处理，并对优先级最低的图片进行更小体积的图片替换，从而节约了对用户重要程度低的缓存图片的存储，同时又保证了瀑布式布局浏览图片时，不会出现图片空位不会使得图片产生位移，而通过图片信息+图片链接来对原缓存图片进行替换，使得用户若需对已清理的图片进行浏览等操作时，能够及时有效地获取到已清理图片的相关信息以及链接，从而保证了清理的同时用户能够正常进行图片相关操作。最后再根据优先级倒序对未加载的缓存图片进行层层清理，并在清理后及时判断是否达到清理目标，从而使得本申请实施例不会像现有技术一样对缓存图片进行无差别的过度清理，极大地提升了对缓存图片清理的精准度，避免了用户操作异常情况的发生。In order to avoid as much as possible the impact of clearing the cached picture on the user's normal picture operations, in the embodiment of the present application, only the cached picture that is not loaded and displayed is cleaned up, and the cached picture that the user is currently loading and displaying is not cleaned up. Among them, a multi-level cleaning strategy is adopted to clean the cached images that are not loaded and displayed. After each cleaning is completed, it is timely detected whether the cached image takes up too much memory. When the occupied memory does not reach the memory threshold, the cached image is stopped in time. In this way, the cached pictures that are not loaded and displayed are timely and effectively cleaned up, and the cached pictures currently browsed by the user are not cleaned up in any way, which guarantees the normal operation of the user. Specifically, first, according to the user ’s operation on the cached picture and the unloaded duration and total loading time of the cached picture, the currently unloaded displayed cached picture is prioritized, and the lowest-priority picture is subjected to a smaller size. Picture replacement, which saves the storage of cached pictures of low importance to users, and at the same time guarantees that when viewing pictures in waterfall layout, there will be no picture vacancies and no displacement of pictures. The cached picture is replaced, so that when the user needs to browse the cleaned picture and other operations, the related information and link of the cleaned picture can be obtained in a timely and effective manner, thereby ensuring that the user can normally perform picture related operations while cleaning. Finally, the unloaded cached images are cleaned layer by layer according to the priority order, and after cleaning, it is judged in time whether the cleaning target is reached, so that the embodiment of the present application does not perform indiscriminate over-cleaning of cached images as in the prior art. , Which greatly improves the accuracy of clearing cached images and avoids the occurrence of abnormal user operations.
作为对缓存图片优先级排序的一种具体实现，如图2所示，本申请实施例二包括：As a specific implementation for prioritizing cached pictures, as shown in FIG. 2, the second embodiment of the present application includes:
S201，将存在于收藏列表的缓存图片设置为第一优先级，并判断不存在于收藏列表的缓存图片对应的未加载时长是否大于预设的第一时长阈值，以及对应的总加载时长是否大于预设的第二时长阈值。S201: Set the cached pictures existing in the favorite list as the first priority, and determine whether the corresponding unloaded duration corresponding to the cached pictures that do not exist in the favorite list is greater than a preset first duration threshold, and whether the corresponding total loaded duration is greater than The preset second duration threshold.
实际情况中，当用户对某张缓存图片收藏了时，说明该缓存图片对用户而言非常重要，因此，为了防止一开始就将这些非常重要的已收藏缓存图片清理掉，造成对重要缓存图片的误清理，本申请实施例中将其设定为最后处理的优先级最高的缓存图片。In actual situations, when a user bookmarks a cached picture, it means that the cached picture is very important to the user. Therefore, in order to prevent the very important cached pictures from being cleaned up at the beginning, causing the cached picture to be important The error clearing is set in the embodiment of the present application as the cache image with the highest priority in the final processing.
同时，对于未被收藏的缓存图片，本申请实施例按照未加载时长以及总加载时长来进行进一步的分类，以确定出对应的优先级。At the same time, for cached pictures that have not been collected, the embodiment of the present application further classifies the unloaded cached pictures according to the unloaded time and the total loaded time to determine the corresponding priority.
S202，将不存在于收藏列表，且对应的未加载时长不大于第一时长阈值的缓存图片设置为第二优先级。S202. Set the cache picture that does not exist in the favorite list and the corresponding unloaded duration is not greater than the first duration threshold to the second priority.
实际情况中，由于瀑布式布局的特殊性，用户极有可能会上下拉动滚动条或滚动滑轮以浏览图片，此时对于未加载时长较小（即脱离显示界面时间较短，离用户当前浏览操作的缓存图片位置较近）的缓存图片而言，其极有可能会被再次显示浏览，若这些图片被设置为优先被清理的行列，会导致用户图片浏览等操作时极为不便。因此为了尽可能地保证用户对缓存图片的正常浏览等操作，本申请实施例会将未加载时长较小的缓存图片设置为较为后面处理的第二优先级图片。In practice, due to the special nature of the waterfall layout, users are very likely to pull up or down the scroll bar or scroll wheel to browse the pictures. At this time, the time for unloading is small (that is, the time off the display interface is shorter, and the user ’s current browsing operation is shorter. For cached pictures, the cached pictures are more likely to be displayed and browsed again. If these pictures are set as the priority to be cleaned up, it will cause inconvenience when users browse pictures and other operations. Therefore, in order to ensure the user's normal browsing of the cached picture as much as possible, the embodiment of the present application sets the cached picture with a small unloaded time as the second priority picture to be processed later.
S203，将不存在于收藏列表，且对应的未加载时长大于第一时长阈值，对应的总加载时长大于第二时长阈值的缓存图片设置为第三优先级。S203. Set the cache picture that does not exist in the favorite list and has a corresponding unloaded duration that is longer than the first duration threshold and a corresponding total loaded duration that is longer than the second duration threshold as the third priority.
S204，将不存在于收藏列表，且对应的未加载时长大于第一时长阈值，对应的总加载时长不大于第二时长阈值的缓存图片设置为第四优先级。S204. Set the cache picture that does not exist in the favorite list and has a corresponding unloaded duration that is longer than the first duration threshold and a corresponding total loaded duration that is not longer than the second duration threshold as the fourth priority.
其中，第一优先级、第二优先级、第三优先级以及第四优先级的优先级级别依次降低。Among them, the priority levels of the first priority, the second priority, the third priority, and the fourth priority are decreased in order.
当未加载时长较长时，意味着缓存图片离用户当前浏览操作的缓存图片距离较远，因此对这些图片的清理，相对对用户正常操作的影响较小。其中，为了细化每一张缓存图片的优先级，以提高逐级清理的效果，本申请实施例还会对未加载时长较长的缓存图片进行进一步地优先级划分。对于总加载时长较长的缓存图片而言，用户对其浏览操作的时间更长，因此重要程度要高于总加载时长短的缓存图片，因此本申请实施例中会将总加载时长较长的缓存图片设置为优先级较高的第三优先级，而将总加载时长短的缓存图片设置为优先级较低的第四优先级，以保证对缓存图片的有效清理，保证用户的正常操作。When the unloading time is long, it means that the cached picture is far away from the cached picture of the user's current browsing operation. Therefore, the cleaning of these pictures has a relatively small impact on the normal operation of the user. In order to refine the priority of each cached picture to improve the effect of level-by-level cleaning, the embodiment of the present application further prioritizes cached pictures with a long unloaded duration. For cached pictures with a long total load time, users have a longer time to browse them. Therefore, they are more important than cached pictures with a long total load time. Therefore, in the embodiment of the present application, the The cached picture is set to a third priority with a higher priority, and the cached picture with a total load duration is set to a fourth priority with a lower priority to ensure effective cleaning of the cached pictures and normal operations of the user.
其中，本申请实施例中的阈值具体大小，可由技术人员根据实际情况自行设定。The specific size of the threshold in the embodiment of the present application can be set by a technician according to the actual situation.
作为对不同优先级缓存图片进行清理的一种具体实现，如图3所示，本申请实施例三包括：As a specific implementation for cleaning pictures with different priorities, as shown in FIG. 3, the third embodiment of the present application includes:
S1031，基于各优先级对应的图片压缩率，按照优先级从低到高的顺序依次对缓存图片进行压缩，直至图片缓存总量小于或等于内存阈值，其中，图片压缩率大小与优先级负相关。S1031. Based on the image compression rate corresponding to each priority, the cached pictures are compressed in order from the lowest to the highest priority until the total picture cache is less than or equal to the memory threshold, where the size of the picture compression rate is negatively related to the priority. .
虽然替换图片中虽然包含了原缓存图片的一些相关信息以及图片链接，可以一定程度上保证用户对原缓存图片的相关操作，但实际情况中，由于替换图片并未原缓存图片，因此在对替换图片进行浏览等操作时，还是对用户造成一定的影响。因此，为了在保证有效清理的同时保证用户的正常操作，本申请实施例在对低优先级的缓存图片替换完成后，会进一步地对剩余的缓存图片进行压缩处理，由于压缩的缓存图片只是分辨率降低了，对用户进行浏览等操作的影响较小，从而尽可能地保证了用户对缓存图片的正常操作。Although the replacement picture contains some related information of the original cached picture and the image link, which can guarantee the user's related operations on the original cached picture to a certain extent, in reality, because the replacement picture is not the original cached picture, When browsing pictures and other operations, it still affects users to some extent. Therefore, in order to ensure the effective cleaning and ensure the normal operation of the user, the embodiment of this application will further compress the remaining cached pictures after the replacement of the low-priority cached pictures. The rate is reduced, and the user's browsing and other operations have less impact, thereby ensuring the user's normal operation of the cached picture as much as possible.
其中，由于图片压缩率的大小，直接决定了本申请实施例可释放内存的大小，图片压缩率越大释放的内存也就越大，清理的效果也就越好，但另一方面来说，图片压缩率越大，对缓存图片的质量影响也就越大，从而对用户对缓存图片操作的影响也就越大，因此，为了实现更好的清理效果的同时，尽可能地减小对用户缓存图片正常操作的影响，本申请实施例中对每个优先级设置了不同的图片压缩率，且优先级越高，其对应的图片压缩率越低，以保证对重要缓存图片的影响减到最小，保证对用户缓存图片操作的影响减到最小。其中图片压缩率的具体值，可有技术人员根据实际需求进行设定。Among them, the size of the picture compression rate directly determines the size of the releasable memory in the embodiment of the present application. The larger the picture compression rate is, the larger the released memory is and the better the cleaning effect is, but on the other hand, The larger the picture compression ratio, the greater the impact on the quality of the cached picture, and therefore the greater the impact on the user's operation of the cached picture. Therefore, in order to achieve a better cleaning effect, at the same time, minimize the impact on the user The impact of the normal operation of cached pictures. In the embodiment of the present application, a different picture compression rate is set for each priority, and the higher the priority, the lower the corresponding picture compression rate to ensure that the impact on important cached pictures is reduced. Minimize the impact on the user's cached image operations to a minimum. The specific value of the picture compression ratio can be set by a technician according to actual needs.
作为本申请的实施例四，如图4所示，考虑到压缩不一定就能使得缓存图片占用内存下降到内存阈值的要求，因此，本申请实施例在压缩的基础上还会对缓存图片进行进一步地处理，以保证最终对缓存图片的有效清理，保证用户对图片的正常浏览等操作以及浏览器的正常运行，包括：As the fourth embodiment of the present application, as shown in FIG. 4, in consideration of the requirement that compression does not necessarily reduce the memory occupied by cached images to a memory threshold, the embodiment of the present application further performs a process on the cached images on the basis of compression. Further processing to ensure the effective cleaning of the cached picture, to ensure the normal operation of the user and the normal operation of the browser, including:
S1032，若压缩后的图片缓存总量大于内存阈值，按照优先级从低到高的顺序，依次对压缩后的缓存图片进行清理。S1032, if the total amount of compressed picture cache is greater than the memory threshold, the compressed cache picture is cleaned up in order from the lowest to the highest priority.
其中，具体对每张压缩后的缓存图片的清理方法此处不予限定，具体可由技术人员自行设定。The method for cleaning each compressed cache picture is not limited here, and can be specifically set by a technician.
作为对压缩后的缓存图片进行清理的一种具体实现，包括：As a specific implementation of cleaning up the compressed cache image, it includes:
利用替换图片替换当前优先级的压缩后的缓存图片，并将该缓存图片对应的图片链接与替换图片关联存储。Use the replacement picture to replace the compressed cache picture with the current priority, and store the image link corresponding to the cache picture with the replacement picture.
由于此处操作与S102操作相同，此处不予赘述。Since the operation here is the same as that of S102, it will not be repeated here.
在本申请实施例中，考虑到瀑布式布局的特殊性：用户对与当前浏览操作的图片距离较近（即未加载时长较短）的图片的查看概率极大，同时考虑到图片替换对用户正常操作的影响较大，因此对本申请实施例一中未替换的缓存图片进行处理时，优先进行了压缩处理，并对不同优先级的缓存图片设置了不同的图片压缩率以提升压缩时的清理效果，并在压缩不足以满足内存阈值的需求时，再对压缩后的图片进行进一步的图片替换，从而实现了对缓存图片的多级清理，以实现在对缓存图片进行精准有效清理的同时，最大化地保证用户对缓存图片的正常操作。In the embodiment of the present application, the particularity of the waterfall layout is taken into account: the user has a great probability of viewing an image that is closer to the current browsing operation (that is, the unloaded time is shorter), and considers that the replacement of the image to the user The impact of normal operation is great, so when processing the unreplaced cached pictures in the first embodiment of the present application, compression processing is preferentially performed, and different picture compression rates are set for cached pictures of different priorities to improve cleanup during compression. Effect, and when the compression is insufficient to meet the memory threshold requirements, further compressed image replacement is performed to achieve multi-level cleaning of cached images to achieve accurate and effective cleaning of cached images. Maximize the user's normal operation of cached pictures.
对应于上文实施例的方法，图5示出了本申请实施例提供的图片缓存清理装置的结构框图，为了便于说明，仅示出了与本申请实施例相关的部分。图5示例的图片缓存清理装置可以是前述实施例一提供的图片缓存清理方法的执行主体。Corresponding to the method of the above embodiment, FIG. 5 shows a structural block diagram of a picture cache cleaning device provided by an embodiment of the present application. For convenience of explanation, only parts related to the embodiment of the present application are shown. The image cache cleaning device illustrated in FIG. 5 may be an execution subject of the image cache cleaning method provided in the foregoing first embodiment.
参照图5，该图片缓存清理装置包括：Referring to FIG. 5, the picture cache cleaning device includes:
优先级排序模块51，用于当图片缓存总量大于预设的内存阈值时，基于当前未加载显示的缓存图片分别对应的收藏标记值、未加载时长以及总加载时长确定各所述缓存图片的优先级，所述收藏标记值用于标示所述缓存图片是否存在于收藏列表，所述未加载时长为所述缓存图片最近一次被终端设备加载显示时间距离当前时间的时长，所述总加载时长为所述缓存图片被所述终端设备历史加载显示的时长总和。The priority sorting module 51 is configured to determine the cache image based on the favorite tag value, the unloaded duration, and the total loaded duration of the currently unloaded displayed cached pictures when the total amount of the picture cache is greater than a preset memory threshold. Priority, the favorite flag value is used to indicate whether the cached picture exists in the favorite list, the unloaded time is the time when the cached picture was last loaded by the terminal device, and the display time is away from the current time, and the total loading time The total length of time for which the cached picture is loaded and displayed by the terminal device history.
图片替换模块52，用于利用替换图片替换所述优先级低于预设级别的所述缓存图片，并将该缓存图片对应的图片链接与所述替换图片关联存储，所述替换图片根据该缓存图片对应的图片名确定。A picture replacement module 52, configured to replace the cache picture with a priority lower than a preset level by using a replacement picture, and store a picture link corresponding to the cache picture with the replacement picture, and the replacement picture is based on the cache The picture name corresponding to the picture is determined.
多级清理模块53，用于若完成替换操作后所述图片缓存总量大于所述内存阈值，按照优先级从低到高的顺序依次对所述缓存图片进行清理，直至所述图片缓存总量小于或等于所述内存阈值。A multi-level cleaning module 53 is configured to clean up the cached pictures in order from low to high priority if the total amount of the picture cache is greater than the memory threshold after completing the replacement operation, until the total amount of the picture cache Is less than or equal to the memory threshold.
进一步地，优先级排序模块51，包括：Further, the priority ranking module 51 includes:
将存在于所述收藏列表的所述缓存图片设置为第一优先级，并判断不存在于所述收藏列表的所述缓存图片对应的所述未加载时长是否大于预设的第一时长阈值，以及对应的所述总加载时长是否大于预设的第二时长阈值。Setting the cached picture existing in the favorite list as a first priority, and judging whether the unloaded duration corresponding to the cached picture not existing in the favorite list is greater than a preset first duration threshold, And whether the corresponding total loading duration is greater than a preset second duration threshold.
将不存在于所述收藏列表，且对应的所述未加载时长不大于所述第一时长阈值的所述缓存图片设置为第二优先级。Setting the cache picture that does not exist in the favorite list and the corresponding unloaded duration is not greater than the first duration threshold as a second priority.
将不存在于所述收藏列表，且对应的所述未加载时长大于所述第一时长阈值，对应的所述总加载时长大于所述第二时长阈值的所述缓存图片设置为第三优先级。Setting the cache picture that does not exist in the favorite list and whose corresponding unloaded duration is greater than the first duration threshold and the corresponding total loaded duration is greater than the second duration threshold to a third priority .
将不存在于所述收藏列表，且对应的所述未加载时长大于所述第一时长阈值，对应的所述总加载时长不大于所述第二时长阈值的所述缓存图片设置为第四优先级。Setting the cache picture that does not exist in the favorite list and whose corresponding unloaded duration is greater than the first duration threshold and the corresponding total loaded duration is not greater than the second duration threshold as a fourth priority level.
其中，所述第一优先级、所述第二优先级、所述第三优先级以及所述第四优先级的优先级级别依次降低。The priority levels of the first priority, the second priority, the third priority, and the fourth priority are sequentially decreased.
进一步地，多级清理模块53，包括：Further, the multi-stage cleaning module 53 includes:
压缩模块，用于基于各优先级对应的图片压缩率，按照优先级从低到高的顺序依次对所述缓存图片进行压缩，直至所述图片缓存总量小于或等于所述内存阈值，其中，所述图片压缩率大小与优先级负相关。A compression module, configured to compress the cached pictures in order from the lowest to the highest priority based on the picture compression rate corresponding to each priority until the total amount of picture cache is less than or equal to the memory threshold, The picture compression ratio is inversely related to the priority.
进一步地，多级清理模块53，包括：Further, the multi-stage cleaning module 53 includes:
二次清理模块，用于若压缩后的所述图片缓存总量大于所述内存阈值，按照优先级从低到高的顺序，依次对压缩后的所述缓存图片进行清理。A secondary cleaning module is configured to clean up the compressed cached pictures in order from the lowest to the highest priority if the total amount of the compressed picture cache is greater than the memory threshold.
进一步地，二次清理模块，包括：Further, the secondary cleaning module includes:
利用所述替换图片替换当前优先级的压缩后的所述缓存图片，并将该缓存图片对应的图片链接与所述替换图片关联存储。Using the replacement picture to replace the compressed cache picture at the current priority, and storing a picture link corresponding to the cache picture in association with the replacement picture.
本申请实施例提供的图片缓存清理装置中各模块实现各自功能的过程，具体可参考前述图1所示实施例一的描述，此处不再赘述。For a process in which each module in the picture cache cleaning device provided by the embodiment of the present application implements its functions, reference may be made to the description of Embodiment 1 shown in FIG. 1 above, and details are not described herein again.
应理解，上述实施例中各步骤的序号的大小并不意味着执行顺序的先后，各过程的执行顺序应以其功能和内在逻辑确定，而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence numbers of the steps in the above embodiments does not mean 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.
还应理解的是，虽然术语“第一”、“第二”等在文本中在一些本申请实施例中用来描述各种元素，但是这些元素不应该受到这些术语的限制。这些术语只是用来将一个元素与另一元素区分开。例如，第一接触可以被命名为第二接触，并且类似地，第二接触可以被命名为第一接触，而不背离各种所描述的实施例的范围。第一接触和第二接触都是接触，但是它们不是同一接触。It should also be understood that although the terms "first", "second", etc. are used in the text to describe various elements in some embodiments of the present application, these elements should not be limited by these terms. These terms are only used to distinguish one element from another. For example, a first contact may be named a second contact, and similarly, a second contact may be named a first contact without departing from the scope of the various described embodiments. Both the first contact and the second contact are contacts, but they are not the same contact.
图6是本申请一实施例提供的终端设备的示意图。如图6所示，该实施例的终端设备6包括：处理器60、存储器61，所述存储器61中存储有可在所述处理器60上运行的计算机可读指令62。所述处理器60执行所述计算机可读指令62时实现上述各个图片缓存清理方法实施例中的步骤，例如图1所示的步骤101至103。或者，所述处理器60执行所述计算机可读指令62时实现上述各装置实施例中各模块/单元的功能，例如图5所示模块51至53的功能。FIG. 6 is a schematic diagram of a terminal device according to an embodiment of the present application. As shown in FIG. 6, the terminal device 6 of this embodiment includes a processor 60 and a memory 61, and the memory 61 stores computer-readable instructions 62 that can be run on the processor 60. When the processor 60 executes the computer-readable instructions 62, steps in the embodiments of the foregoing picture cache cleaning method embodiments are implemented, for example, steps 101 to 103 shown in FIG. Alternatively, when the processor 60 executes the computer-readable instructions 62, the functions of each module / unit in the foregoing device embodiments are implemented, for example, the functions of modules 51 to 53 shown in FIG. 5.
所述终端设备6可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。所述终端设备可包括，但不仅限于，处理器60、存储器61。本领域技术人员可以理解，图6仅仅是终端设备6的示例，并不构成对终端设备6的限定，可以包括比图示更多或更少的部件，或者组合某些部件，或者不同的部件，例如所述终端设备还可以包括输入发送设备、网络接入设备、总线等。The terminal device 6 may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server. The terminal device may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art can understand that FIG. 6 is only an example of the terminal device 6, and does not constitute a limitation on the terminal device 6, and may include more or less components than shown in the figure, or combine some components or different components. For example, the terminal device may further include an input sending device, a network access device, a bus, and the like.
Processing Unit，CPU），还可以是其他通用处理器、数字信号处理器（Digital Signal Processor，DSP）、专用集成电路（Application
Specific Integrated Circuit，ASIC）、现成可编程门阵列（Field-Programmable Gate Array，FPGA）或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The processor 60 may be a central processing unit (Central
Processing Unit (CPU), or other general-purpose processors, Digital Signal Processors (DSPs), and application-specific integrated circuits (Applications)
Specific Integrated Circuit (ASIC), off-the-shelf Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
所述存储器61可以是所述终端设备6的内部存储单元，例如终端设备6的硬盘或内存。所述存储器61也可以是所述终端设备6的外部存储设备，例如所述终端设备6上配备的插接式硬盘，智能存储卡（Smart Media Card，SMC），安全数字（Secure Digital，SD）卡，闪存卡（Flash Card）等。进一步地，所述存储器61还可以既包括所述终端设备6的内部存储单元也包括外部存储设备。所述存储器61用于存储所述计算机可读指令以及所述终端设备所需的其他程序和数据。所述存储器61还可以用于暂时地存储已经发送或者将要发送的数据。The memory 61 may be an internal storage unit of the terminal device 6, such as a hard disk or a memory of the terminal device 6. The memory 61 may also be an external storage device of the terminal device 6, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (SD) provided on the terminal device 6. Card, flash card, etc. Further, the memory 61 may further include both an internal storage unit of the terminal device 6 and an external storage device. The memory 61 is configured to store the computer-readable instructions and other programs and data required by the terminal device. The memory 61 may also be used to temporarily store data that has been sent or will be sent.
另外，在本申请各个实施例中的各功能单元可以集成在一个处理单元中，也可以是各个单元单独物理存在，也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现，也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each of the units may exist separately physically, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional unit.
所述集成的模块/单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时，可以存储在一个计算机可读取存储介质中。基于这样的理解，本申请实现上述实施例方法中的全部或部分流程，也可以通过计算机可读指令来指令相关的硬件来完成，所述的计算机可读指令可存储于一计算机可读存储介质中，该计算机可读指令在被处理器执行时，可实现上述各个方法实施例的步骤。其中，所述计算机可读指令包括计算机可读指令代码，所述计算机可读指令代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括：能够携带所述计算机可读指令代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器（Read-Only Memory，ROM）、随机存取存储器（Random Access
Memory，RAM）、电载波信号、电信信号以及软件分发介质等。需要说明的是，所述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减，例如在某些司法管辖区，根据立法和专利实践，计算机可读介质不包括电载波信号和电信信号。When the integrated module / unit is implemented in the form of 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, the present application implements all or part of the processes in the methods of the above embodiments, and can also be completed by computer-readable instructions instructing related hardware. The computer-readable instructions can be stored in a computer-readable storage medium In the computer-readable instructions, when executed by a processor, the steps of the foregoing method embodiments can be implemented. The computer-readable instructions include computer-readable instruction codes, and the computer-readable instruction codes may be in a source code form, an object code form, an executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, a recording medium, a U disk, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory, ROM), Random Access Memory
Memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdictions. For example, in some jurisdictions, the computer-readable medium Excludes electric carrier signals and telecommunication signals.
以上所述实施例仅用以说明本申请的技术方案，而非对其限制；尽管参照前述实施例对本申请进行了详细的说明，本领域的普通技术人员应当理解：其依然可以对前述各实施例所记载的技术方案进行修改，或者对其中部分技术特征进行等同替换；而这些修改或者替换，并不使对应技术方案的本质脱离本申请各实施例技术方案的精神和范围，均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to describe the technical solution of the present application, but not limited thereto. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still implement the foregoing implementations. The technical solutions described in the examples are modified, or some of the technical features are equivalently replaced; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in Within the scope of this application.