@@ -44,8 +44,8 @@ It can also be thought of as a layer on top of Flutter's local storage packages
4444like the [ sharable_preferences] ( https://pub.dev/packages/shared_preferences ) and
4545[ localstorage] ( https://pub.dev/packages/localstorage ) packages.
4646
47- The ultimate goal of this package is to unify Flutter's main local caching
48- packages into an elegant caching API.
47+ Therefore, this package aims to unify most of Flutter's local caching packages
48+ into an elegant caching API.
4949
5050** Why Json?**
5151
@@ -64,22 +64,22 @@ requirements.
6464cached data. It is defined as:
6565
6666``` dart
67- /// Represents data cached in json.
67+ /// Represents cached data in json format .
6868abstract class JsonCache {
6969 /// Frees up storage space.
7070 Future<void> clear();
7171
72- /// It either updates the data found at [key] with [value] or, if there is no
72+ /// Removes cached data located at [key].
73+ Future<void> remove(String key);
74+
75+ /// Retrieves cached data located at [key] or null if a cache miss occurs.
76+ Future<Map<String, dynamic>?> value(String key);
77+
78+ /// It either updates data located at [key] with [value] or, if there is no
7379 /// previous data at [key], creates a new cache row at [key] with [value].
7480 ///
7581 /// **Note**: [value] must be json encodable.
7682 Future<void> refresh(String key, Map<String, dynamic> value);
77-
78- /// Removes data from cache at [key].
79- Future<void> remove(String key);
80-
81- /// Retrieves the data value at [key] or null if a cache miss occurs.
82- Future<Map<String, dynamic>?> value(String key);
8383}
8484```
8585
@@ -95,6 +95,15 @@ represents the name of a single data group. For example:
9595Above, the _ profile_ key is associated with the profile-related data group,
9696while the _ preferences_ key is associated with the preferences-related data.
9797
98+ A typical code for saving the previous _ profile_ and _ preferences_ data is:
99+
100+ ``` dart
101+ final JsonCache jsonCache = … retrieve one of the JsonCache implementations.
102+ …
103+ await jsonCache.refresh('profile', {'name': 'John Doe', 'email': 'johndoe@email.com', 'accountType': 'premium'});
104+ await jsonCache.refresh('preferences', {'theme': {'dark': true}, 'notifications':{'enabled': true}});
105+ ```
106+
98107## List of JsonCache Implementations
99108
100109The library
@@ -121,9 +130,26 @@ object. For example:
121130
122131``` dart
123132 …
133+ /// Cache initialization
124134 final prefs = await SharedPreferences.getInstance();
125135 final JsonCacheMem jsonCache = JsonCacheMem(JsonCachePrefs(prefs));
126136 …
137+ /// Saving profile and preferences data.
138+ await jsonCache.refresh('profile', {'name': 'John Doe', 'email': 'johndoe@email.com', 'accountType': 'premium'});
139+ await jsonCache.refresh('preferences', {'theme': {'dark': true}, 'notifications':{'enabled': true}});
140+ …
141+ /// Retrieving preferences data.
142+ final Map<String, dynamic> preferences = await jsonCache.value('preferences');
143+ …
144+ /// Frees up cached data before the user leaves the application.
145+ Future<void> signout() async {
146+ await jsonCache.clear();
147+ }
148+ …
149+ /// Removes cached data related to a specific user.
150+ Future<void> signoutId(String userId) async {
151+ await jsonCache.remove(userId);
152+ }
127153```
128154
129155In addition, ` JsonCacheMem ` has the ` JsonCacheMem.init ` constructor whose
0 commit comments