Appcelerator Titanium backup restore: configure automatic cache clearing after restore
0 reputation · 28 May 2026, 06:30 UTC
0 reputation · 28 May 2026, 06:30 UTC
Goal: ensure that after restoring a backup, any cached data does not cause stale application state.
Constraint/uncertainty: The Ti.Filesystem backup/restore APIs do not specify whether the application cache should be cleared automatically; current behavior leaves cache intact, and the documentation does not define a hook or permission for automatic cache clearing.
Should the restore API automatically clear the cache? If not, what is the recommended pattern for developers to clear cache after a restore? Are there platform‑specific limitations that affect cache clearing after a restore?
No. The Titanium restore API does not automatically clear cache, and there is no built-in restore-complete hook or permission to do so automatically.
Confirmed fact: Titanium core does not define a built-in restore-complete hook or automatic cache invalidation for backup restore. Ti.Filesystem exposes Ti.Filesystem.applicationCacheDirectory and Ti.Filesystem.applicationDataDirectory, but no API automatically clears cache after a restore operation.
Likely explanation: Cache remains intact after a restore because iOS and Android backup mechanisms restore app data while treating cache as a separate location. Titanium does not intercept the OS restore process, so stale cached files can persist and cause stale application state.
Detect a restore on first launch and clear cache programmatically. This is version-sensitive and must be tested on target SDK and OS versions.
Ti.App.Properties.Ti.Filesystem.applicationCacheDirectory.Ti.Filesystem.applicationDataDirectory that you control.iOS does not deliver a reliable restore completion callback to the app. Detection must be done on first launch after install or update. iOS backup inclusion rules generally exclude Caches from iCloud backup, but a local restore can still bring back data files while leaving cache files from the device.
Android Auto Backup can restore data without the app running. The OS may evict cache under storage pressure, so manual clearing must be guarded and performed on launch. Do not assume cache is included in the backup.
One diagnostic detail that changes the recommendation: Are you storing cache only in Ti.Filesystem.applicationCacheDirectory or also in custom folders under applicationDataDirectory? The paths to clear depend on this.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 28 May 2026, 13:07 UTC
On Android, Ti.Filesystem.applicationCacheDirectory maps to /data/data//cache, which the OS treats as non-essential and may clear independently. However, a full backup/restore via adb backup or Google One does restore this directory by default unless the app sets android:allowBackup="false" or uses android:fullBackupContent to exclude it. Titanium's own backup API does not interact with this system-level mechanism.
If the app uses a Ti.UI.WebView, its internal cache (Cookies, localStorage, IndexedDB) lives outside the Titanium filesystem sandbox. Clearing applicationCacheDirectory alone will not reset WebView state. Call webView.evalJS("localStorage.clear(); sessionStorage.clear();") and, on Android 9+, CookieManager.getInstance().removeAllCookies(null) after the restore marker check.
Use adb shell run-as ls -la cache/ before and after a restore cycle to confirm which files persist.