Skip to main content

Clear Cache Remote Config

The Clear Cache Remote Config feature allows engineers to remotely instruct the mobile application to delete specific types of cached data using Firebase Remote Config. This functionality helps manage app data effectively, ensuring that cached data is updated or removed as needed, without requiring a manual app update.

Features and Supported Instructions

Currently, the mobile application supports the following types of cache-clearing instructions:

  1. video
    Deletes all offline videos that have been downloaded to the device.

  2. sharedPreference
    Clears all data stored in the application's shared preferences.

  3. database
    Deletes the SQLite database used by the application.

warning

If the video instruction is executed, the database instruction must also be executed. This is because the SQLite database contains references to the downloaded videos. Executing only the video instruction will cause errors, as the app will attempt to reference video files that no longer exist.

How It Works

The workflow of the Clear Cache Remote Config feature is as follows:

Remote Config Configuration

  1. Open the Firebase Console and navigate to the Remote Config menu. Open Firebase console remote config dashboard
  2. Locate the key mobile_cache_version and edit its value. Edit key remote config
  3. Expand the JSON editor and add the required fields: Open JSON editor
  4. Add the action_type and version data. Sample added config data

    Sample JSON Configuration

    {
    "version": "40002",
    "action_type": ["video", "database"]
    }
    • action_type: Specifies the type of cache-clearing instruction (e.g., video, sharedPreference, or database). Supports multiple instructions in an array format.
    • version: Defines the app version that will execute the instruction. Ensures the instructions are executed only by the specified app version (40002 in this example).
  5. Validate the JSON for errors, then save the configuration. Correct Valid JSON Button save config
  6. Click Publish Changes to push the updated configuration to Firebase Remote Config. Publish changes edited config

Mobile App Workflow

Once the Remote Config is updated, the mobile app will execute the cache-clearing instructions based on the following steps: Clear Cache Flow Diagram

Step 1: Start Clear Cache Process

  • When the app launches for the first time after an update, it will trigger the Clear Cache Remote Config feature.
  • During this process, the user will remain on the SplashScreen page until the cache-clearing workflow is completed.

Step 2: Load Cache Reset Instructions

  • The app fetches the latest instructions from Remote Config and retrieves the last executed instructions from local storage.
  • It compares the locally stored execution history with the new instructions from Remote Config to identify pending instructions.

NOTE: If no new instructions are found, the workflow terminates immediately.

Step 3: Execute the First Cache Reset Instruction

  • The app executes the first pending cache-clearing instruction from the list.
  • Upon successful completion, the app proceeds to the next instruction.

Step 4: Execute Remaining Instructions

  • The app iterates through the remaining instructions and executes them one by one until all instructions are completed.

Step 5: Save Execution Status

  • After all instructions have been executed, the app records the status of the executed instructions in local storage.
  • This information is used by the app to identify which instructions have already been processed when the Clear Cache Remote Config feature is triggered in the future.

NOTE: This ensures that previously executed instructions are not repeated unless new instructions are added to the Remote Config.

Key Considerations

  • Consistency of Instructions: Ensure that the database instruction is included whenever the video instruction is executed to avoid errors.
  • Version Control: Use the version parameter to control which app versions execute the instructions. This ensures backward compatibility and prevents unsupported app versions from receiving invalid configurations.
  • Testing: Before publishing changes, test the configuration on development or staging environments to verify the workflow.

Example Use Cases

  1. Clearing Offline Videos After Feature Deprecation:
    If offline video support is removed, use the video and database instructions to delete all cached video files and references.

  2. Resetting User Preferences:
    To reset app settings for all users, use the sharedPreference instruction to clear shared preferences.

  3. Database Schema Update:
    When updating the SQLite schema, use the database instruction to delete the old database version and ensure a fresh start.

Troubleshooting

Issue: App Errors After Executing video Instruction

  • Cause: database instruction was not executed along with video.
  • Solution: Always pair the video and database instructions to maintain consistency.

Issue: Instructions Not Being Executed

  • Cause: Incorrect version parameter or unsaved changes in Firebase Console.
  • Solution: Verify the version parameter matches the app version and ensure changes are published in Firebase Console.

Writer: Arfandy, Media
25 November 2024