Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 5 additions & 5 deletions example/lib/flutter_map_cache/cache_store_types.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:io';

import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_db_store/dio_cache_interceptor_db_store.dart';
import 'package:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
import 'package:flutter/material.dart';
import 'package:http_cache_drift_store/http_cache_drift_store.dart';
import 'package:http_cache_file_store/http_cache_file_store.dart';
import 'package:http_cache_hive_store/http_cache_hive_store.dart';

enum CacheStoreTypes {
memCache('MemCache'),
Expand All @@ -18,7 +18,7 @@ enum CacheStoreTypes {

CacheStore getCacheStore(String path) => switch (this) {
CacheStoreTypes.memCache => MemCacheStore(),
CacheStoreTypes.dbCache => DbCacheStore(
CacheStoreTypes.dbCache => DriftCacheStore(
databasePath: path,
databaseName: 'DbCacheStore',
),
Expand All @@ -33,7 +33,7 @@ enum CacheStoreTypes {

CacheStore getCacheStoreWeb() => switch (this) {
CacheStoreTypes.memCache => MemCacheStore(),
CacheStoreTypes.dbCache => DbCacheStore(
CacheStoreTypes.dbCache => DriftCacheStore(
databasePath: '', // ignored on web
databaseName: 'DbCacheStore',
),
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ dependencies:
connectivity_plus: ^6.0.0
path_provider: ^2.0.15
dio: ^5.2.0+1
dio_cache_interceptor: ^3.4.2
dio_cache_interceptor_db_store: ^6.0.0
dio_cache_interceptor_file_store: ^1.2.2
dio_cache_interceptor_hive_store: ^4.0.0
dio_cache_interceptor: ^4.0.0
http_cache_drift_store: ^7.0.0
http_cache_file_store: ^2.0.0
http_cache_hive_store: ^5.0.0
sqlite3_flutter_libs: ^0.5.15
# vector_map_tiles: ^8.0.0
# vector_tile_renderer: ^6.0.0
Expand Down
15 changes: 15 additions & 0 deletions flutter_map_cache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [2.0.0] 2025-04-06

- Use
[dio_cache_interceptor: ^4.0.0](https://pub.dev/packages/dio_cache_interceptor/changelog#400)
- Remove deprecated `dioOptions` parameter
- Add
[hitCacheOnNetworkFailure](https://pub.dev/documentation/dio_cache_interceptor/latest/dio_cache_interceptor/CacheOptions/hitCacheOnNetworkFailure.html)
- Remove `hitCacheOnErrorExcept` in favor of the
new [hitCacheOnErrorCodes](https://pub.dev/documentation/dio_cache_interceptor/latest/dio_cache_interceptor/CacheOptions/hitCacheOnErrorCodes.html)

Please update your integration and used store packages according to
the [Getting Started section](https://pub.dev/packages/flutter_map_cache#getting-started).
More information can be found in
the [dio_cache_interceptor changelog](https://pub.dev/packages/dio_cache_interceptor/changelog#400).

## [1.5.2] 2025-02-05

- Support for flutter_map v6, v7 and v8
Expand Down
11 changes: 6 additions & 5 deletions flutter_map_cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ dependencies:
path_provider: ^2.1.2 # in case the storage backend requires a path

# drift
dio_cache_interceptor_db_store: ^5.1.0
http_cache_drift_store: ^7.0.0
sqlite3_flutter_libs: ^0.5.15

# file system
dio_cache_interceptor_file_store: ^1.2.2
http_cache_file_store: ^2.0.0

# hive
dio_cache_interceptor_hive_store: ^3.2.1
http_cache_hive_store: ^5.0.0

# objectbox
dio_cache_interceptor_objectbox_store: ^1.1.3
http_cache_objectbox_store: ^2.0.0
objectbox_flutter_libs: ^1.4.1

# isar
http_cache_isar_store: ^2.0.0
isar: ^3.1.0+1
isar_flutter_libs: ^3.1.0+1
```
Expand Down Expand Up @@ -181,7 +182,7 @@ class MyMap extends StatelessWidget {
import 'dart:io';

import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:http_cache_file_store/http_cache_file_store.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_cache/flutter_map_cache.dart';
Expand Down
38 changes: 13 additions & 25 deletions flutter_map_cache/lib/src/cached_tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@ class CachedTileProvider extends TileProvider {
required CacheStore store,
CachePolicy cachePolicy = CachePolicy.forceCache,
Dio? dio,
@Deprecated(
'''
This parameter will be removed in version 2.0.0 of flutter_map_cache.

Please use the `dio` parameter instead and provide your own Dio instance.

CachedTileProvider(
dio: Dio(
BaseOptions(...),
),
),
''',
)
BaseOptions? dioOptions,
List<Interceptor>? interceptors,
Duration? maxStale,
CacheKeyBuilder? keyBuilder,
List<int>? hitCacheOnErrorExcept = defaultHitCacheOnErrorExcept,
}) : dio = dio ?? Dio(dioOptions ?? BaseOptions()) {
List<int> hitCacheOnErrorCodes =
CachedTileProvider.defaultHitCacheOnErrorCodes,
bool hitCacheOnNetworkFailure = true,
}) : dio = dio ?? Dio() {
this.dio.interceptors.addAll([
...?interceptors,
DioCacheInterceptor(
Expand All @@ -47,7 +35,8 @@ class CachedTileProvider extends TileProvider {
policy: cachePolicy,
maxStale: maxStale,
keyBuilder: keyBuilder ?? CacheOptions.defaultCacheKeyBuilder,
hitCacheOnErrorExcept: hitCacheOnErrorExcept,
hitCacheOnErrorCodes: hitCacheOnErrorCodes,
hitCacheOnNetworkFailure: hitCacheOnNetworkFailure,
),
),
]);
Expand All @@ -56,14 +45,13 @@ class CachedTileProvider extends TileProvider {
/// dio http client
final Dio dio;

/// list of http status codes that will not hit the cache, e.g. if the user
/// needs authentication or the server is currently not able to handle the
/// request
static const List<int> defaultHitCacheOnErrorExcept = [
HttpStatus.unauthorized,
HttpStatus.forbidden,
HttpStatus.badGateway,
];
/// List of HTTP status codes that allow to return a previous cached
/// response.
///
/// If a request fails with a status code in this list,
/// the cached response (if available) will be used instead of treating
/// the error as a complete failure.
static const List<int> defaultHitCacheOnErrorCodes = [HttpStatus.notFound];

@override
bool get supportsCancelLoading => true;
Expand Down
4 changes: 2 additions & 2 deletions flutter_map_cache/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_map_cache
description: A slim yet powerful caching plugin for flutter_map tile layers.
version: 1.5.2
version: 2.0.0
repository: https://github.com/josxha/flutter_map_plugins
issue_tracker: https://github.com/josxha/flutter_map_plugins/issues
resolution: workspace
Expand All @@ -20,7 +20,7 @@ environment:

dependencies:
dio: ^5.2.0+1
dio_cache_interceptor: ^3.4.2
dio_cache_interceptor: ^4.0.0
flutter:
sdk: flutter
flutter_map: ">=6.0.0 <9.0.0"
Expand Down