1 /** 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 */ 7 8 #import <Foundation/Foundation.h> 9 10 #import <React/RCTBridgeModule.h> 11 #import <React/RCTInvalidating.h> 12 13 #import "RNCAsyncStorageDelegate.h" 14 15 /** 16 * A simple, asynchronous, persistent, key-value storage system designed as a 17 * backend to the AsyncStorage JS module, which is modeled after LocalStorage. 18 * 19 * Current implementation stores small values in serialized dictionary and 20 * larger values in separate files. Since we use a serial file queue 21 * `RKFileQueue`, reading/writing from multiple threads should be perceived as 22 * being atomic, unless someone bypasses the `RNCAsyncStorage` API. 23 * 24 * Keys and values must always be strings or an error is returned. 25 */ 26 @interface RNCAsyncStorage : NSObject <RCTBridgeModule, RCTInvalidating> 27 28 @property (nonatomic, weak, nullable) id<RNCAsyncStorageDelegate> delegate; 29 30 @property (nonatomic, assign) BOOL clearOnInvalidate; 31 32 @property (nonatomic, readonly, getter=isValid) BOOL valid; 33 34 // NOTE(nikki): Added to allow scoped per Expo app 35 - (instancetype)initWithStorageDirectory:(NSString *)storageDirectory; 36 37 // Clear the RNCAsyncStorage data from native code 38 - (void)clearAllData; 39 40 // Grab data from the cache. ResponseBlock result array will have an error at position 0, and an 41 // array of arrays at position 1. 42 - (void)multiGet:(NSArray<NSString *> *)keys callback:(RCTResponseSenderBlock)callback; 43 44 // Add multiple key value pairs to the cache. 45 - (void)multiSet:(NSArray<NSArray<NSString *> *> *)kvPairs 46 callback:(RCTResponseSenderBlock)callback; 47 48 // Interface for natively fetching all the keys from the storage data. 49 - (void)getAllKeys:(RCTResponseSenderBlock)callback; 50 51 @end 52