Skip to content

Commit

Permalink
core: moved Db, Hive stores to their respective packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed Jun 22, 2021
1 parent 9696508 commit 21930fe
Show file tree
Hide file tree
Showing 129 changed files with 3,623 additions and 1,852 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions CHANGELOG.md → dio_cache_interceptor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0
- core: Moved DB & Hive cache stores to their respective packages.
- fix: import of file_cache_store.

## 2.3.1
- fix: Cache-Control parsing. Dio does not expand multi valued headers.

Expand Down
File renamed without changes.
9 changes: 2 additions & 7 deletions README.md → dio_cache_interceptor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ Dio HTTP cache interceptor with multiple stores respecting HTTP directives (or n

## Stores
- __BackupCacheStore__: Combined store with primary and secondary.
- __DbCacheStore__: Cache with database (Moor).
- __DbCacheStore__: Cache with database (Moor) [Get it](https://pub.dev/packages/dio_cache_interceptor_db_store).
- __FileCacheStore__: Cache with file system (no web support obviously).
- __HiveCacheStore__: Cache using Hive package (available on all platforms).
- __HiveCacheStore__: Cache using Hive package (available on all platforms) [Get it](https://pub.dev/packages/dio_cache_interceptor_hive_store).
- __MemCacheStore__: Volatile cache with LRU strategy.

### DbCacheStore:
- __Android - iOS support__: Add sqlite3_flutter_libs as dependency in your app (version 0.4.0+1 or later).
- __Desktop support__: Follow Moor install [documentation](https://moor.simonbinder.eu/docs/platforms/).
- __Web support__: You must include 'sql.js' library. Follow Moor install [documentation](https://moor.simonbinder.eu/web/) for further info.

## Usage

```dart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
- "example/**"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
pp.getApplicationDocumentsDirectory().then((dir) {
cacheStore = DbCacheStore(databasePath: dir.path, logStatements: true);
// cacheStore = FileCacheStore(dir.path);
cacheStore = FileCacheStore(dir.path);

// or

// cacheStore = DbCacheStore(databasePath: dir.path, logStatements: true);
// cacheStore = HiveCacheStore(dir.path);

cacheOptions = CacheOptions(
store: cacheStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
path: ../

path_provider: ^2.0.0
sqlite3_flutter_libs: ^0.4.1
sqlite3_flutter_libs: ^0.5.0

# The following section is specific to Flutter.
flutter:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
library dio_cache_interceptor;

export 'io_unsupported.dart'
if (dart.library.io) 'src/store/file_cache_store.dart';
export 'src/dio_cache_interceptor.dart';
export 'src/model/cache_control.dart';
export 'src/model/cache_options.dart';
export 'src/model/cache_priority.dart';
export 'src/model/cache_response.dart';
export 'src/store/backup_cache_store.dart';
export 'src/store/cache_store.dart';
export 'src/store/db_cache_store.dart';
export 'src/store/hive_cache_store.dart';
export 'src/store/file_cache_store/file_cache_store.dart';
export 'src/store/mem_cache_store.dart';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/// Encrypt content/headers method.
typedef Encrypt = Future<List<int>> Function(List<int> bytes);

/// Decrypt content/headers method.
typedef Decrypt = Future<List<int>> Function(List<int> bytes);

class CacheCipher {
/// Optional method to decrypt cache content
final Decrypt decrypt;

/// Optional method to encrypt cache content
final Encrypt encrypt;

const CacheCipher({required this.decrypt, required this.encrypt});
}
/// Encrypt content/headers method.
typedef Encrypt = Future<List<int>> Function(List<int> bytes);

/// Decrypt content/headers method.
typedef Decrypt = Future<List<int>> Function(List<int> bytes);

class CacheCipher {
/// Optional method to decrypt cache content
final Decrypt decrypt;

/// Optional method to encrypt cache content
final Encrypt encrypt;

const CacheCipher({required this.decrypt, required this.encrypt});
}
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
/// Cache-Control header subset representation
class CacheControl {
/// How long the response can be used from the time it was requested (in seconds).
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.8
final int? maxAge;

/// 'public' / 'private'.
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.5
final String? privacy;

/// Must first submit a validation request to an origin server.
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.2
final bool? noCache;

/// Disallow cache, overriding any other directives (Etag, Last-Modified)
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.3
final bool? noStore;

/// Other attributes not parsed
final List<String> other;

CacheControl({
this.maxAge,
this.privacy,
this.noCache = false,
this.noStore = false,
this.other = const [],
});

static CacheControl? fromHeader(List<String>? headerValues) {
if (headerValues == null) return null;

int? maxAge;
String? privacy;
bool? noCache;
bool? noStore;
final other = <String>[];

for (var value in headerValues) {
// Expand values since dio does not do it !
for (var expandedValue in value.split(',')) {
expandedValue = expandedValue.trim();
if (expandedValue == 'no-cache') {
noCache = true;
} else if (expandedValue == 'no-store') {
noStore = true;
} else if (expandedValue == 'public' || expandedValue == 'private') {
privacy = expandedValue;
} else if (expandedValue.startsWith('max-age')) {
maxAge = int.tryParse(
expandedValue.substring(expandedValue.indexOf('=') + 1),
);
} else {
other.add(expandedValue);
}
}
}

return CacheControl(
maxAge: maxAge,
privacy: privacy,
noCache: noCache,
noStore: noStore,
other: other,
);
}

/// Serialize cache-control values
String toHeader() {
final values = <String>[
maxAge != null ? 'max-age=$maxAge' : '',
privacy ?? '',
(noCache ?? false) ? 'no-cache' : '',
(noStore ?? false) ? 'no-store' : '',
...other
];

return values.join(', ');
}
}
/// Cache-Control header subset representation
class CacheControl {
/// How long the response can be used from the time it was requested (in seconds).
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.8
final int? maxAge;

/// 'public' / 'private'.
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.5
final String? privacy;

/// Must first submit a validation request to an origin server.
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.2
final bool? noCache;

/// Disallow cache, overriding any other directives (Etag, Last-Modified)
/// https://tools.ietf.org/html/rfc7234#section-5.2.2.3
final bool? noStore;

/// Other attributes not parsed
final List<String> other;

CacheControl({
this.maxAge,
this.privacy,
this.noCache = false,
this.noStore = false,
this.other = const [],
});

static CacheControl? fromHeader(List<String>? headerValues) {
if (headerValues == null) return null;

int? maxAge;
String? privacy;
bool? noCache;
bool? noStore;
final other = <String>[];

for (var value in headerValues) {
// Expand values since dio does not do it !
for (var expandedValue in value.split(',')) {
expandedValue = expandedValue.trim();
if (expandedValue == 'no-cache') {
noCache = true;
} else if (expandedValue == 'no-store') {
noStore = true;
} else if (expandedValue == 'public' || expandedValue == 'private') {
privacy = expandedValue;
} else if (expandedValue.startsWith('max-age')) {
maxAge = int.tryParse(
expandedValue.substring(expandedValue.indexOf('=') + 1),
);
} else {
other.add(expandedValue);
}
}
}

return CacheControl(
maxAge: maxAge,
privacy: privacy,
noCache: noCache,
noStore: noStore,
other: other,
);
}

/// Serialize cache-control values
String toHeader() {
final values = <String>[
maxAge != null ? 'max-age=$maxAge' : '',
privacy ?? '',
(noCache ?? false) ? 'no-cache' : '',
(noStore ?? false) ? 'no-store' : '',
...other
];

return values.join(', ');
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 21930fe

Please sign in to comment.