//进行缓存的步骤:
//1.创建单例(返回自己或者id)
static DYPDataCache *cache = nil;
+(id)sharedInstance{
//保证线程安全
@synchronized(self){
if (cache == nil) {
//cache = [[DYPDataCache alloc]init];
//通过[self class]方法可以获取到当前类的类名
cache = [[[self class]alloc]init];
//初始化有效时间
cache.validTime = 20*60;
}
}
return cache;
}
+(id)allocWithZone:(struct _NSZone *)zone{
if (cache == nil) {
cache = [super allocWithZone:zone];
}
return cache;
}
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
内涵的老男人