hurshi / dio-http-cache

http cache lib for Flutter dio like RxCache
Apache License 2.0
274 stars 223 forks source link

Delete from cache not working #59

Closed pikkenix closed 3 years ago

pikkenix commented 3 years ago

I guess I'm doing something wrong but I cannot seem to delete anything from the cache...

Here is my code. My dio request: `

DioCacheManager _dioCacheManager;

void setupDio() { _dioCacheManager = DioCacheManager(CacheConfig()); dio.interceptors.add(_dioCacheManager.interceptor); }

Options createOptions(bool withCache) { Options options = Options(headers: {'Authorization': 'Bearer $_accessToken'});

if (withCache) {
  options = buildCacheOptions(Duration(minutes: 30),
      maxStale: Duration(days: 1), primaryKey: 'test', options: options);
}

Future<List> getLists( {@required int teamId, @required int position}) async { assert(teamId != null);

setupDio();

final response = await dio.get(_baseUrl + 'api/Draft/GetLists',
    queryParameters: {'teamid': teamId, 'position': position},
    options: createOptions(true));
return (response.data as List).map((i) => Player.fromJson(i)).toList();

}`

My code for clearing this requests cache: DioCacheManager _dioCacheManager; _dioCacheManager = DioCacheManager(CacheConfig()); String key = '_baseUrl + '/api/Draft/GetLists'; bool res = await _dioCacheManager.deleteByPrimaryKey(key);

This always returns false, what am I doing wrong?

Mapk26 commented 3 years ago

I had the same problem since the last update, it was working perfectly but for some reason after updating some libs something stopped to work.

Btw, I solved the issue with the requestMethod param: _dioCacheManager.deleteByPrimaryKey(path, requestMethod: "GET");

I hope it helps!