From fcaaaf3b9a3f999f909abe98d69f62102c7e3aae Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 14:25:14 +0100 Subject: [PATCH 01/11] Update versions --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 762da87..071dae7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ environment: dependencies: fetch_tray: git: - url: https://github.com/marqably/fetch_tray + url: https://github.com/Lightgaming/fetch_tray.git ref: next dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 @@ -18,5 +18,5 @@ dependencies: logger: ^1.4.0 dev_dependencies: - lints: ^2.0.0 + lints: ^3.0.0 test: ^1.21.0 From 14b43fad170d8f20799fe4e641f08474e54e9bfe Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 14:26:50 +0100 Subject: [PATCH 02/11] Update versions --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 071dae7..49e2745 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fetch_tray_cache_plugin description: A caching plugin for fetch_tray. -version: 0.0.2 +version: 0.0.3 # repository: https://github.com/my_org/my_repo environment: @@ -15,7 +15,7 @@ dependencies: dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 - logger: ^1.4.0 + logger: ^2.0.2+1 dev_dependencies: lints: ^3.0.0 From 9141c62e7c75cab705a55e4ab562b16ac2523e86 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 14:55:10 +0100 Subject: [PATCH 03/11] Update versions --- pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 49e2745..4eab19f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,7 @@ name: fetch_tray_cache_plugin description: A caching plugin for fetch_tray. version: 0.0.3 +publish_to: none # repository: https://github.com/my_org/my_repo environment: @@ -11,7 +12,7 @@ dependencies: fetch_tray: git: url: https://github.com/Lightgaming/fetch_tray.git - ref: next + ref: 65714e488654c9563051354e0b6c88812bde2b42 dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 From 8bedca370d254ae6c7fe08f39c5386d6b931567e Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 15:08:55 +0100 Subject: [PATCH 04/11] Update versions --- example/fetch_tray_cache_example.dart | 2 +- pubspec.yaml | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/example/fetch_tray_cache_example.dart b/example/fetch_tray_cache_example.dart index 9a39561..6f573b2 100644 --- a/example/fetch_tray_cache_example.dart +++ b/example/fetch_tray_cache_example.dart @@ -2,7 +2,7 @@ import 'dart:io'; -import 'package:fetch_tray/fetch_tray.dart'; +import 'package:fetch_tray/utils/make_tray_request.dart'; import 'package:fetch_tray_cache_plugin/fetch_tray_cache.dart'; import 'models/post.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 4eab19f..0c3810b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,17 @@ name: fetch_tray_cache_plugin description: A caching plugin for fetch_tray. version: 0.0.3 -publish_to: none # repository: https://github.com/my_org/my_repo environment: - sdk: ^3.0.2 + sdk: ">=3.0.0 <4.0.0" # Add regular dependencies here. dependencies: fetch_tray: git: url: https://github.com/Lightgaming/fetch_tray.git - ref: 65714e488654c9563051354e0b6c88812bde2b42 + ref: 9a34f0ddc5b61ec6fa77d0d6855c1300aa4c34b3 dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 From ded59ee9da5b335129e344a3ca2c72ee135a28a7 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 15:47:03 +0100 Subject: [PATCH 05/11] Update versions --- example/fetch_tray_cache_example.dart | 2 +- lib/src/interceptors/cache_interceptor.dart | 24 +++++++++++++++------ pubspec.yaml | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/example/fetch_tray_cache_example.dart b/example/fetch_tray_cache_example.dart index 6f573b2..9a39561 100644 --- a/example/fetch_tray_cache_example.dart +++ b/example/fetch_tray_cache_example.dart @@ -2,7 +2,7 @@ import 'dart:io'; -import 'package:fetch_tray/utils/make_tray_request.dart'; +import 'package:fetch_tray/fetch_tray.dart'; import 'package:fetch_tray_cache_plugin/fetch_tray_cache.dart'; import 'models/post.dart'; diff --git a/lib/src/interceptors/cache_interceptor.dart b/lib/src/interceptors/cache_interceptor.dart index ac25d98..ccf1e01 100644 --- a/lib/src/interceptors/cache_interceptor.dart +++ b/lib/src/interceptors/cache_interceptor.dart @@ -33,10 +33,8 @@ class TrayCacheInterceptor extends Interceptor { }); @override - void onRequest( - RequestOptions options, - RequestInterceptorHandler handler, - ) async { + void onRequest(RequestOptions options, RequestInterceptorHandler handler, + [bool loggingEnabled = false]) async { // TODO: implement filter for logger /* final requestShouldLog = options.extra[TrayCachePluginKeys.requestShouldLog] as bool? ?? false; */ @@ -61,7 +59,11 @@ class TrayCacheInterceptor extends Interceptor { final cacheDuration = requestCacheDuration ?? maxAge; if (difference <= cacheDuration) { - logger.i('Cache hit, returning cached response', logPrefix); + if (loggingEnabled) { + logger.i( + '$logPrefix Cache hit, returning cached response', + ); + } return handler.resolve( cache.toResponse( options, @@ -69,13 +71,21 @@ class TrayCacheInterceptor extends Interceptor { ), ); } else { - logger.i('Cache too old, deleting...', logPrefix); + if (loggingEnabled) { + logger.i( + '$logPrefix Cache too old, deleting...', + ); + } await store.delete(key); } } } - logger.i('Sending request over network', logPrefix); + if (loggingEnabled) { + logger.i( + '$logPrefix Sending request over network', + ); + } handler.next(options); } diff --git a/pubspec.yaml b/pubspec.yaml index 0c3810b..3f2226c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: fetch_tray: git: url: https://github.com/Lightgaming/fetch_tray.git - ref: 9a34f0ddc5b61ec6fa77d0d6855c1300aa4c34b3 + ref: 6effd288177b80102e79d269f2ab1f619afc17b2 dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 From c18e98533fa70121feb5c382f6b6829f897bc0ac Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Thu, 1 Feb 2024 16:11:17 +0100 Subject: [PATCH 06/11] Update versions --- example/fetch_tray_cache_example.dart | 1 + lib/src/fetch_tray_cache_base.dart | 4 +++- lib/src/interceptors/cache_interceptor.dart | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/example/fetch_tray_cache_example.dart b/example/fetch_tray_cache_example.dart index 9a39561..39404bf 100644 --- a/example/fetch_tray_cache_example.dart +++ b/example/fetch_tray_cache_example.dart @@ -15,6 +15,7 @@ void main() async { TrayCachePlugin( cacheStoreType: TrayCacheStoreType.memory, cacheDuration: const Duration(seconds: 2), + loggingEnabled: true, ), ], ); diff --git a/lib/src/fetch_tray_cache_base.dart b/lib/src/fetch_tray_cache_base.dart index 0a7f1e5..df5e1c2 100644 --- a/lib/src/fetch_tray_cache_base.dart +++ b/lib/src/fetch_tray_cache_base.dart @@ -4,7 +4,6 @@ import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_stor import 'package:fetch_tray/fetch_tray.dart'; import '../fetch_tray_cache.dart'; -import 'interceptors/cache_interceptor.dart'; /// Type of cache store enum TrayCacheStoreType { @@ -29,11 +28,13 @@ class TrayCachePluginKeys { class TrayCachePlugin implements TrayPlugin { final TrayCacheStoreType cacheStoreType; final Duration cacheDuration; + final bool loggingEnabled; late final CacheStore store; TrayCachePlugin({ this.cacheStoreType = TrayCacheStoreType.memory, this.cacheDuration = const Duration(days: 7), + this.loggingEnabled = false, String? cacheDirectory, }) { switch (cacheStoreType) { @@ -51,6 +52,7 @@ class TrayCachePlugin implements TrayPlugin { TrayCacheInterceptor( cacheOptions: cacheOptions, maxAge: cacheDuration, + loggingEnabled: loggingEnabled, ), DioCacheInterceptor( options: cacheOptions, diff --git a/lib/src/interceptors/cache_interceptor.dart b/lib/src/interceptors/cache_interceptor.dart index ccf1e01..a63b745 100644 --- a/lib/src/interceptors/cache_interceptor.dart +++ b/lib/src/interceptors/cache_interceptor.dart @@ -20,6 +20,7 @@ import 'package:logger/logger.dart'; class TrayCacheInterceptor extends Interceptor { final Duration maxAge; final CacheOptions cacheOptions; + final bool loggingEnabled; final Logger logger = Logger( printer: PrettyPrinter( methodCount: 0, @@ -30,11 +31,12 @@ class TrayCacheInterceptor extends Interceptor { TrayCacheInterceptor({ required this.cacheOptions, required this.maxAge, + this.loggingEnabled = false, }); @override - void onRequest(RequestOptions options, RequestInterceptorHandler handler, - [bool loggingEnabled = false]) async { + void onRequest( + RequestOptions options, RequestInterceptorHandler handler) async { // TODO: implement filter for logger /* final requestShouldLog = options.extra[TrayCachePluginKeys.requestShouldLog] as bool? ?? false; */ From dccb0d7335692b9d2a5541856fae066ecf2b7f60 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Wed, 7 Feb 2024 10:44:24 +0100 Subject: [PATCH 07/11] Add LogLevel Parameter --- example/fetch_tray_cache_example.dart | 4 +- lib/src/fetch_tray_cache_base.dart | 8 ++-- lib/src/interceptors/cache_interceptor.dart | 41 +++++++++------------ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/example/fetch_tray_cache_example.dart b/example/fetch_tray_cache_example.dart index 39404bf..a8eed6b 100644 --- a/example/fetch_tray_cache_example.dart +++ b/example/fetch_tray_cache_example.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:fetch_tray/fetch_tray.dart'; import 'package:fetch_tray_cache_plugin/fetch_tray_cache.dart'; +import 'package:logger/logger.dart'; import 'models/post.dart'; import 'requests/get_all_posts_request.dart'; @@ -15,7 +16,8 @@ void main() async { TrayCachePlugin( cacheStoreType: TrayCacheStoreType.memory, cacheDuration: const Duration(seconds: 2), - loggingEnabled: true, + logLevel: Level.debug, + // cacheDirectory: (await getTemporaryDirectory()).path, ), ], ); diff --git a/lib/src/fetch_tray_cache_base.dart b/lib/src/fetch_tray_cache_base.dart index df5e1c2..847cdc3 100644 --- a/lib/src/fetch_tray_cache_base.dart +++ b/lib/src/fetch_tray_cache_base.dart @@ -2,6 +2,7 @@ import 'package:dio/dio.dart'; import 'package:dio_cache_interceptor/dio_cache_interceptor.dart'; import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart'; import 'package:fetch_tray/fetch_tray.dart'; +import 'package:logger/logger.dart'; import '../fetch_tray_cache.dart'; @@ -28,13 +29,14 @@ class TrayCachePluginKeys { class TrayCachePlugin implements TrayPlugin { final TrayCacheStoreType cacheStoreType; final Duration cacheDuration; - final bool loggingEnabled; + + final Level logLevel; late final CacheStore store; TrayCachePlugin({ this.cacheStoreType = TrayCacheStoreType.memory, this.cacheDuration = const Duration(days: 7), - this.loggingEnabled = false, + this.logLevel = Level.error, String? cacheDirectory, }) { switch (cacheStoreType) { @@ -52,7 +54,7 @@ class TrayCachePlugin implements TrayPlugin { TrayCacheInterceptor( cacheOptions: cacheOptions, maxAge: cacheDuration, - loggingEnabled: loggingEnabled, + logLevel: logLevel, ), DioCacheInterceptor( options: cacheOptions, diff --git a/lib/src/interceptors/cache_interceptor.dart b/lib/src/interceptors/cache_interceptor.dart index a63b745..ada3269 100644 --- a/lib/src/interceptors/cache_interceptor.dart +++ b/lib/src/interceptors/cache_interceptor.dart @@ -20,18 +20,19 @@ import 'package:logger/logger.dart'; class TrayCacheInterceptor extends Interceptor { final Duration maxAge; final CacheOptions cacheOptions; - final bool loggingEnabled; - final Logger logger = Logger( - printer: PrettyPrinter( - methodCount: 0, - printTime: true, - ), - ); + final Level logLevel; + + get logger => Logger( + printer: PrettyPrinter( + methodCount: 0, + printTime: true, + ), + level: logLevel); TrayCacheInterceptor({ required this.cacheOptions, required this.maxAge, - this.loggingEnabled = false, + this.logLevel = Level.error, }); @override @@ -61,11 +62,9 @@ class TrayCacheInterceptor extends Interceptor { final cacheDuration = requestCacheDuration ?? maxAge; if (difference <= cacheDuration) { - if (loggingEnabled) { - logger.i( - '$logPrefix Cache hit, returning cached response', - ); - } + logger.i( + '$logPrefix Cache hit, returning cached response', + ); return handler.resolve( cache.toResponse( options, @@ -73,21 +72,17 @@ class TrayCacheInterceptor extends Interceptor { ), ); } else { - if (loggingEnabled) { - logger.i( - '$logPrefix Cache too old, deleting...', - ); - } + logger.i( + '$logPrefix Cache too old, deleting...', + ); await store.delete(key); } } } - if (loggingEnabled) { - logger.i( - '$logPrefix Sending request over network', - ); - } + logger.i( + '$logPrefix Sending request over network', + ); handler.next(options); } From 311a37f77ecd2ab3f3eb18b859969d8fa1c1f3cc Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Wed, 7 Feb 2024 10:46:38 +0100 Subject: [PATCH 08/11] Update Pubspec version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3f2226c..97551d2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fetch_tray_cache_plugin description: A caching plugin for fetch_tray. -version: 0.0.3 +version: 0.0.4 # repository: https://github.com/my_org/my_repo environment: From 2056ab7f7feb3b363aa11cf7b7d8f75eabd694f0 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Wed, 7 Feb 2024 10:55:31 +0100 Subject: [PATCH 09/11] Revert old fetch_tray dependency to main ref --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 97551d2..ba7d686 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,7 @@ name: fetch_tray_cache_plugin description: A caching plugin for fetch_tray. version: 0.0.4 +publish_to: none # repository: https://github.com/my_org/my_repo environment: @@ -10,8 +11,7 @@ environment: dependencies: fetch_tray: git: - url: https://github.com/Lightgaming/fetch_tray.git - ref: 6effd288177b80102e79d269f2ab1f619afc17b2 + url: https://github.com/marqably/fetch_tray dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 From 798cd12690e6cff9b4ff1dfc02919e1b10c4b802 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Wed, 7 Feb 2024 11:28:02 +0100 Subject: [PATCH 10/11] Depend on Fetch Tray from Pub.dev --- pubspec.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index ba7d686..6077d88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,9 +9,7 @@ environment: # Add regular dependencies here. dependencies: - fetch_tray: - git: - url: https://github.com/marqably/fetch_tray + fetch_tray: 0.2.4 dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1 From d423213b156e91ad3f922fde1c90d49cabd2cea6 Mon Sep 17 00:00:00 2001 From: Florian Lotz Date: Wed, 7 Feb 2024 12:58:51 +0100 Subject: [PATCH 11/11] Depend on Fetch Tray from Pub.dev --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6077d88..0c13cf7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: # Add regular dependencies here. dependencies: - fetch_tray: 0.2.4 + fetch_tray: ^0.3.3 dio: ^5.2.1+1 dio_cache_interceptor: ^3.4.2 dio_cache_interceptor_hive_store: ^3.2.1