Closed dimitar71 closed 2 months ago
MMKV has something similar to this, it's called ContentChangeHandler.
Note that it's not in realtime. The listener must do a CRUD or at least checkContentChanged()
to trigger the callback.
Yeah, this will require a while loop or a count timer or alike. Which will be read/write expensive, happening so often. Also, not seeing it for Android, maybe Win32-only?
It's available on most platforms (except OHOS). For Android https://github.com/Tencent/MMKV/blob/master/Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java#L1647-L1648
Thank you!
Spent some time with it.
Extended MMKV, and overrode checkContentChangedByOuterProcess()
,
It is going to be an overkill, since it does not provide the key names for changed values. We have around 300 items stored. Getting all values every time there is a change may be an overkill, especially for long JSON strings.
Is there a possibility to know which keys have been updated?
E.g. checkContentChangedByOuterProcess(changedKeys: List<String>)
It's impossible. Even if we did, it won't be accurate because the file might be full write back by the writer, and there's no way to know which key changes.
Yes, I was suspecting such an answer.
Thank you for validating and confirming all this!
MMKV for Android is great supporting multiple processes.
One important feature is missing though: the ability to notify a listener across all processes when a change is done (add/remove/delete). Something of the vicinity of
SharedPreferences.OnSharedPreferenceChangeListener
orLiveData
or alike.Not sure if there is even a plan for it, at least for Android.
But honestly, there is literally no library around which supports this. Except Harmony - but it does not work in some cases.