Skip to content

Commit b896a41

Browse files
authored
refactor!: restore JsonCacheMem's mem constructor
1 parent 5351002 commit b896a41

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Changed
1717

18-
- rename JsonCacheMem.mem constructor to JsonCacheMem.ext**BREAKING CHANGE**.
18+
- JsonCacheMem.mem constructor parameters**BREAKING CHANGE**.
1919
- improvements in several unit tests.
2020
- general improvements in many doc comments.
2121

lib/src/json_cache_mem.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class JsonCacheMem implements JsonCache {
2828
/// prototyping or mocking phase. However, its unlikely to be the right
2929
/// behavior in production code.
3030
JsonCacheMem([JsonCache? level2])
31+
<<<<<<< HEAD
3132
: this.ext(_shrMem, level2: level2, mutex: _shrMutex);
33+
=======
34+
: this.mem(_shrMem, level2: level2, mutex: _shrMutex);
35+
>>>>>>> 32
3236

3337
/// Cache with initial data.
3438
///
@@ -76,7 +80,11 @@ class JsonCacheMem implements JsonCache {
7680
/// Cache with an external memory and an optional custom mutex.
7781
///
7882
/// **Note**: the memory [mem] will **not** be copied deeply.
83+
<<<<<<< HEAD
7984
JsonCacheMem.ext(
85+
=======
86+
JsonCacheMem.mem(
87+
>>>>>>> 32
8088
Map<String, Map<String, dynamic>?> mem, {
8189
JsonCache? level2,
8290
ReadWriteMutex? mutex,

test/json_cache_fake_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ void main() {
3838
});
3939
test('mem ctor', () async {
4040
final copy = Map<String, Map<String, dynamic>?>.of(data);
41+
<<<<<<< HEAD
4142
final JsonCacheFake memMemCache = JsonCacheFake.mem(copy);
4243
await memMemCache.clear();
4344

4445
final cachedProf = await memMemCache.value(profKey);
4546
expect(cachedProf, isNull);
4647

4748
final cachedPref = await memMemCache.value(prefKey);
49+
=======
50+
final JsonCacheFake memCache = JsonCacheFake.mem(copy);
51+
await memCache.clear();
52+
53+
final cachedProf = await memCache.value(profKey);
54+
expect(cachedProf, isNull);
55+
56+
final cachedPref = await memCache.value(prefKey);
57+
>>>>>>> 32
4858
expect(cachedPref, isNull);
4959

5060
expect(copy.isEmpty, true);

test/json_cache_mem_test.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void main() {
8080
final cachedPref = await initMemCache.value(prefKey);
8181
expect(cachedPref, isNull);
8282
});
83+
<<<<<<< HEAD
8384
test('ext ctor', () async {
8485
final copy = Map<String, Map<String, dynamic>?>.of(data);
8586
final JsonCacheMem extMemCache = JsonCacheMem.ext(copy);
@@ -89,6 +90,17 @@ void main() {
8990
expect(cachedProf, isNull);
9091

9192
final cachedPref = await extMemCache.value(prefKey);
93+
=======
94+
test('mem ctor', () async {
95+
final copy = Map<String, Map<String, dynamic>?>.of(data);
96+
final JsonCacheMem memCache = JsonCacheMem.mem(copy);
97+
await memCache.clear();
98+
99+
final cachedProf = await memCache.value(profKey);
100+
expect(cachedProf, isNull);
101+
102+
final cachedPref = await memCache.value(prefKey);
103+
>>>>>>> 32
92104
expect(cachedPref, isNull);
93105

94106
expect(copy.isEmpty, true);
@@ -110,6 +122,7 @@ void main() {
110122
final JsonCacheMem initMemCache = JsonCacheMem.init(data);
111123
await initMemCache.refresh(profKey, profData);
112124
await initMemCache.refresh(prefKey, prefData);
125+
<<<<<<< HEAD
113126

114127
await initMemCache.remove(profKey);
115128
final cachedProf = await initMemCache.value(profKey);
@@ -140,6 +153,38 @@ void main() {
140153
await memCache.refresh(profKey, profData);
141154
await memCache.refresh(prefKey, prefData);
142155

156+
=======
157+
158+
await initMemCache.remove(profKey);
159+
final cachedProf = await initMemCache.value(profKey);
160+
expect(cachedProf, isNull);
161+
162+
await initMemCache.remove(prefKey);
163+
final cachedPref = await initMemCache.value(prefKey);
164+
expect(cachedPref, isNull);
165+
});
166+
test('mem ctor', () async {
167+
final copy = Map<String, Map<String, dynamic>?>.of(data);
168+
final JsonCacheMem memCache = JsonCacheMem.mem(copy);
169+
await memCache.refresh(profKey, profData);
170+
await memCache.refresh(prefKey, prefData);
171+
172+
await memCache.remove(profKey);
173+
final cachedProf = await memCache.value(profKey);
174+
expect(cachedProf, isNull);
175+
176+
await memCache.remove(prefKey);
177+
final cachedPref = await memCache.value(prefKey);
178+
expect(cachedPref, isNull);
179+
});
180+
});
181+
group('refresh and value', () {
182+
test('default ctor', () async {
183+
final JsonCacheMem memCache = JsonCacheMem();
184+
await memCache.refresh(profKey, profData);
185+
await memCache.refresh(prefKey, prefData);
186+
187+
>>>>>>> 32
143188
final cachedProf = await memCache.value(profKey);
144189
expect(cachedProf, profData);
145190

@@ -157,6 +202,7 @@ void main() {
157202
final cachedPref = await initMemCache.value(prefKey);
158203
expect(cachedPref, prefData);
159204
});
205+
<<<<<<< HEAD
160206
test('ext ctor', () async {
161207
final ext = <String, Map<String, dynamic>?>{};
162208
final JsonCacheMem extMemCache = JsonCacheMem.ext(ext);
@@ -170,6 +216,21 @@ void main() {
170216
expect(cachedPref, prefData);
171217
expect(ext[profKey], profData);
172218
expect(ext[prefKey], prefData);
219+
=======
220+
test('mem ctor', () async {
221+
final mem = <String, Map<String, dynamic>?>{};
222+
final JsonCacheMem memCache = JsonCacheMem.mem(mem);
223+
await memCache.refresh(profKey, profData);
224+
await memCache.refresh(prefKey, prefData);
225+
226+
final cachedProf = await memCache.value(profKey);
227+
expect(cachedProf, profData);
228+
229+
final cachedPref = await memCache.value(prefKey);
230+
expect(cachedPref, prefData);
231+
expect(mem[profKey], profData);
232+
expect(mem[prefKey], prefData);
233+
>>>>>>> 32
173234
});
174235
});
175236
});

0 commit comments

Comments
 (0)