Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
738 stars 427 forks source link

Export File System #431

Open wyyadd opened 8 months ago

wyyadd commented 8 months ago

: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
  2. run flutter pub get
  3. 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](https://github.com/Baseflow/flutter_cache_manager/blob/develop/CONTRIBUTING.md))
- [x] Relevant documentation was updated
- [x] Rebased onto current develop

### Proposal
> Please consider using `getApplicationCachePath()` introduced in path_provider 2.1.0:
> 
> * [[path_provider] Add getApplicationCachePath() flutter/packages#4483](https://github.com/flutter/packages/pull/4483)
> 
> Notice that /tmp may be unsuitable for caching on systems with multiple users. For example, run the [cached_network_image](https://pub.dev/packages/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
MichalNemec commented 3 months ago

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