Skip to content
pubscout

stash_dio

5.2.0, released 3 years ago by ivoleitao.dev

Dio interceptor that caches responses using stash

WASM-readyRepository archived
$ flutter pub add stash_dio
Source repository

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.

  • http

    Simple HTTP client but lacks built‑in caching

Works with

Packages commonly used together with stash_dio: ones it builds on, ones built on it, and its own family.