Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flutter_cache_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [3.6.0] - 2026-11-14

* Persists the cache on web in IndexedDB, so cached files survive page reloads and browser restarts ([#480](https://github.com/Baseflow/flutter_cache_manager/issues/480), [#339](https://github.com/Baseflow/flutter_cache_manager/issues/339), [#361](https://github.com/Baseflow/flutter_cache_manager/issues/361), [#122](https://github.com/Baseflow/flutter_cache_manager/issues/122)). This changes the web default from in-memory storage; pass `fileSystem: MemoryCacheSystem()` and `repo: NonStoringObjectProvider()` to `Config` to keep the previous behavior.
* Writes and reads web files in chunks, and when the browser's storage quota is reached evicts the least recently used files together with their data.
* Checks for a cached file with `await file.exists()` on every platform, and treats a file that a concurrent removal already deleted as removed.

## [3.5.0] - 2026-11-04

* **DEPRECATION** Deprecates `supportedFileNames`: whether an image is resized is now decided by the image engine from the file's content instead of from the file extension derived from the `Content-Type` header of the response ([#475](https://github.com/Baseflow/flutter_cache_manager/pull/475))
Expand Down
6 changes: 6 additions & 0 deletions flutter_cache_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ By default the cached files are stored in the temporary directory of the app. Th
Information about the files is stored in a database using sqflite on Android, iOS and macOs, or in a plain JSON file
on other platforms. The file name of the database is the key of the cacheManager, that's why that has to be unique.

On web the files and their information are stored in **IndexedDB**, so the cache persists across page reloads and
browser restarts. Each cache manager gets its own database named `flutter_cache_manager_<key>`. Files are written in
chunks as they download, and when the browser's storage quota is reached the least recently used files are evicted.
Browsers can still clear this storage, for example when the user clears site data. To keep the old in-memory
behaviour, pass `fileSystem: MemoryCacheSystem()` and `repo: NonStoringObjectProvider()` to `Config`.

### When are the cached files updated?
A valid url response should contain a Cache-Control header. More info on the header can be found
[here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control), but in summary it says for how long
Expand Down
11 changes: 7 additions & 4 deletions flutter_cache_manager/lib/src/cache_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,15 @@ class CacheStore {
_futureCache.remove(cacheObject.key);
final file = await fileSystem.createFile(cacheObject.relativePath);

if (file.existsSync()) {
if (await file.exists()) {
try {
await file.delete();
// ignore: unused_catch_clause
} on PathNotFoundException catch (e) {
// File has already been deleted. Do nothing #184
} on FileSystemException {
// A concurrent removal can delete the file between the exists() check
// and delete(), since both are awaited. Already gone is the outcome we
// wanted (#184); anything else is a real failure. Not every backend
// throws PathNotFoundException for this (MemoryFileSystem does not).
if (await file.exists()) rethrow;
}
}
removed.add(id);
Expand Down
15 changes: 9 additions & 6 deletions flutter_cache_manager/lib/src/config/_config_web.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_cache_manager/src/config/config.dart' as def;
import 'package:flutter_cache_manager/src/storage/cache_info_repositories/cache_info_repository.dart';
import 'package:flutter_cache_manager/src/storage/cache_info_repositories/non_storing_object_provider.dart';
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart';
import 'package:flutter_cache_manager/src/web/file_service.dart';
import 'package:flutter_cache_manager/src/storage/cache_info_repositories/indexed_db_cache_info_repository.dart';

class Config implements def.Config {
Config(
Expand All @@ -14,8 +12,13 @@ class Config implements def.Config {
FileService? fileService,
}) : stalePeriod = stalePeriod ?? const Duration(days: 30),
maxNrOfCacheObjects = maxNrOfCacheObjects ?? 200,
repo = repo ?? NonStoringObjectProvider(),
fileSystem = fileSystem ?? MemoryCacheSystem(),
repo =
repo ??
IndexedDbCacheInfoRepository(
databaseName: 'flutter_cache_manager_$cacheKey',
),
fileSystem =
fileSystem ?? IndexedDbFileSystem('flutter_cache_manager_$cacheKey'),
fileService = fileService ?? HttpFileService();

@override
Expand Down
8 changes: 5 additions & 3 deletions flutter_cache_manager/lib/src/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ abstract class Config {
/// time will be removed.
/// [repo] is the [CacheInfoRepository] which stores the cache metadata. On
/// Android, iOS and macOS this defaults to [CacheObjectProvider], a
/// sqflite implementation due to legacy. On web this defaults to
/// [NonStoringObjectProvider]. On the other platforms this defaults to
/// [JsonCacheInfoRepository].
/// sqflite implementation due to legacy. On web this defaults to an
/// IndexedDB repository, and [fileSystem] to IndexedDB storage, so the
/// cache persists across reloads; pass [NonStoringObjectProvider] and
/// [MemoryCacheSystem] for the previous in-memory behaviour. On the other
/// platforms this defaults to [JsonCacheInfoRepository].
/// The [fileSystem] defines where the cached files are stored and the
/// [fileService] defines where files are fetched, for example online.
factory Config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export 'cache_info_repository.dart';
export 'cache_object_provider.dart';
export 'json_cache_info_repository.dart';
export 'non_storing_object_provider.dart';

// Note: indexed_db_cache_info_repository.dart is web-only and not exported here
// to avoid dart:js_interop import errors on non-web platforms.
// Web code should import it directly when needed.
Loading
Loading