Skip to content

Commit b710e3b

Browse files
authored
refactor: 'JsonCache' as a Dart interface and implementations as 'final'
Closes #168 Breaking Changes
1 parent a765638 commit b710e3b

11 files changed

+26
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Method "keys" for listing all cache keys —
12+
- Method `keys` for listing all cache keys —
1313
[152](https://github.com/dartoos-dev/json_cache/issues/152)
1414

1515
### Changed
1616

17-
- Mehtod "keys" returns an immutable copy of the underlying cache keys
18-
[165](https://github.com/dartoos-dev/json_cache/issues/152)
17+
- Make `JsonCache` a Dart interface and mark implementations as `final`**BREAKING CHANGE**
18+
[168](https://github.com/dartoos-dev/json_cache/issues/168).
1919

2020
- Update linting rules —
2121
[162](https://github.com/dartoos-dev/json_cache/issues/154).
2222

23+
### Fixed
24+
25+
- Mehtod `keys` returns an immutable copy of the underlying cache keys —
26+
[165](https://github.com/dartoos-dev/json_cache/issues/152)
27+
2328
## [3.0.2] - 2024-08-19
2429

2530
### Changed

lib/src/json_cache.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import 'dart:collection';
22

33
/// Represents cached data in json format.
44
///
5-
///> Cache is a hardware or software component that stores data so that future
6-
///> requests for that data can be served faster; the data stored in a cache
7-
///> might be the result of an earlier computation or a copy of data stored
8-
///> elsewhere.
5+
///> "Cache is a hardware or software component that stores data so that future
6+
///> requests for that data can be served faster; the data stored in a cache
7+
///> might be the result of an earlier computation or a copy of data stored
8+
///> elsewhere."
99
///> — [cache Wikipedia](https://en.wikipedia.org/wiki/Cache_(computing))
10-
abstract class JsonCache {
10+
abstract interface class JsonCache {
1111
/// Frees up storage space — deletes all keys and values.
1212
Future<void> clear();
1313

lib/src/json_cache_exception.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// An exception to indicate cache operation failures.
2-
class JsonCacheException<T extends Object> implements Exception {
2+
final class JsonCacheException<T extends Object> implements Exception {
33
/// Sets [extra] as the aditional information and [exception] as the original
44
/// exception.
55
const JsonCacheException({required this.extra, this.exception});

lib/src/json_cache_fake.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:json_cache/json_cache.dart';
77
/// It is intended for unit testing and prototyping.
88
///
99
/// **Warning**: do not use it in production code. It is not thread-safe.
10-
class JsonCacheFake implements JsonCache {
10+
final class JsonCacheFake implements JsonCache {
1111
/// Shares a static memory with other instances.
1212
JsonCacheFake() : this.mem(_shrMem);
1313

lib/src/json_cache_flutter_secure_storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:json_cache/json_cache.dart';
88
///
99
/// See also:
1010
/// - [flutter_secure_storage](https://pub.dev/packages/flutter_secure_storage).
11-
class JsonCacheFlutterSecureStorage implements JsonCache {
11+
final class JsonCacheFlutterSecureStorage implements JsonCache {
1212
/// Sets the [FlutterSecureStorage] instance.
1313
const JsonCacheFlutterSecureStorage(this._storage);
1414

lib/src/json_cache_hive.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:json_cache/json_cache.dart';
77
/// Implementation on top of the Hive package.
88
///
99
/// See: [hive](https://pub.dev/packages/hive)
10-
class JsonCacheHive implements JsonCache {
10+
final class JsonCacheHive implements JsonCache {
1111
/// Sets the Hive [Box] instance.
1212
const JsonCacheHive(this._box);
1313

lib/src/json_cache_hollow.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'package:json_cache/json_cache.dart';
1616
/// > - Hollow blocks are used because they are lighter
1717
/// > - a hollow log
1818
/// > — [Cambridge Dictionary](https://dictionary.cambridge.org/dictionary/english/hollow)
19-
class JsonCacheHollow implements JsonCache {
19+
final class JsonCacheHollow implements JsonCache {
2020
/// This const constructor ensures that there will be only one
2121
/// [JsonCacheHollow] instance throughout the program.
2222
const JsonCacheHollow();

lib/src/json_cache_mem.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import 'package:mutex/mutex.dart';
99
/// [JsonCacheMem.init] initialization error callback.
1010
typedef OnInitError = FutureOr<Null> Function(Object, StackTrace);
1111

12+
/// {@template json_cache_mem}
13+
///
1214
/// Thread-safe in-memory [JsonCache] decorator.
1315
///
1416
/// It is a kind of _level 1_ cache.
1517
///
1618
/// It encapsulates a slower cache and keeps its own data in-memory.
17-
class JsonCacheMem implements JsonCache {
19+
///
20+
/// {@endtemplate}
21+
final class JsonCacheMem implements JsonCache {
1822
/// In-memory _level 1_ cache with an optional _level 2_ instance.
1923
///
2024
/// **Note**: if you do not pass an object to the parameter [level2], the data

lib/src/json_cache_safe_local_storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:safe_local_storage/safe_local_storage.dart';
88
/// Implementation on top of the SafeLocalStorage package.
99
///
1010
/// See: [Safe local storage](https://pub.dev/packages/safe_local_storage)
11-
class JsonCacheSafeLocalStorage implements JsonCache {
11+
final class JsonCacheSafeLocalStorage implements JsonCache {
1212
/// Encapsulates a [SafeLocalStorage] instance.
1313
const JsonCacheSafeLocalStorage(this._localStorage);
1414

lib/src/json_cache_shared_preferences.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:json_cache/json_cache.dart';
55
import 'package:shared_preferences/shared_preferences.dart';
66

77
/// Persistent preferences file cache.
8-
class JsonCacheSharedPreferences implements JsonCache {
8+
final class JsonCacheSharedPreferences implements JsonCache {
99
/// Sets the [SharedPreferences] instance.
1010
const JsonCacheSharedPreferences(this._sharedPreferences);
1111

lib/src/json_cache_try.dart

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

55
/// A [JsonCache] decorator that provides improved information about
66
/// cache-related failures by throwing [JsonCacheException].
7-
class JsonCacheTry implements JsonCache {
7+
final class JsonCacheTry implements JsonCache {
88
/// Sets [wrapped] as the instance to which this object will forward all
99
/// method calls.
1010
///

0 commit comments

Comments
 (0)