ivoleitao / stash

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

HiveError: Wrong checksum in hive file. Box may be corrupted. #36

Closed zhangjianguo1 closed 2 years ago

zhangjianguo1 commented 2 years ago

Describe the bug

_diskCache = newHiveCache(
      path,
      cacheName: name,
      maxEntries: diskCountLimit,
      expiryPolicy: diskAgeLimit != null ? ModifiedExpiryPolicy(diskAgeLimit) : null,
      evictionPolicy: const LruEvictionPolicy(),
    );

invoke _diskCache.keys then got this error:

HiveError: Wrong checksum in hive file. Box may be corrupted.

0 StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:97)

Version stash: 2.0.2 stash_hive: 2.0.2

Flutter 2.5.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 3595343e20 (11 months ago) • 2021-09-30 12:58:18 -0700 Engine • revision 6ac856380f Tools • Dart 2.14.3

ivoleitao commented 2 years ago

I think this is related with this PR in Hive. The version that you are using of stash_hive is very old and depends on hive 2.0.2. From the PR it seems this hive bug was fixed on 2.0.6 version of hive. I believe you have two alternatives:

zhangjianguo1 commented 2 years ago

Thanks, I solved my problem with 'crashRecovery: true'. However, some data will be lost.