Skip to content

Commit e0d6155

Browse files
committed
chore: add code style improvements
Closes #86
1 parent 049dca4 commit e0d6155

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- minor changes in the README file.
13+
- code style improvements —
14+
[86](https://github.com/dartoos-dev/json_cache/issues/86).
1315

1416
### Fixed
1517

lib/src/json_cache_fake.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import 'package:json_cache/json_cache.dart';
66
///
77
/// **Warning**: do not use it in production code. It is not thread-safe.
88
class JsonCacheFake implements JsonCache {
9-
/// It will share a static memory with other instances.
9+
/// Shares a static memory with other instances.
1010
JsonCacheFake() : this.mem(_shrMem);
1111

12-
/// Initializes the cache with [init] by performing a deep copy.
12+
/// Initializes the cache with [init] by performing a deep copy.
1313
JsonCacheFake.init(Map<String, Map<String, dynamic>?> init)
1414
: this.mem(Map<String, Map<String, dynamic>?>.of(init));
1515

@@ -19,9 +19,9 @@ class JsonCacheFake implements JsonCache {
1919
/// in-memory storage.
2020
final Map<String, Map<String, dynamic>?> _memory;
2121

22-
static late final Map<String, Map<String, dynamic>?> _shrMem = {};
22+
static final Map<String, Map<String, dynamic>?> _shrMem = {};
2323

24-
/// Clears the internal map.
24+
/// Clears its internal in-memory storage.
2525
@override
2626
Future<void> clear() async => _memory.clear();
2727

@@ -34,7 +34,7 @@ class JsonCacheFake implements JsonCache {
3434
@override
3535
Future<void> remove(String key) async => _memory.remove(key);
3636

37-
/// Retrieves a copy of the data at [key] or null if there is no data.
37+
/// Retrieves a copy of the data at [key] or `null` if there is no data.
3838
@override
3939
Future<Map<String, dynamic>?> value(String key) async {
4040
final cached = _memory[key];

lib/src/json_cache_hollow.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ class JsonCacheHollow implements JsonCache {
3333

3434
/// Always returns null.
3535
@override
36-
Future<Map<String, dynamic>?> value(String key) async {
37-
return null;
38-
}
36+
Future<Map<String, dynamic>?> value(String key) async => null;
3937
}

lib/src/json_cache_mem.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ typedef OnInitError = FutureOr<Null> Function(Object, StackTrace);
1616
class JsonCacheMem implements JsonCache {
1717
/// In-memory level1 cache with an optional level2 instance.
1818
///
19-
/// ATTENTION: if you do not pass an object to the parameter [level2], the
20-
/// data will remain cached in-memory only; that is, no data will be persited
21-
/// to the user's device's local storage area. Indeed, not persisting data on
22-
/// the user's device might be the desired behavior if you are at the
23-
/// prototyping or mocking phase. However, its unlikely to be the right
24-
/// behavior in production code.
19+
/// **Note**: if you do not pass an object to the parameter [level2], the data
20+
/// will remain cached in-memory only; that is, no data will be persited to
21+
/// the user's device's local storage area. Indeed, not persisting data on the
22+
/// user's device might be the desired behavior if you are at the prototyping
23+
/// or mocking phase. However, its unlikely to be the right behavior in
24+
/// production code.
2525
JsonCacheMem([JsonCache? level2])
2626
: this.mem(_shrMem, level2: level2, mutex: _shrMutex);
2727

@@ -73,14 +73,14 @@ class JsonCacheMem implements JsonCache {
7373
Map<String, Map<String, dynamic>?> mem, {
7474
JsonCache? level2,
7575
ReadWriteMutex? mutex,
76-
}) : _level2 = level2 ?? const JsonCacheHollow(),
77-
_memory = mem,
76+
}) : _memory = mem,
77+
_level2 = level2 ?? const JsonCacheHollow(),
7878
_mutex = mutex ?? ReadWriteMutex();
7979

8080
/// Slower cache level.
8181
final JsonCache _level2;
8282

83-
/// in-memory storage.
83+
/// In-memory storage.
8484
final Map<String, Map<String, dynamic>?> _memory;
8585

8686
/// Mutex lock-guard.
@@ -135,8 +135,9 @@ class JsonCacheMem implements JsonCache {
135135
Future<Map<String, dynamic>?> value(String key) {
136136
return _mutex.protectRead(() async {
137137
final cachedL1 = _memory[key];
138-
if (cachedL1 != null) return Map<String, dynamic>.of(cachedL1);
139-
138+
if (cachedL1 != null) {
139+
return Map<String, dynamic>.of(cachedL1);
140+
}
140141
final cachedL2 = await _level2.value(key);
141142
if (cachedL2 != null) {
142143
_memory[key] = cachedL2;

lib/src/json_cache_wrap.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:json_cache/json_cache.dart';
22

3-
/// Decorator Envelope of [JsonCache].
3+
/// Decorator Envelope of [JsonCache].
44
///
55
/// It just forwards method calls to its encapsulated [JsonCache] instance.
66
abstract class JsonCacheWrap implements JsonCache {

0 commit comments

Comments
 (0)