Flutter shareable package of object-oriented classes for local caching of user data in json

Overview

json_cache

json cache logo

EO principles respected here DevOps By Rultor.com

pub license style: lint PDD status build codecov Hits-of-Code

Json Cache is an object-oriented package to serve as a layer on top of local storage packages - packages that persist data locally on the user's device -, unifying them as an elegant cache API.

In addition, this package gives the programmer great flexibility; it provides a set of classes that can be selected and combined in various ways to address specific caching requirements.

Why Json?

  • Because most of the local storage packages available for Flutter applications use json as the data format.
  • There is an one-to-one relationship between the Dart's built-in type Map<String, dynamic> and json, which makes json encoding/decoding a trivial task.

Getting Started

JsonCache - the core interface of this package - represents the concept of cached data. It is defined as:

/// Represents a cached json data.
abstract class JsonCache {
  /// Frees up cache storage space.
  Future<void> clear();

  /// Refreshes some cached data by its associated key.
  Future<void> refresh(String key, Map<String, dynamic> data);

  /// Erases [key] and returns its associated data.
  Future<Map<String, dynamic>?> erase(String key);

  /// Recovers some cached data; null if a cache miss occurs - no [key] found.
  Future<Map<String, dynamic>?> recover(String key);
}

It's reasonable to consider each cache entry (pair of key/data) as a group of related data. Thus, it is expected to cache user data in groups, in which a key represents the name of a single group of data. Example:

'profile': {'name': 'John Doe', 'email': '[email protected]', 'accountType': 'premium'};
'preferences': {'theme': {'dark': true}, 'notifications':{'enabled': true}}

Above the 'profile' key is associated with the group of profile related data; 'preferences', with preferences data.

You might also like...

A generator for fhir dart classes with json artifacts.

A generator for fhir dart classes with json artifacts. Thie generator uses the freezed package to generate the data classes. It also uses all the primitive_types from the fhir package.

Jun 14, 2022

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications Example Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_l

Nov 29, 2022

A Video and Audio player that can play from local assets, local files and network URLs with the powerful controls

A Video and Audio player that can play from local assets, local files and network URLs with the powerful controls

Video/Audio Player in Flutter with Powerful controls How can we play videos in Flutter? There is a library directly from the Flutter team simply calle

Jan 31, 2022

Flutter package: Json Table Widget to create table from json array

Flutter package: Json Table Widget to create table from json array

Json Table Widget 💙 Proudly Sponsored by FieldAssist Request a Demo This Flutter package provides a Json Table Widget for directly showing table from

Jan 7, 2023

Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

Stories like in Instagram, each story can include multiple images and videos. Package supports video, titles, preliminary caching.

flutter_instagram_stories A Flutter package for displaying stories just like Whatsapp & Instagram. Built-in groups (multiple stories with one icon), c

Dec 9, 2022

Snoozed, open source Flutter app. A focus oriented To-Do list with skippable tasks.

Snoozed, open source Flutter app. A focus oriented To-Do list with skippable tasks.

Snoozed: Skippable To Do list Download the App Apple App Store Google Play Store Video Tutorial YouTube video link Stack Front-end: Flutter Back-end:

Jan 5, 2023

Created a mobile application for my Project Oriented class.

Created a mobile application for my Project Oriented class.

Projet Scarla C'est pour notre cours : Projet d'intégration avec Raouf Babari au semestre d'hiver 2021. Projet Scarla Le nom de notre projet d’intégra

Jan 4, 2022

Create dart data classes easily, fast and without writing boilerplate or running code generation.

Create dart data classes easily, fast and without writing boilerplate or running code generation.

Dart Data Class Generator Create dart data classes easily, fast and without writing boilerplate or running code generation. Features The generator can

