cached_repository 0.0.1 copy "cached_repository: ^0.0.1" to clipboard
cached_repository: ^0.0.1 copied to clipboard

retracted

Simple, easy to use and extensible cached repository which can store all you need.

Logger #

pub package Last Commits Pull Requests Code size License

Simple, easy to use and extensible cached repository which can store all you need.
Inspired by NetworkBoundResource for Android.

Show some ❤️ and star the repo to support the project

Resources: #

Getting Started #

Just create a class with CachedRepository field and start caching:

class StringRepository {
  StringRepository(SomeClassApi _someClassApi)
      : _cachedRepo = CachedRepository.persistent(
    'my_objects',
    fetch: (String key, [__]) => _someClassApi.getObjects(),
    decode: (json) => SomeClass.listFromJson(json),
    cacheDuration: const Duration(hours: 12),
  );

  final CachedRepository<String, List<SomeClass>> _cachedRepo;

  static const _key = '';

  Stream<Resource<List<SomeClass>>> officeString({
    bool forceReload = false,
  }) =>
      _cachedRepo.stream(_key, forceReload: forceReload);

  Future<void> invalidate() => _cachedRepo.invalidate(_key);

  Future<void> removeStringFromCache({
    required String stringId,
  }) async {
    return _cachedRepo.updateValue(_key, (list) {
      return list?.where((it) => it.id != stringId).toList(growable: false);
    });
  }

  Future<void> removeCompaniesFromCache({
    required List<String> stringIds,
  }) async {
    return _cachedRepo.updateValue(_key, (list) {
      return list
          ?.where((it) => !stringIds.contains(it.id))
          .toList(growable: false);
    });
  }

  Future<void> clear() => _cachedRepo.clear();
}

abstract class SomeClass {
  String get id;

  static List<SomeClass> listFromJson(List<dynamic> jsonList) => <SomeClass>[];
}

abstract class SomeClassApi {
  Future<List<SomeClass>> getObjects();
}

Instead of a SomeClass and SomeClassApi, you can use your own classes.

Feel free to open pull requests.

Acknowledgments #

This package was created by Artemii Oliinyk.

2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Simple, easy to use and extensible cached repository which can store all you need.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_secure_storage, hive_flutter, logger, rxdart, synchronized, worker_manager

More

Packages that depend on cached_repository