Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export File System #431

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Export File System #431

wants to merge 2 commits into from

Conversation

wyyadd
Copy link

@wyyadd wyyadd commented Oct 9, 2023

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

feature

⤵️ What is the current behavior?

The FileSystem, IOFileSystem and MemoryCacheSystem can't be imported like code below.

import 'package:flutter_cache_manager/flutter_cache_manager.dart';

class CustomCacheManager {
  static const key = 'customCacheKey';
  static CacheManager instance = CacheManager(
    Config(
      key,
      stalePeriod: const Duration(days: 7),
      maxNrOfCacheObjects: 20,
      repo: JsonCacheInfoRepository(databaseName: key),
      fileSystem: IOFileSystem(key),
      fileService: HttpFileService(),
    ),
  );
}

🆕 What is the new behavior (if this is a feature change)?

The FileSystem, IOFileSystem and MemoryCacheSystem can be imported

💥 Does this PR introduce a breaking change?

No

🐛 Recommendations for testing

  1. update pubspec.yaml
  flutter_cache_manager:
    git:
      url: https://github.com/wyyadd/flutter_cache_manager
      path: flutter_cache_manager
  1. run flutter pub get
  2. run code below to test
import 'package:flutter_cache_manager/flutter_cache_manager.dart';

class CustomCacheManager {
  static const key = 'customCacheKey';
  static CacheManager instance = CacheManager(
    Config(
      key,
      stalePeriod: const Duration(days: 7),
      maxNrOfCacheObjects: 20,
      repo: JsonCacheInfoRepository(databaseName: key),
      fileSystem: IOFileSystem(key),
      fileService: HttpFileService(),
    ),
  );
}

📝 Links to relevant issues/docs

#365

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

Proposal

Please consider using getApplicationCachePath() introduced in path_provider 2.1.0:

Notice that /tmp may be unsuitable for caching on systems with multiple users. For example, run the cached_network_image example first as user A and then as user B on Ubuntu:

PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc555ac0-23b8-11ee-8203-690c79df21e0.jpg' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc555ac0-23b8-11ee-8203-690c79df21e0.jpg' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://notAvalid.uri with error:
ClientException with SocketException: Failed host lookup: 'notavalid.uri' (OS Error: No address associated with hostname, errno = -5), uri=https://notavalid.uri
flutter: CacheManager: Failed to download file from https://via.placeholder.com/300x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854460-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/200x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854461-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/350x200 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc854462-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc854461-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/350x150 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc856b70-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
flutter: CacheManager: Failed to download file from https://via.placeholder.com/300x300 with error:
PathAccessException: Cannot open file, path = '/tmp/libCachedImageData/dc856b71-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc856b70-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)
Another exception was thrown: PathAccessException: Cannot open file, path =
'/tmp/libCachedImageData/dc856b71-23b8-11ee-8203-690c79df21e0.png' (OS Error: Permission denied, errno = 13)

For flutter desktop, it would be better to use getApplicationCacheDirectory() instead of getTemporaryDirectory() to create directory.
Relevant issue: #416

@MichalNemec
Copy link

why is this not merged already, it has been quite some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants