Implement efficient DiskCache.clear()

Summary: public

Ability to efficiently remove all keys with a particular prefix

Reviewed By: tadeuzagallo

Differential Revision: D2658741

fb-gh-sync-id: 3770f061c83288efe645162ae84a9fd9194d2fd6
This commit is contained in:
Milen Dzhumerov
2015-11-25 03:17:50 -08:00
committed by facebook-github-bot-3
parent aaffb239ca
commit fc5a8678d3
2 changed files with 43 additions and 0 deletions

View File

@@ -435,6 +435,24 @@ RCT_EXPORT_METHOD(clear:(RCTResponseSenderBlock)callback)
callback(@[RCTNullIfNil(error)]);
}
RCT_EXPORT_METHOD(clearPrefix:(NSString *)prefix callack:(RCTResponseSenderBlock)callback)
{
NSDictionary *errorOut = [self _ensureSetup];
if (errorOut) {
callback(@[errorOut]);
return;
}
NSMutableArray<NSString *> *keys = [NSMutableArray array];
for (NSString *key in _manifest.allKeys) {
if ([key hasPrefix:prefix]) {
[keys addObject:key];
}
}
[self multiRemove:keys callback:callback];
}
RCT_EXPORT_METHOD(getAllKeys:(RCTResponseSenderBlock)callback)
{
NSDictionary *errorOut = [self _ensureSetup];