mirror of
https://github.com/wled/WLED.git
synced 2025-07-10 20:36:32 +00:00
presets.json PSRAM caching: consider cacheInvalidate
* trying to make the caching mechanism bulletproof. `cacheInvalidate` is changed when - autosave usermod updates presets - a file was upload * (coding style) fixed some unitialized variables
This commit is contained in:
parent
8110259d1c
commit
9f99a1896d
@ -381,11 +381,15 @@ void updateFSInfo() {
|
|||||||
// original idea by @akaricchi (https://github.com/Akaricchi)
|
// original idea by @akaricchi (https://github.com/Akaricchi)
|
||||||
// returns a pointer to the PSRAM buffer, updates size parameter
|
// returns a pointer to the PSRAM buffer, updates size parameter
|
||||||
static const uint8_t *getPresetCache(size_t &size) {
|
static const uint8_t *getPresetCache(size_t &size) {
|
||||||
static unsigned long presetsCachedTime;
|
static unsigned long presetsCachedTime = 0;
|
||||||
static uint8_t *presetsCached;
|
static uint8_t *presetsCached = nullptr;
|
||||||
static size_t presetsCachedSize;
|
static size_t presetsCachedSize = 0;
|
||||||
|
static byte presetsCachedValidate = 0;
|
||||||
|
|
||||||
if (presetsModifiedTime != presetsCachedTime) {
|
//if (presetsModifiedTime != presetsCachedTime) DEBUG_PRINTLN(F("getPresetCache(): presetsModifiedTime changed."));
|
||||||
|
//if (presetsCachedValidate != cacheInvalidate) DEBUG_PRINTLN(F("getPresetCache(): cacheInvalidate changed."));
|
||||||
|
|
||||||
|
if ((presetsModifiedTime != presetsCachedTime) || (presetsCachedValidate != cacheInvalidate)) {
|
||||||
if (presetsCached) {
|
if (presetsCached) {
|
||||||
free(presetsCached);
|
free(presetsCached);
|
||||||
presetsCached = nullptr;
|
presetsCached = nullptr;
|
||||||
@ -396,6 +400,7 @@ static const uint8_t *getPresetCache(size_t &size) {
|
|||||||
File file = WLED_FS.open(FPSTR(getPresetsFileName()), "r");
|
File file = WLED_FS.open(FPSTR(getPresetsFileName()), "r");
|
||||||
if (file) {
|
if (file) {
|
||||||
presetsCachedTime = presetsModifiedTime;
|
presetsCachedTime = presetsModifiedTime;
|
||||||
|
presetsCachedValidate = cacheInvalidate;
|
||||||
presetsCachedSize = 0;
|
presetsCachedSize = 0;
|
||||||
presetsCached = (uint8_t*)ps_malloc(file.size() + 1);
|
presetsCached = (uint8_t*)ps_malloc(file.size() + 1);
|
||||||
if (presetsCached) {
|
if (presetsCached) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user