mirror of
https://github.com/Myzel394/quid_faciam_hodie.git
synced 2025-06-18 15:25:27 +02:00
improved caching
This commit is contained in:
parent
ab764e7b16
commit
a09525c553
13
README.md
13
README.md
@ -1,16 +1,9 @@
|
||||
# Quid faciam Hodie
|
||||
|
||||
A new Flutter project.
|
||||
## What did I do today?
|
||||
|
||||
## Getting Started
|
||||
Find out what you did all the days and unlock moments you completely forgot!
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
## Showcase
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
|
@ -24,6 +24,8 @@ PODS:
|
||||
- permission_handler_apple (9.0.4):
|
||||
- Flutter
|
||||
- Polyline (5.0.2)
|
||||
- shared_preferences_ios (0.0.1):
|
||||
- Flutter
|
||||
- Tangram-es (0.17.1)
|
||||
- Toast (4.0.0)
|
||||
- uni_links (0.0.1):
|
||||
@ -44,6 +46,7 @@ DEPENDENCIES:
|
||||
- location (from `.symlinks/plugins/location/ios`)
|
||||
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
|
||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
|
||||
- uni_links (from `.symlinks/plugins/uni_links/ios`)
|
||||
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
|
||||
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/ios`)
|
||||
@ -76,6 +79,8 @@ EXTERNAL SOURCES:
|
||||
:path: ".symlinks/plugins/path_provider_ios/ios"
|
||||
permission_handler_apple:
|
||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||
shared_preferences_ios:
|
||||
:path: ".symlinks/plugins/shared_preferences_ios/ios"
|
||||
uni_links:
|
||||
:path: ".symlinks/plugins/uni_links/ios"
|
||||
url_launcher_ios:
|
||||
@ -96,6 +101,7 @@ SPEC CHECKSUMS:
|
||||
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
|
||||
permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce
|
||||
Polyline: fce41d72e1146c41c6d081f7656827226f643dff
|
||||
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
|
||||
Tangram-es: 628b634f7fc09d2217469b9914de00d9de49ff9d
|
||||
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
|
||||
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
|
||||
|
@ -1,59 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:quid_faciam_hodie/constants/storage_keys.dart';
|
||||
import 'package:quid_faciam_hodie/constants/values.dart';
|
||||
|
||||
const storage = FlutterSecureStorage();
|
||||
|
||||
class CacheManager {
|
||||
static _createKey(final String key) => '$CACHE_KEY/$key';
|
||||
|
||||
static Future<bool> isCacheValid(final String key) async {
|
||||
final cacheKey = _createKey(key);
|
||||
final existingEntry = await storage.read(key: cacheKey);
|
||||
|
||||
if (existingEntry != null) {
|
||||
try {
|
||||
final entry = jsonDecode(existingEntry);
|
||||
final DateTime creationDate = DateTime.parse(entry['creationDate']);
|
||||
|
||||
// Check if the entry is still valid using CACHE_INVALIDATION_DURATION as the validity duration.
|
||||
return DateTime.now().difference(creationDate) <
|
||||
CACHE_INVALIDATION_DURATION;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static Future<void> set(final String key, final String data) async {
|
||||
final cacheKey = _createKey(key);
|
||||
final cacheEntry = {
|
||||
'creationDate': DateTime.now().toIso8601String(),
|
||||
'data': data,
|
||||
};
|
||||
|
||||
return storage.write(
|
||||
key: cacheKey,
|
||||
value: json.encode({
|
||||
key: cacheEntry,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<String?> get(final String key) async {
|
||||
final cacheKey = _createKey(key);
|
||||
final existingEntry = await storage.read(key: cacheKey);
|
||||
|
||||
if (existingEntry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final entry = jsonDecode(existingEntry);
|
||||
|
||||
return entry['data'];
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_cache/flutter_cache.dart' as cache;
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:location/location.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:quid_faciam_hodie/constants/values.dart';
|
||||
import 'package:quid_faciam_hodie/foreign_types/memory.dart';
|
||||
import 'package:quid_faciam_hodie/managers/cache_manager.dart';
|
||||
import 'package:quid_faciam_hodie/managers/global_values_manager.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@ -99,15 +100,15 @@ class FileManager {
|
||||
final key = '$table:$path';
|
||||
|
||||
// Check cache
|
||||
if (!disableCache && await CacheManager.isCacheValid(key)) {
|
||||
final data = (await CacheManager.get(key))!;
|
||||
return Uint8List.fromList(data.codeUnits);
|
||||
if (!disableCache) {
|
||||
return cache.load(key) as Uint8List;
|
||||
}
|
||||
|
||||
final data = await _downloadFileData(table, path);
|
||||
|
||||
final cacheData = String.fromCharCodes(data);
|
||||
await CacheManager.set(key, cacheData);
|
||||
|
||||
await cache.write(key, cacheData, CACHE_INVALIDATION_DURATION.inMinutes);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache/flutter_cache.dart' as cache;
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
@ -179,6 +180,9 @@ class _SettingsScreenState extends AuthRequiredState<SettingsScreen>
|
||||
title: Text(localizations
|
||||
.settingsScreenAccountSectionLogoutLabel),
|
||||
onPressed: (_) async {
|
||||
cache.clear();
|
||||
storage.deleteAll();
|
||||
|
||||
await callWithLoading(supabase.auth.signOut);
|
||||
|
||||
if (!mounted) {
|
||||
|
@ -31,7 +31,6 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
storage.deleteAll();
|
||||
getInitialImageForPhotoSwitching();
|
||||
}
|
||||
|
||||
|
63
pubspec.lock
63
pubspec.lock
@ -167,6 +167,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_cache:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_cache
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.0"
|
||||
flutter_calendar_widget:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -630,6 +637,62 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
shared_preferences:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.15"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.12"
|
||||
shared_preferences_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_ios
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
shared_preferences_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
@ -64,6 +64,7 @@ dependencies:
|
||||
url_launcher: ^6.1.5
|
||||
apple_maps_flutter: ^1.2.0
|
||||
morphing_text: ^1.0.1
|
||||
flutter_cache: ^0.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user