tencent cloud

Tencent Cloud Super App as a Service

Cache Management

Download
Focus Mode
Font Size
Last updated: 2025-07-04 16:48:08
During the use of mini programs, the following cache data is generated:
Mini program code cache: When a mini program is opened for the first time, its code is downloaded and cached for quicker access in the future. This data is shared across all accounts and is not isolated by account.
Mini program data cache: This refers to the files and data cached during the use of the mini program. This data is stored separately for each account.
To facilitate the superapp to manage mini program cache, the SDK provides TMACacheManager that supports the following capabilities.

Get the list of cached mini programs

Return a list of cached mini programs across all accounts. If the same mini program exists under multiple accounts, duplicates will be removed.
// Get the information about all cached mini programs

// @return Mini program array <TMFMiniAppInfo>
+ (NSArray<TMFMiniAppInfo *> *)loadAllAppletsFromCache;

Get the cache size of a specified mini program

// Get the storage information for a specified mini program
// @param appid - The appid of the mini program
// @param error - The error object
// @return The storage information for the mini program
+ (TMACacheInfo *)fetchStorageInfoForAppId:(NSString *)appId error:(NSError **)error;

Delete the data cache of a specified mini program

/// Clear user data
+ (void)clearUserDataWithAppId:(NSString *)appId completion:(void(^)(NSError * _Nullable error))completion;

Delete the code cache of a specified mini program

/// Clear mini program package files
+ (void)clearPackageWithAppId:(NSString *)appId completion:(void(^)(NSError * _Nullable error))completion;

Delete the data and code cache of a specified mini program

/// Clear all storage contents
+ (void)clearAllStorageWithAppId:(NSString *)appId completion:(void(^)(NSError * _Nullable error))completion;

Example:

NSArray<TMFMiniAppInfo *> *appInfos = [TMACacheManager loadAllAppletsFromCache];
NSMutableArray *dataSource = [NSMutableArray array];
for (TMFMiniAppInfo *appInfo in appInfos) {
NSError *error = nil;
TMACacheInfo *cacheInfo = [TMACacheManager fetchStorageInfoForAppId:appInfo.appId error:&error];
if (cacheInfo) {
NSLog(@"appId:%@,cacheInfo:%ld,userDataSize:%ld,totalSize:%ld",appInfo.appId,cacheInfo.packageSize,cacheInfo.userDataSize,cacheInfo.totalSize);
}
}



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback