-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSImageCacheFactory.m
90 lines (76 loc) · 2.26 KB
/
CSImageCacheFactory.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// ImageCacheFactory.m
// Calineczka
//
// Created by ciukes on 25/10/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CSImageCacheFactory.h"
#import "GTMObjectSingleton.h"
#import "CSGeneralImageCacheDomain.h"
#import "CSBundleImageCacheDomain.h"
@implementation CSImageCacheFactory
@synthesize _generalCache;
//@synthesize _avatarCache;
@synthesize _bundleCache;
GTMOBJECT_SINGLETON_BOILERPLATE(CSImageCacheFactory, sharedImageCache)
-(CSImageCache*)newCacheWithDomain:(id<CSImageCacheDomain>)domain {
return [[CSImageCache alloc] initWithDomain:domain];
}
-(CSImageCache*)getCacheWithDomainId:(ImageCacheDomainId)domainId {
switch(domainId){
case ImageCacheDomainIdGeneral:{
if(!_generalCache){
id<CSImageCacheDomain> generalDomain=[[CSGeneralImageCacheDomain alloc] init];
self._generalCache=[[CSImageCache alloc] initWithDomain:generalDomain];
[generalDomain release];
}
return _generalCache;
break;
}
/*case ImageCacheDomainIdAvatar:{
if(!_avatarCache){
id<ImageCacheDomain> avatarDomain=[[AvatarImageCacheDomain alloc] init];
self._avatarCache=[[ImageCache alloc] initWithDomain:avatarDomain];
[avatarDomain release];
}
return _avatarCache;
break;
}*/
case ImageCacheDomainIdBundle: {
if(!_bundleCache){
id<CSImageCacheDomain> tableDomain=[[CSBundleImageCacheDomain alloc] init];
self._bundleCache=[[CSImageCache alloc] initWithDomain:tableDomain];
[tableDomain release];
}
return _bundleCache;
break;
}
}
return nil;
}
-(void)dealloc {
[_generalCache release];
// [_avatarCache release];
[_bundleCache release];
[super dealloc];
}
+(UIImage*)bundleImageNamed:(NSString*)bundleImageFileName {
CSImageCache *bundleImagesCache=[[CSImageCacheFactory sharedImageCache] getCacheWithDomainId:ImageCacheDomainIdBundle];
UIImage *result=[bundleImagesCache imageForKey:bundleImageFileName];
return result;
}
-(void)removeAllImagesInMemory {
[_generalCache removeAllImagesInMemory];
// [_avatarCache removeAllImagesInMemory];
[_bundleCache removeAllImagesInMemory];
}
-(void)removeAllImages {
[_generalCache removeAllImages];
// [_avatarCache removeAllImages];
[_bundleCache removeAllImages];
}
-(void)didReceiveMemoryWarning {
[self removeAllImagesInMemory];
}
@end