Skip to content

Add CDN asset prefetching and cache expiry#2306

Open
sharjeelyunus wants to merge 1 commit into
mainfrom
cdn-asset-prefetching
Open

Add CDN asset prefetching and cache expiry#2306
sharjeelyunus wants to merge 1 commit into
mainfrom
cdn-asset-prefetching

Conversation

@sharjeelyunus

Copy link
Copy Markdown
Member

Description

Adds CDN asset caching improvements, next-screen asset prefetching, and automatic expiry for unused cached assets. Prefetching runs in the background, avoids current-screen assets, waits for foreground downloads, and does not mark prefetched assets as used until they are actually read by the app.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

What Has Changed

  • Added CdnAssetPrefetcher for bounded next-screen asset prefetching.
  • Updated CdnAssetCache to track downloadedAt and lastUsedAt.
  • Added 30-day background expiry cleanup for unused cached assets.
  • Ensured prefetched and manifest-refresh downloads do not update lastUsedAt.
  • Prioritized foreground asset downloads over background prefetch work.
  • Added tests for prefetching, usage tracking, migration, expiry, and cache refresh behavior.
  • Added doc/asset-cache-and-prefetcher.md with lifecycle diagrams and behavior notes.

How to Test

  1. From modules/ensemble, run:
    flutter test test/cdn_asset_cache_test.dart test/cdn_asset_prefetcher_test.dart
  2. Verify current-screen assets load normally through CdnAssetCache.
  3. Verify next-screen assets can be prefetched without setting lastUsedAt.

Screenshots / Videos

N/A

Checklist

  • I have run flutter analyze and addressed any new warnings
  • I have run flutter test and all tests pass
  • I have tested my changes on the relevant platform(s)
  • I have updated documentation if needed
  • My changes do not introduce new warnings or errors

- Added a new document detailing the asset cache and prefetcher functionality, enhancing the understanding of CDN asset management.
- Introduced `CdnAssetCache` and `CdnAssetPrefetcher` classes to manage asset caching and prefetching for improved performance during navigation.
- Updated the `README.md` to include references to the new asset cache and prefetcher documentation.
- Enhanced asset resolution logic to track usage and manage cache expiry effectively.
- Implemented tests to validate the new caching and prefetching features, ensuring robust asset management.
@sharjeelyunus sharjeelyunus self-assigned this Jun 26, 2026
@sharjeelyunus sharjeelyunus requested a review from M-Talha4 June 26, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant