Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
749 stars 438 forks source link

Added option for json-file repo #226

Closed renefloor closed 4 years ago

renefloor commented 4 years ago

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Feature

:arrow_heading_down: What is the current behavior?

Currently only sqflite is supported out of the box. This doesn't work on all platforms.

:new: What is the new behavior (if this is a feature change)?

Added a simple json-file provider that stores the objects in memory and caches the info in a json based file. This works on all platforms that are supported by path_provider.

:boom: Does this PR introduce a breaking change?

No, it is only made the default on platforms that were not supported yet.

:bug: Recommendations for testing

Test still need to be written.

:memo: Links to relevant issues/docs

Fixes #224 Fixes #222 Fixes #197

:thinking: Checklist before submitting

escamoteur commented 4 years ago

if it stores the objects in memory, isn't that a problem with image data like map tiles?

renefloor commented 4 years ago

I have to run some memory tests for comparison, but it only stores some meta info. I can imagine that the sqlite connection uses more memory for relatively small amounts of objects. The amount of objects should never get into the hundreds as that would be much for the cache anyway.

codecov[bot] commented 4 years ago

Codecov Report

Merging #226 into develop will increase coverage by 1.95%. The diff coverage is 80.80%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #226      +/-   ##
===========================================
+ Coverage    73.26%   75.22%   +1.95%     
===========================================
  Files           17       18       +1     
  Lines          475      565      +90     
===========================================
+ Hits           348      425      +77     
- Misses         127      140      +13     
Impacted Files Coverage Δ
flutter_cache_manager/lib/src/cache_manager.dart 87.50% <ø> (ø)
...ter_cache_manager/lib/src/compat/file_fetcher.dart 90.00% <ø> (ø)
...utter_cache_manager/lib/src/config/_config_io.dart 12.50% <0.00%> (-12.50%) :arrow_down:
...lutter_cache_manager/lib/src/result/file_info.dart 100.00% <ø> (ø)
...cache_info_repositories/cache_object_provider.dart 0.00% <0.00%> (ø)
...info_repositories/non_storing_object_provider.dart 0.00% <0.00%> (ø)
...er/lib/src/storage/file_system/file_system_io.dart 0.00% <ø> (ø)
..._info_repositories/json_cache_info_repository.dart 91.46% <91.46%> (ø)
...er_cache_manager/lib/src/storage/cache_object.dart 93.93% <100.00%> (+0.39%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fbc82be...9933ac1. Read the comment docs.

hpoul commented 4 years ago

if it stores the objects in memory, isn't that a problem with image data like map tiles?

it is only storing the metadata in memory, not the binary files as far as i understand it, You'd have to cache a lot of objects before you reach the size of the sqlite.so probably 😅️

escamoteur commented 4 years ago

This here was then a bit missleading:

that stores the objects in memory and caches the info in a json based file.

As a cache is just a map<id,image> there are no queries necessary so I see no real benefit of using Sqlite. What are you doing if you get too many entries?

renefloor commented 4 years ago

Sorry, the naming can be better indeed. (It is already improving though).

The info on a cached files is called a CacheObject. This include info for example on the eTag, the fileName, when it is last used: https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/storage/cache_object.dart This is all that is stored in memory.

When the cache is used it also checks how many files there are and when the last time was that the files were used. Files that haven't been used for some time or that are over capacity are removed continuously by the store: https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/cache_store.dart#L125

escamoteur commented 4 years ago

Sounds good!

renefloor commented 4 years ago

Verified it works on Linux and Windows.

fmatosqg commented 4 years ago

Very happy to see this. Pls advise what will be the release version containing this. I couldn't find a release notes file in this repo.

renefloor commented 4 years ago

I expect to release it later today as version 2.0.0-beta, but will have to write at least a bit of documentation mentioning the breaking changes.