Cache migration on mobile app update

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Cache migration on mobile app update
Simple
from 1 business day to 3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Cache Migration on Mobile App Update

After app update, cache may become invalid. This isn't always obvious: old images loaded under old keys, JSON responses from API serialized in old format, HTTP cache contains headers with outdated URLs. If cache isn't invalidated on update — user sees old data mixed with new, or app crashes on deserialization.

Cache Invalidation by App Version

Simplest and most reliable approach: tie cache keys to app version or API version.

// Android — cache namespace by version
object CacheKeyBuilder {
    private val appVersion = BuildConfig.VERSION_CODE

    fun forImage(imageId: String) = "img_v${appVersion}_$imageId"
    fun forApiResponse(endpoint: String) = "api_v${appVersion}_$endpoint"
}

On update VERSION_CODE, all keys change — old cache stops being used. But old files remain on disk and need explicit cleanup.

Cleanup Outdated Cache on Startup

// iOS
class CacheManager {
    private let defaults = UserDefaults.standard
    private let lastVersionKey = "lastCachedVersion"

    func cleanupIfNeeded() {
        let current = Bundle.main.buildVersionNumber
        let last = defaults.string(forKey: lastVersionKey) ?? ""
        guard current != last else { return }

        clearDiskCache()
        clearURLCache()
        defaults.set(current, forKey: lastVersionKey)
    }

    private func clearDiskCache() {
        let cacheDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
        try? FileManager.default.removeItem(at: cacheDir.appendingPathComponent("ImageCache"))
    }

    private func clearURLCache() {
        URLCache.shared.removeAllCachedResponses()
    }
}

Called in application(_:didFinishLaunchingWithOptions:) before UI initialization.

Kingfisher (iOS) and Glide (Android)

Both libraries use own disk caches. Kingfisher stores cache in Library/Caches/com.onevcat.Kingfisher.ImageCache. Cleanup:

KingfisherManager.shared.cache.clearDiskCache()
KingfisherManager.shared.cache.clearMemoryCache()

Glide: Glide.get(context).clearDiskCache() — only from background thread.

Work Scope

  • Cache key versioning
  • Invalidate outdated cache on first launch of new version
  • Clear HTTP cache and image cache
  • Background cleanup without blocking startup

Timeline

Basic cache invalidation on update: 0.5 day. With versioned keys, selective cache preservation, and background cleanup: 1 day.