Feb 28, 2022
Comments
  • Async operations don't complete inside testWidgets()

    Async operations don't complete inside testWidgets()

    I'm working on my first flutter application, so I may have missed an obvious solution to this. I'm running into problems interacting with json_cache + localstorage within the context of tests. I've attempted to create a minimal reprodction.

    import 'package:flutter/material.dart';
    import 'package:flutter_test/flutter_test.dart';
    
    import 'package:json_cache/json_cache.dart';
    import 'package:localstorage/localstorage.dart';
    
    void main() {
      TestWidgetsFlutterBinding.ensureInitialized();
    
      testWidgets('database insert', (tester) async {
        final LocalStorage storage = LocalStorage('test-idea');
        var database = JsonCacheMem(JsonCacheLocalStorage(storage));
        print('before');
        await database.refresh('test', {'k': 'v'});
        print('set value');
      });
    }
    

    When I run this test with flutter test it prints before but never prints set value. However, if I use test() instead of testWidgets() the test completes successfully. The broader context of what I'm trying to do is, write a more complex test case where I display a form. That form contains dropdown menus that contain data that would be read from json_cache, but I'm not currently able to get data into json_cache.

    opened by markstory 7
Releases(1.5.0)
  • 1.5.0(Dec 5, 2022)

    See #111, release log:

    • 3feee6b8e50edece6e9a9cdc32838cf6f1ab4216 by @rultor: version 1.5.0
    • 32834bf590191458214ae9b821b8260525b16d3e by @rafamizes: feat: 'JsonCacheTry' throws 'J...
    • 6bc4cad1d4cc48b22f523c5e1f45c9c0c0039b0b by @rultor: version 1.4.2

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.4.2(Sep 10, 2022)

  • 1.4.1(Sep 10, 2022)

    See #105, release log:

    • fd5a4a22db6c6b630d0df5cc359f9f5c1de9e546 by @rultor: version 1.4.1
    • 7523dfcc3697658427d04c9efd7baf8d57dc7acd by @rafamizes: fix: export 'JsonCacheTry' (#1...

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Sep 10, 2022)

    See #102, release log:

    • f1898553556c069a61fca452f1c8b205349515ef by @rultor: version 1.4.0
    • d4b58407a9be5d719b197a9aaeb6a204dba874a0 by @rafamizes: feat: 'JsonCacheException' and...
    • 81e0162cfe0ad54f79ded6af65e3184abf3df9d3 by @rafamizes: Update README.md

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Aug 25, 2022)

    See #99, release log:

    • 5b5d5aea6c426566f90347614f27aea97f2d2186 by @rultor: version 1.3.1
    • 9c9aced69ae2265b743946a7cbbc69861a023bb1 by @rafamizes: Update pubspec.yaml
    • 5ad81ec4d925ed6bb6df7e9b2c398e1dc95f634d by @rafamizes: build: update 'flutter_secure_...
    • ee57ec479bab220036f57c0d0dd91f50741075f7 by @rafamizes: Update CHANGELOG.md
    • fd83ac22f9395493248ddeac3f45cb2eacfa38dc by @rafamizes: doc: documentation improvement...

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Aug 7, 2022)

    See #94, release log:

    • 543dbddbbc75057168699fefc92b77c5a9aa42d8 by @rultor: version 1.3.0
    • 03f5d76a146214205c3a7bb5149d26368492b184 by @rafamizes: feat: implementation of the 'c...
    • 6ec937d7ff71587852af0cc4ca382d6909351918 by @rultor: version 1.2.6

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.2.6(Aug 1, 2022)

    See #90, release log:

    • 9f7a18c9bcc98dd4e1b3ac905009fb9b13a9dc58 by @rafamizes: Update README.md
    • 6f613f029742ec67dfc224705b6a8bb4b86bbd77 by @rafamizes: doc(README): minor corrections...
    • e0d61555b15dd63e02d844962c7062f6bf36ac39 by @rafamizes: chore: add code style improvem...
    • 049dca49cf58fc2c7b05161844ef1167d306e42b by @rafamizes: Update CHANGELOG.md
    • 00d8fff68dcfdf551479dc8ab008a96e9197684f by @rafamizes: doc(README): minor changes
    • 73ad5133a8a77d458a088d98fabf51152e0ddc60 by @rafamizes: Update CHANGELOG.md
    • 6c8ae1309e2afea673d35b2fe6ab86273a01b64a by @rafamizes: doc(README): fix broken link
    • cd68b0709ec624ad162668f1165975737423c7da by @rultor: version 1.2.5

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.2.5(Jul 26, 2022)

    See #85, release log:

    • 3ae38ff74b6330204cd970c272d168b4b8f03f1c by @rafamizes: Update README.md
    • 9eeb2f99479302fe812b207d1d2854c7473fff6b by @rafamizes: doc: move 'Suggested Dependenc...

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.2.4(Jul 26, 2022)

    See #82, release log:

    • 124a4b7a7df1cd22a6efcac0ec02ca8a03a32bf7 by @rultor: version 1.2.4
    • 27ad997d107d864c90fc475d093146a547468a32 by @rafamizes: fix: the value of the version ...
    • ae8285d56205d500811dd08bfac5432e30d118b7 by @rafamizes: build: bump up dependencies Cl...
    • 537023142194ebc0122b2c3585c68a8b111b7c53 by @rafamizes: doc: add unit testing tips to ...

    Released by Rultor 2.0-SNAPSHOT, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Apr 2, 2022)

    See #71, release log:

    • 1d75f6dd213cbc0e9fe1e809f266517a84b733c1 by @rultor: version 1.2.1
    • 4a821f7f3b26e0a2f0f9fd1eb7edae3865a34de2 by @rafamizes: build: bump up dependencies Cl...
    • 4831c8ab68800d4964353721f875895276df4cbe by @rafamizes: chore(README): fix logo positi...
    • c2f8f89c56ab04fd7d107f915b373f54e4ad1c0f by @rafamizes: chore: fix project logo image ...

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Apr 1, 2022)

    See #66, release log:

    • 1772ebb9dc9c52188786bd2c864026dd2a55d142 by @rultor: version 1.2.0
    • 97bff0e2ba492f6ecf7bc5c05ed64b33263192e7 by @rafamizes: feat: JsonCacheHive class (#65...

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.1.2(Jan 28, 2022)

    See #63, release log:

    • 79c36046bdb119ff659272016e2851c499e0d4c1 by @rultor: version 1.1.2
    • 36f3912cc94b5ef95ef1cee191ff85ae080fe7ad by @rafamizes: Update CHANGELOG.md
    • ada7d293dd66f6e4224f24779dadb8bb47bb6d54 by @rafamizes: doc(README): how to write stri...
    • fb269526af3b5fbcd314b158a334c6a44c9a4b2e by @rafamizes: doc(README): fix grammar error

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.1.1(Jan 28, 2022)

    See #62, release log:

    • 7b0e9c8bd72df7eafa0e52d36fe8d4b52c5d6d21 by @rultor: version 1.1.1
    • 9f84981929cfd042ec8cb2c8544c2d4949c6038f by @rafamizes: Fix readme (#61) * fix: error ...

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jan 28, 2022)

    See #60, release log:

    • 7751b01c1dff1990aa8990fb0cdd6627721272cf by @rultor: version 1.1.0
    • bffc03c79ddf8f57e840c0487ec5b28ce9382ae5 by @rafamizes: feat: create JsonCacheSecStora...
    • 01b09ed349a07ede0c4fab15b831c0c489aa1483 by @rafamizes: doc(README): change contribute...
    • fd52ed5da0f46b6d82c1f2f7446d59775c43d426 by @rultor: version 1.0.0

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jan 8, 2022)

    See #57, release log:

    • b4ab9a78d68e5658b3239a14df5d51e2d1c44378 by @rafamizes: test: add test case for L2 hit...
    • c8022e1a91516398080451cdddab10642e0a35c4 by @rafamizes: doc(README): add link to the J...
    • 7685da2d93864acb47e141af09cc2963d22334ce by @rafamizes: doc(CHANGELOG): changes of the...
    • 45416b51155fcc5e81ee8a633160246f3409af25 by @rafamizes: doc: improvements to the READM...
    • 8677785e2411b47cfc5dd7f9a58ca973d711f025 by @rafamizes: style: stricter linting rules ...
    • c1318035eede3be99c159ebac682538997a5e37f by @rafamizes: build: bump up dependencies (#...

    Released by Rultor 1.70.6, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.3.4(Aug 26, 2021)

    See #47, release log:

    • a3b4a2c7e18f5aba223838e572906119713f9a51 by @rultor: version 0.3.4
    • 06c23647fc86bf5daa4ebf8d86a48c15f93c19ce by @rafamizes: Update CHANGELOG.md
    • 0b01aad21ed7a6af0ac4e56a8bef5ef21b0d34b8 by @rafamizes: doc(README): much better packa...
    • dcd4dff29bca1621b60b6662e59690ab8d669ccd by @rafamizes: Update README.md

    Released by Rultor 1.70.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.3.3(Aug 26, 2021)

    See #46, release log:

    • 05851ccc703b55a4c87d8bc323feacf3fc9af3f1 by @rultor: version 0.3.3
    • 55930954f220c4798b89f34f6c60e9f74ad2091a by @rafamizes: feat: create JsonCacheEncPrefs...

    Released by Rultor 1.70.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Aug 25, 2021)

    See #44, release log:

    • b7b7dd4015f8f00d3ee8ed1161fa10ddbf05919f by @rultor: version 0.3.2
    • 12d366a8636115796b08ab35a2d316ade8c08b29 by @rafamizes: Update README.md
    • 8e8909ffd3e94603a7776337a9f53f614bdb692f by @rafamizes: refact: remove 'late' modifier...
    • aef40105adc8e65b4f9120c93c31e18f26177fc3 by @rafamizes: Update README.md

    Released by Rultor 1.70.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Aug 25, 2021)

    See #42, release log:

    • 61569ace4eeb120281a5b283dcef318d90fa630b by @rultor: version 0.3.1
    • bc4590616e4fbfa8d6ec804355fa03dcdd1545e7 by @rafamizes: doc(README): fix formatting an...
    • a3b0737da76f30bfebee84a3ffe3aa1319651238 by @rafamizes: Update README.md
    • 7445f5b5ee806517779edbea6ac30eb0014d3b4b by @rafamizes: Update README.md
    • 6d43a7635c09d493ef9f9c1c19b3a4dfa0c86fa2 by @rafamizes: Update README.md
    • 3cb00283588827eca2d16617ff9e4f71af7f52d2 by @rafamizes: feat: JsonCacheCrossLocalStora...
    • 326f2385ccd2e6508734cbc4199c2bbdb818414a by @rafamizes: style: pub dev fixes * refacto...

    Released by Rultor 1.70.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Aug 25, 2021)

    See #37, release log:

    • 2cef1ddfae7ead0296c4535299b8a0931c95802b by @rultor: version 0.3.0
    • b896a41923efeb4ddf451f1562867b1f0e5f857a by @rafamizes: refactor!: restore JsonCacheMe...
    • 5351002a06aaf212c5e8e291bd2ad124da0a27fd by @rafamizes: refactor! rename JsonCacheMem....
    • 1f91e763fdfb4b685974f2978adc8c2b952be872 by @rafamizes: Update README.md
    • 9410fad1904c4a1b9f6c1f12f185eb8b5c586230 by @rafamizes: Update README.md
    • f7ea4fa58657c6e680bc121c7190ed618d020743 by @rafamizes: Update README.md
    • f7e67114ed027dc6fb9a9a1d5e9ee7842f0b55d1 by @rafamizes: Update README.md
    • 8b3f21857e2e1c49e21ed0ed9a514f2dfff52cea by @rafamizes: Update README.md

    Released by Rultor 1.70.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.2.1(Aug 23, 2021)

    See #34, release log:

    • 947f0a6d46157494b50fcb2b505af2b04e4fd35b by @rultor: version 0.2.1
    • 14f2529a9dabd19a8849d1aa45531e8ebf6f4d58 by @rafamizes: Update README.md
    • 2d757cc3a26d5a00f3cc89dbe205ebadbecfee5d by @rafamizes: feat: JsoCacheLocalStorage Clo...

    Released by Rultor 1.69.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Aug 22, 2021)

    See #28, release log:

    • 811fd844c40be6962b7c6e01656a575393c8e1a7 by @rultor: version 0.2.0
    • 8bbf7ff3ec74202469d950b01520ce3a487741ff by @rafamizes: feat: JsonCachePrefs class Clo...

    Released by Rultor 1.69.1, see build log

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Aug 22, 2021)

    See #25, release log:

    • cf9777825c028ea3438cc44b5c154b6fa221405b by @rultor: version 0.1.0
    • 0cddc6e66a9e2f182fb4163e020e11557bbdc130 by @rafamizes: Update CHANGELOG.md
    • cc95ff6dc62ca74e68b0f273527a71e24386bfeb by @rafamizes: built: update lint version to ...
    • a3e8247991c0abf76faeaa41515897e05a111c97 by @rafamizes: Update README.md
    • f6eca7cb746d4484e5009d1d186cecb07d63c9de by @rafamizes: Update README.md
    • b515e01a5ce89aa64d6021c097d351d9ede4f2ae by @rafamizes: Update README.md
    • 870ddc46883c3f236952c1ea6593ea4ec66ef103 by @rafamizes: test: JsonCacheWrap, JsonCache...
    • 5730204f6a16e1328fd628fca8977992f67a66f7 by @rafamizes: fix more grammar mistakes
    • b4db1e479629360c25fa7b116938c23e5b25b6d9 by @rafamizes: fix grammar errors
    • f5e0535282d3901b06b92156b9b5d11337b3d5c7 by @rafamizes: Update README.md
    • b8b9593acbe652ad551bad43897f504df2362757 by @rafamizes: Update README.md
    • dbba968f1a75b267dcd5e9db94e785a7d9dedc62 by @rafamizes: feat: JsonCache interface and ...
    • d1d22f1c9048394d539a381380bbc18878bc4e23 by @rafamizes: build(rultor): disable squashi...
    • 7907fd43cbd1e9b1018861709e9f525656d472d1 by @rultor: build: structural configuratio...
    • 00959bc149c06e335bc1349e2a9676824fbff283 by @rafamizes: chore: remove annoying issue t...
    • 84ccc66097d0686a2e503a8a0fa12916faffcc43 by @rafamizes: doc(README): enhance the conte...
    • 6bef1d693ce6f7678b4b59b109a5dfdd645d2e02 by @rultor: doc(README): improve the packa...
    • cf9f37fcfd355d90178fcc214647aebc2abf1f33 by @rafamizes: doc(README): add the project's...
    • 77b4c8ffdfb83adb2e451215e53bccd953cc48c7 by @rafamizes: doc(README): insert badges #8 ...
    • 0678745e41ba730fd6acf786b694638c25c2444a by @rafamizes: doc: fix the project name in i...
    • and 4 more...

    Released by Rultor 1.69.1, see build log

    Source code(tar.gz)
    Source code(zip)
