nvs: remove search cache at page level

Since read cache was introduced at page level, search cache became
useless in terms of reducing the number of flash read operations.
In addition to that, search cache used an assumption that if pointers to
keys are identical, the keys are also identical, which was proven wrong
by applications which generate key names dynamically.

This change removes CachedFindInfo, and all its uses. This is done at
expense of a small extra number of CPU operations (looking up a value in
the read cache is slightly more expensive) but no extra flash read
operations.

Ref TW12505
Ref https://github.com/espressif/arduino-esp32/issues/365
This commit is contained in:
Ivan Grokhotkov
2017-05-12 12:18:08 +08:00
parent 15a6145961
commit bf01525fc1
3 changed files with 21 additions and 59 deletions
@@ -18,6 +18,9 @@
#include <sstream>
#include <iostream>
#define TEST_ESP_ERR(rc, res) CHECK((rc) == (res))
#define TEST_ESP_OK(rc) CHECK((rc) == ESP_OK)
using namespace std;
using namespace nvs;
@@ -209,6 +212,24 @@ TEST_CASE("can write and read variable length data", "[nvs]")
CHECK(memcmp(buf, str, strlen(str)) == 0);
}
TEST_CASE("different key names are distinguished even if the pointer is the same", "[nvs]")
{
SpiFlashEmulator emu(1);
Page page;
TEST_ESP_OK(page.load(0));
TEST_ESP_OK(page.writeItem(1, "i1", 1));
TEST_ESP_OK(page.writeItem(1, "i2", 2));
int32_t value;
char keyname[10] = {0};
for (int i = 0; i < 2; ++i) {
strncpy(keyname, "i1", sizeof(keyname) - 1);
TEST_ESP_OK(page.readItem(1, keyname, value));
CHECK(value == 1);
strncpy(keyname, "i2", sizeof(keyname) - 1);
TEST_ESP_OK(page.readItem(1, keyname, value));
CHECK(value == 2);
}
}
TEST_CASE("can init PageManager in empty flash", "[nvs]")
{
@@ -428,9 +449,6 @@ TEST_CASE("can erase items", "[nvs]")
CHECK(storage.readItem(3, "key00222", val) == ESP_ERR_NVS_NOT_FOUND);
}
#define TEST_ESP_ERR(rc, res) CHECK((rc) == (res))
#define TEST_ESP_OK(rc) CHECK((rc) == ESP_OK)
TEST_CASE("nvs api tests", "[nvs]")
{
SpiFlashEmulator emu(10);