ivoleitao / stash

Key-value store abstraction with plain and cache driven semantics and a pluggable backend architecture.
MIT License
87 stars 16 forks source link

stash_dio crash when reading from named hive cache #13

Closed tjarvstrand closed 3 years ago

tjarvstrand commented 3 years ago

Describe the bug When trying to read from a named cache, the stash_dio_interceptor crashes when using stash_hive.

As an aside, maybe stash_dio could use a default name (or require a name) for the cache rather than generating a new one each time. Presumably one uses persistent storage like Hive to be able to reuse it between runs no? :)

To Reproduce

  1. Make a request to any URL that responds with headers that allow caching while using stash_dio with a named stash_hive cache
  2. Restart
  3. Make a request to the same URL again.

Expected behavior The cached response should be returned

Actual behavior There is a crash:

E/flutter (13275): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>'
E/flutter (13275): #0      CacheInterceptorBuilder._onRequest (package:stash_dio/src/dio/interceptor_builder.dart:134:67)
E/flutter (13275): <asynchronous suspension>

Version dio: 4.0.0 stash: 3.0.0 stash_dio: 3.0.0 stash_hive: 3.0.0

Additional context This seems related to https://github.com/ivoleitao/stash/issues/9 but I didn't hit this before because I wasn't using a named cache and as such, a new one was created on each run.

ivoleitao commented 3 years ago

Weird one let me debug

ivoleitao commented 3 years ago

Ok I know what's happening. I will work on a fix ASAP

ivoleitao commented 3 years ago

It's fixed and available on version 3.0.1

tjarvstrand commented 3 years ago

Looks to be working. Thanks for the qucik fix!