-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGMModelManager.m
More file actions
47 lines (39 loc) · 916 Bytes
/
GMModelManager.m
File metadata and controls
47 lines (39 loc) · 916 Bytes
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
//
// GMModelManager.m
//
// Created by Gersham Meharg on 11-12-08.
// Copyright (c) 2011 Gersham Meharg. All rights reserved.
//
#import "GMModelManager.h"
#import "GMModel.h"
@implementation GMModelManager
static GMModelManager *shared = nil;
@synthesize cache = _cache;
@synthesize cacheSize = _cacheSize;
- (void)cacheModelObject:(GMModel *)object {
if (object.uuid == nil)
return;
if (_cache == nil) {
self.cache = [[NSCache alloc] init];
self.cache.countLimit = _cacheSize;
}
[_cache setObject:object forKey:object.uuid];
}
- (GMModel *)objectForUUID:(NSString *)uuid {
return [_cache objectForKey:uuid];
}
#pragma mark Singleton
+ (id)shared {
@synchronized(self) {
if(shared == nil)
shared = [[super allocWithZone:NULL] init];
}
return shared;
}
- (id)init {
if ((self = [super init])) {
self.cacheSize = 1000;
}
return self;
}
@end