Skip to content
Merged
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
91 changes: 68 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,53 @@
.atom/
.buildlog/
.history
.project
.svn/
bin/
devtools_options.yaml

# Environment files
ios/Flutter/Dart-Defines.xcconfig

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Android Studio related
android/.classpath
android/.settings/

# Visual Studio Code related
.vscode/

# Flutter repo-specific
/bin/cache/
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/docs/doc/
/dev/docs/lib/
/dev/docs/pubspec.yaml
/packages/flutter/coverage/
version
.classpath
.project
.settings/
.vscode/*

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
**/generated_plugin_registrant.dart
.packages
.pub-preload-cache/
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds
flutter_export_environment.sh

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
.gradle/
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
*.jks

# iOS/XCode related
**/ios/**/*.mode1v3
Expand All @@ -77,20 +73,69 @@ flutter_export_environment.sh
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/ephemeral
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# macOS
**/Flutter/ephemeral/
**/Pods/
**/macos/Flutter/GeneratedPluginRegistrant.swift
**/macos/Flutter/ephemeral
**/xcuserdata/

# Windows
**/windows/flutter/generated_plugin_registrant.cc
**/windows/flutter/generated_plugin_registrant.h
**/windows/flutter/generated_plugins.cmake

# Linux
**/linux/flutter/generated_plugin_registrant.cc
**/linux/flutter/generated_plugin_registrant.h
**/linux/flutter/generated_plugins.cmake

# Coverage
coverage/

# Submodules
packages/**/pubspec.lock

# Web related
lib/generated_plugin_registrant.dart

# Symbols
app.*.symbols

# Obfuscation related
app.*.map.json

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
example/.flutter-plugins-dependencies
flutter_cache_manager/example/ios/Flutter/.last_build_id
!/dev/ci/**/Gemfile.lock
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.idea/codeStyles/
!.idea/dictionaries/
!.idea/runConfigurations/

# Generated files
**/generated
*.g.dart

# Injection generated files
injectable.config.dart
6 changes: 4 additions & 2 deletions flutter_cache_manager/lib/src/cache_store.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'dart:io' as io;
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart';

///Flutter Cache Manager
Expand Down Expand Up @@ -181,8 +182,9 @@ class CacheStore {
if (_futureCache.containsKey(cacheObject.key)) {
_futureCache.remove(cacheObject.key);
}
final file = await fileSystem.createFile(cacheObject.relativePath);
if (await file.exists()) {
final file = io.File(cacheObject.relativePath);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martijn00
Files will not be deleted after this change. Previously, the location of the directory was set within the fileSystem, so can get file information by relativePath. But now, cannot get file information by relativePath because using io.File


if (file.existsSync()) {
await file.delete();
}
}
Expand Down
55 changes: 43 additions & 12 deletions flutter_cache_manager/test/cache_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import 'helpers/mock_cache_info_repository.dart';
import 'helpers/test_configuration.dart';

void main() {
late int fileId;
late String fileName;
late String fileUrl;
late DateTime validTill;

late CacheObject cacheObject;

setUp(() {
fileId = 666;
fileName = 'testimage.png';
fileUrl = 'baseflow.com/test.png';
validTill = DateTime(2017, 9, 7, 17, 30);

cacheObject = CacheObject(
fileUrl,
relativePath: fileName,
id: fileId,
validTill: validTill,
);
});

group('Retrieving files from store', () {
test('Store should return null when file not cached', () async {
var repo = MockCacheInfoRepository();
Expand All @@ -21,9 +42,6 @@ void main() {
});

test('Store should return FileInfo when file is cached', () async {
var fileName = 'testimage.png';
var fileUrl = 'baseflow.com/test.png';

var config = createTestConfig();
await config.returnsFile(fileName);
config.returnsCacheObject(fileUrl, fileName, DateTime.now());
Expand All @@ -36,6 +54,28 @@ void main() {
expect(await store.getFile('baseflow.com/test.png'), isNotNull);
});

test('Store should return null if file is not cached', () async {
var config = createTestConfig();
await config.returnsFile(fileName);
config.returnsCacheObject(fileUrl, fileName, validTill,
id: fileId, key: fileUrl);

var tempDir = createDir();
await (await tempDir).childFile('testimage.png').create();

final store = CacheStore(config);

final results = Future.wait([
store.removeCachedFile(cacheObject),
store.removeCachedFile(cacheObject),
]);

expect(
() => results,
returnsNormally,
);
});

test('Store should return null when file is no longer cached', () async {
var repo = MockCacheInfoRepository();

Expand All @@ -59,9 +99,6 @@ void main() {
});

test('Store should return CacheInfo when file is cached', () async {
var fileName = 'testimage.png';
var fileUrl = 'baseflow.com/test.png';

var config = createTestConfig();
await config.returnsFile(fileName);
config.returnsCacheObject(fileUrl, fileName, DateTime.now(), id: 1);
Expand All @@ -74,8 +111,6 @@ void main() {

test('Store should return CacheInfo from memory when asked twice',
() async {
var fileName = 'testimage.png';
var fileUrl = 'baseflow.com/test.png';
var validTill = DateTime.now();
var config = createTestConfig();

Expand All @@ -96,8 +131,6 @@ void main() {
test(
'Store should return File from memcache only when file is retrieved before',
() async {
var fileName = 'testimage.png';
var fileUrl = 'baseflow.com/test.png';
var validTill = DateTime.now();
var config = createTestConfig();

Expand Down Expand Up @@ -172,8 +205,6 @@ void main() {

group('Removing files in store', () {
test('Store should remove fileinfo from repo on delete', () async {
var fileName = 'testimage.png';
var fileUrl = 'baseflow.com/test.png';
var validTill = DateTime.now();
var config = createTestConfig();

Expand Down