Owner
Dartoos
Web and mobile software company
Dartoos
State Persistence - Persist state across app launches. By default this library store state as a local JSON file called `data.json` in the applications data directory. Maintainer: @slightfoot

State Persistence Persist state across app launches. By default this library store state as a local JSON file called data.json in the applications dat

Flutter Community 70 Sep 28, 2022
🎯 This library automatically generates object classes from JSON files that can be parsed by the freezed library.

The Most Powerful Way to Automatically Generate Model Objects from JSON Files âš¡ 1. Guide ?? 1.1. Features ?? 1.1.1. From 1.1.2. To 1.2. Getting Starte

KATO, Shinya / 加藤 真也 14 Nov 9, 2022
Object-oriented package for validating Flutter form fields.

formdator Contents Overview Getting Started List of Validators Categories Demo Application References Overview Form Validator — Formdator is a fully o

Dartoos 10 Oct 26, 2022
Seyifunmi Araoluwa 1 Jan 10, 2022
Local data hive - Local data hive for flutter

local_data_hive A new Flutter application. ScreenShot

Mehmet Emre ÖZ 0 Jan 8, 2022
Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON.

JSON to Dart Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON. This library is designed to ge

Javier Lecuona 1.2k Dec 25, 2022
A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes.

A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes. Introduction Jsonize solves the problem of

null 2 Nov 17, 2022
This repository is Online_Learning Screen UI - Flutter. I am fetching the data from the local JSON API.

online_learning A new Flutter Online_Learning application. Designed by Arun PP, Code with Flutter by Kishor Kc. Kishor Kc I am fetching the data from

Kishor Kc 14 Jul 5, 2022
Fluter-json - App Demonstrating JSON Data Parsing with various flutter widgets

users_list Flutter App to Demonstrate JSON Parsing Getting Started This project is a starting point for a Flutter application. A few resources to get

Khurram Rizvi 5 Jul 10, 2021
Receiving ozh's github-colors repository with latest commit of colors.json to Flutter's Color object.

Apply GitHub's languages colours into Flutter's Color object. Receiving ozh's github-colors repository with latest commit of colors.json to Flutter's

Cyrus Chan 1 Jun 6, 2022