restio_cache 0.1.2+1 copy "restio_cache: ^0.1.2+1" to clipboard
restio_cache: ^0.1.2+1 copied to clipboard

discontinued

HTTP Cache (RFC 7234) support for Restio using LRU replacement strategy.

Cache #

HTTP Cache (RFC 7234) support for Restio using LRU replacement strategy.

Installation #

In pubspec.yaml add the following dependencies:

dependencies:
  restio_cache: ^0.1.2+1

Usage #

final store = await LruCacheStore.local('./cache');
final cache = Cache(store: store);
final client = Restio(cache: cache);

final request = get('https://postman-echo.com/get');
final call = client.newCall(request);
final response = await call.execute();

final networkResponse = response.networkResponse; // From network validation.
final cacheResponse = response.cacheResponse; // From cache.

Supports LruCacheStore.memory() too.

With encryption using encrypt package:

import 'dart:convert';
import 'dart:typed_data';

import 'package:encrypt/encrypt.dart';

final key = Key.fromUtf8('TLjBdXJxDiqHAFWQAk68NyEtK9D8XYEG');
final encrypter = Encrypter(Fernet(Key.fromUtf8(base64.encode(key.bytes))));

Uint8List encrypt(List<int> data) {
  data = base64Encode(data).codeUnits;
  return encrypter.encryptBytes(data).bytes;
}

List<int> decrypt(Uint8List data) {
  return base64Decode(encrypter.decrypt(Encrypted(data)));
}

final store = await LruCacheStore.local('./cache', decrypt: decrypt, encrypt: encrypt);
1
likes
40
points
9
downloads

Publisher

verified publishertiagohm.dev

Weekly Downloads

HTTP Cache (RFC 7234) support for Restio using LRU replacement strategy.

Repository (GitHub)

License

MIT (license)

Dependencies

convert, crypto, file, meta, path, restio

More

Packages that depend on restio_cache