stash_dio
5.2.0, released 3 years ago by ivoleitao.dev
Dio interceptor that caches responses using stash
WASM-readyRepository archived
What it does
Adds a caching layer to Dio requests by storing responses in a stash cache. Subsequent identical requests are served from the cache instead of hitting the network.
AI-written summary of version 5.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to cache REST API responses to reduce network traffic
- You want offline support for previously fetched data
- You want to avoid duplicate network calls for the same endpoint
Skip it when
- You require custom caching logic not supported by stash
- You are not using Dio or prefer another HTTP client
Strengths
- Zero‑config integration with Dio
- Supports any stash backend (memory, file, shared_preferences)
- Transparent caching – no changes to request code
Weaknesses
- Depends on the stash package, adding another dependency
- No built‑in support for GraphQL or WebSocket caching
- Limited control over cache eviction policies
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 5
Add stash_dio to pubspec, import stash_dio and stash, create a stash store, add cache.interceptor to Dio interceptors
import 'package:dio/dio.dart';
import 'package:stash/stash_api.dart';
import 'package:stash_dio/stash_dio.dart';
import 'package:stash_memory/stash_memory.dart';
void main() async {
final store = await newMemoryCacheStore();
final cache = store.cache(eventListenerMode: EventListenerMode.synchronous);
final dio = Dio(BaseOptions(baseUrl: 'https://jsonplaceholder.typicode.com'))
..interceptors.addAll([
cache.interceptor('/todos/1'),
LogInterceptor(requestHeader: false, requestBody: false, responseHeader: false, responseBody: false)
]);
final task = await dio.get('/todos/1').then((r) => r.data);
print(task);
}Alternatives
Packages that do the same job and could replace stash_dio.
Works with
Packages commonly used together with stash_dio: ones it builds on, ones built on it, and its own family.
- cryptostash_dio depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- http_parserstash_dio depends on itA platform-independent package for parsing and serializing HTTP formats.
- equatablestash_dio depends on itProvides value‑based equality for Dart objects without manual == and hashCode.
- diostash_dio depends on itA powerful HTTP networking package for Dart and Flutter with interceptors and request cancellation.
- stashstash_dio depends on itKey-value store abstraction with caching semantics and pluggable backends.
- stash_memorySame familyMemory storage extension for the stash API to store vaults and caches in-memory.
- stash_hiveSame familyHive storage extension for the stash caching API