zoukankan      html  css  js  c++  java
  • iOS中清除缓存的方法 以及SDWebimage自带的清除缓存方法

    1  SDWebimage中 

    (1)  计算缓存的大小 

    单位 : (MB)

      CGFloat size = [[SDImageCache sharedImageCache] getSize] / 1024 / 1024.;

    (2)  清除缓存

    给button设置一个点击事件, 弹出警告框

     UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"清理缓存" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

    (3) 使用UIAlertView的回调方法判断点击的下标惊醒下一步操作

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == 0) {
            [[SDImageCache sharedImageCache] clearDisk];
            [self.tableView reloadData];
    }

    / /    自己实现清除缓存

    - (void)cleanCase
    {
        [self startAnimation];
        //创建文件夹
        NSFileManager *fileManager = [NSFileManager defaultManager];
        //缓存
        NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
        //判断是否存在一个文件或者文件夹
        BOOL flag = NO;
        BOOL result = [fileManager fileExistsAtPath:cachesPath isDirectory:&flag];
        if (result) {
            NSLog(@"存在");
            if (flag) {
                NSLog(@"是一个文件夹");
                NSError *error = nil;
                BOOL removeResult =[fileManager removeItemAtPath:cachesPath error:&error];
                if (removeResult) {
                    NSLog(@"删除成功");
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"恭喜您" message:@"清除缓存成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    [alertView show];
                    [alertView release];
                }
            } else {
                NSLog(@"是一个文件");
            }
        } else {
            NSLog(@"不存在");
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"没有可清理的缓存了哦!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }

  • 相关阅读:
    TLS握手、中断恢复与证书中心的原因
    PROC 文件系统调节参数介绍(netstat -us)
    CPU状态信息us,sy,ni,id,wa,hi,si,st含义
    优化Linux内核参数
    linux内核(kernel)版本号的意义
    ethhdr、ether_header、iphdr、tcphdr、udphdr 结构介绍
    linux下将不同线程绑定到不同core和cpu上——pthread_setaffinity_np
    module_init的加载和释放
    (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
    netfilter的钩子——数据包在内核态得捕获、修改和转发
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4351427.html
Copyright © 2011-2022 走看看