rx_cache_manager 0.0.11+2 copy "rx_cache_manager: ^0.0.11+2" to clipboard
rx_cache_manager: ^0.0.11+2 copied to clipboard

RxCacheManager is a caching library for Flutter that provides a simple and flexible way to cache data and retrieve it efficiently. It uses a strategy-based approach, allowing you to define different c [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:rx_cache_manager/rx_cache_manager.dart';
import 'package:rx_cache_manager/strategy/cache_and_async_strategy.dart';
import 'package:rx_cache_manager/strategy/cache_or_async_strategy.dart';

class PayoutSettings {
  PayoutSettings({
    this.id,
    this.bankCode,
    this.bankName,
    this.bankAccountNumber,
    this.bankAccountName,
    this.bankEnquirySessionID,
    this.interval,
    this.canEdit = true,
    this.verified = false,
    this.prevPayout,
    this.nextPayout,
    this.createdAt,
    this.updatedAt,
  });
  String? id;
  String? bankCode;
  String? bankName;
  String? bankAccountNumber;
  String? bankAccountName;
  String? bankEnquirySessionID;
  String? interval;
  bool verified;
  bool canEdit;
  DateTime? prevPayout;
  DateTime? nextPayout;
  DateTime? createdAt;
  DateTime? updatedAt;
  factory PayoutSettings.fromMap(Map json) {
    return PayoutSettings()
      ..id = json['id']
      ..bankCode = json['bankCode']
      ..bankName = json['bankName']
      ..bankAccountNumber = json['bankAccountNumber']
      ..bankAccountName = json['bankAccountName']
      ..bankEnquirySessionID = json['bankEnquirySessionID']
      ..interval = json['interval']
      ..canEdit = json['canEdit'] == true
      ..verified = json['verified'] == true
      ..prevPayout =
          json['prevPayout'] != null ? DateTime.parse(json['prevPayout']) : null
      ..nextPayout =
          json['nextPayout'] != null ? DateTime.parse(json['nextPayout']) : null
      ..createdAt =
          json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null
      ..updatedAt =
          json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null;
  }
  Map toMap() {
    return {
      'id': id,
      'bankCode': bankCode,
      'bankName': bankName,
      'bankAccountNumber': bankAccountNumber,
      'bankAccountName': bankAccountName,
      'bankEnquirySessionID': bankEnquirySessionID,
      'interval': interval,
      'canEdit': canEdit,
      'prevPayout': prevPayout?.toIso8601String(),
      'nextPayout': nextPayout?.toIso8601String(),
      'createdAt': createdAt?.toIso8601String(),
      'updatedAt': updatedAt?.toIso8601String(),
    };
  }
}

void main() async {
  final cache = RxCacheManager(CacheStorage("default", debug: true));
  await Future.delayed(const Duration(seconds: 1));
  // await cache.clear();
  print(await cache.size(prefix: 'main'));
  final request = await cache
      .from<PayoutSettings, Map>("payout-settings")
      .withAsync(() => Future.delayed(
          const Duration(seconds: 2),
          () => {
                "id": "1234",
                "interval": "monthly",
              }))
      .withSerializer((json) => PayoutSettings.fromMap(json))
      .withStrategy(CacheAndAsyncStrategy())
      .withTtl(300)
      .execute();

  print(request?.toMap());
  print(await cache.cacheStorage.read("payout-settings"));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Placeholder(),
      ),
    );
  }
}
0
likes
120
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

RxCacheManager is a caching library for Flutter that provides a simple and flexible way to cache data and retrieve it efficiently. It uses a strategy-based approach, allowing you to define different caching strategies and apply them to your data. This README will guide you through the basic usage of RxCacheManager and how to integrate it into your Flutter project.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, hive_flutter, path_provider

More

Packages that depend on rx_cache_manager