flutter_cache_manager icon indicating copy to clipboard operation
flutter_cache_manager copied to clipboard

Export File System

Open wyyadd opened this issue 2 years ago • 1 comments

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

feature

:arrow_heading_down: 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(),
    ),
  );
}

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

The FileSystem, IOFileSystem and MemoryCacheSystem can be imported

:boom: Does this PR introduce a breaking change?

No

:bug: 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(),
    ),
  );
}

:memo: Links to relevant issues/docs

https://github.com/Baseflow/flutter_cache_manager/issues/365

:thinking: Checklist before submitting

  • [x] All projects build
  • [x] Follows style guide lines (code style guide)
  • [x] Relevant documentation was updated
  • [x] 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: https://github.com/Baseflow/flutter_cache_manager/issues/416

wyyadd avatar Oct 09 '23 03:10 wyyadd

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

MichalNemec avatar Mar 24 '24 18:03 MichalNemec

Without this it is not even possible to create a CacheManager object properly 🙃

slaci avatar Jul 26 '24 12:07 slaci