Skip to content

Commit

Permalink
fix clearMemoryCache followed by clearAll bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lingol committed Jan 16, 2020
1 parent cf94132 commit 5dc6ec6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iOS/MMKV/MMKV/MMKV.mm
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ - (void)loadFromFile {
}
}

m_fd = open(m_path.UTF8String, O_RDWR, S_IRWXU);
m_fd = open(m_path.UTF8String, O_RDWR | O_CREAT, S_IRWXU);
if (m_fd < 0) {
MMKVError(@"fail to open:%@, %s", m_path, strerror(errno));
} else {
Expand Down
10 changes: 9 additions & 1 deletion iOS/MMKVDemo/MMKVMacDemo/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ @implementation ViewController {
- (void)viewDidLoad {
[super viewDidLoad];

[self funcionalTest];
// [self funcionalTest];
[self testNeedLoadFromFile];

m_loops = 10000;
m_arrStrings = [NSMutableArray arrayWithCapacity:m_loops];
Expand Down Expand Up @@ -88,4 +89,11 @@ - (void)setRepresentedObject:(id)representedObject {
// Update the view, if already loaded.
}

- (void)testNeedLoadFromFile {
auto mmkv = [MMKV mmkvWithID:@"testNeedLoadFromFile"];
[mmkv clearMemoryCache]; // or may be triggered by Memory Warning
[mmkv clearAll];
NSAssert([mmkv setString:@"value" forKey:@"key"], @"Fail to save");
}

@end

0 comments on commit 5dc6ec6

Please sign in to comment.